-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Added script for deployment and interaction scripts (#2)
* chore: Added script for deployment and interaction scripts * chore: Added creation of temporary .env file for git actions to pass * chore: Testet incentive creation and endIncentive scripts * chore: Added prettier write command * chore: Hardhat config fix * chore: Added env.example * chore: Scripts improvement * chore: Ran prettier * chore: Removed unneccesary part for script * chore: Fixed typo
- Loading branch information
Showing
14 changed files
with
373 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PK= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
12 | ||
12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
export default { | ||
dragonswapV2Staker: { | ||
mainnet: "0x72c0cd98d21ee3263D375437b4FDAC097b596dD6", | ||
testnet: "", | ||
}, | ||
refundee: { | ||
mainnet: "", | ||
testnet: "", | ||
}, | ||
pool: { | ||
mainnet: "", | ||
testnet: "", | ||
}, | ||
rewardToken: { | ||
mainnet: "", | ||
testnet: "", | ||
}, | ||
startTime: { | ||
mainnet: 0, | ||
testnet: 0, | ||
}, | ||
endTime: { | ||
mainnet: 0, | ||
testnet: 0, | ||
}, | ||
rewardAmount: { | ||
mainnet: 0, // Amount is converted to decimals of the reward token in the script | ||
testnet: 0, | ||
}, | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.7.6; | ||
|
||
import '@openzeppelin/contracts/token/ERC20/ERC20.sol'; | ||
|
||
contract Token is ERC20 { | ||
uint8 private tokenDecimals; | ||
|
||
constructor( | ||
string memory _name, | ||
string memory _symbol, | ||
uint8 _decimals | ||
) ERC20(_name, _symbol) { | ||
tokenDecimals = uint8(_decimals); | ||
_mint(msg.sender, 100_000_000 * 10**_decimals); | ||
} | ||
|
||
function decimals() public view virtual override returns (uint8) { | ||
return tokenDecimals; | ||
} | ||
} |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { ethers, network, run } from "hardhat"; | ||
import config from "../config"; | ||
import { saveJson, jsons, sleep } from "./utils"; | ||
import { parseUnits } from "ethers/lib/utils"; | ||
|
||
const wait = async () => { | ||
await sleep(3000); | ||
}; | ||
|
||
const main = async () => { | ||
// Get network data from Hardhat config (see hardhat.config.ts). | ||
const networkName = network.name; | ||
|
||
// Check if the network is supported. | ||
if (networkName === "testnet" || networkName === "mainnet") { | ||
console.log(`Creating incentive on ${networkName} network...`); | ||
|
||
const zeroAddress = ethers.constants.AddressZero; | ||
const refundeeAddress = config.refundee[networkName]; | ||
|
||
// Check if the addresses in the config are set. | ||
if (refundeeAddress === zeroAddress || refundeeAddress === null || refundeeAddress === "") { | ||
throw new Error("Missing refundee address"); | ||
} | ||
|
||
// Compile contracts. | ||
await run("compile"); | ||
console.log("Compiled contracts..."); | ||
|
||
const dragonswapV2StakerAddress = config.dragonswapV2Staker[networkName]; | ||
|
||
const dragonswapV2Staker = await ethers.getContractAt( | ||
"DragonswapV2Staker", | ||
dragonswapV2StakerAddress, | ||
); | ||
|
||
// Define incentive parameters | ||
const rewardToken = config.rewardToken[networkName]; // Address of the reward token | ||
const pool = config.pool[networkName]; // Address of the Dragonswap V2 pool | ||
const startTime = config.startTime[networkName]; // Start time | ||
const endTime = config.endTime[networkName]; // End time | ||
const refundee = refundeeAddress; // Address to receive leftover rewards | ||
|
||
// Create the incentive key | ||
const incentiveKey = { | ||
rewardToken, | ||
pool, | ||
startTime, | ||
endTime, | ||
refundee | ||
}; | ||
|
||
// Approve the DragonswapV2Staker contract to spend reward tokens | ||
const rewardTokenContract = await ethers.getContractAt("Token", rewardToken); | ||
const rewardTokenDecimals = await rewardTokenContract.decimals(); | ||
const rewardAmount = parseUnits(config.rewardAmount[networkName].toString(), rewardTokenDecimals); | ||
await rewardTokenContract.approve(dragonswapV2StakerAddress, rewardAmount); | ||
|
||
await wait(); | ||
|
||
// Create the incentive | ||
const createIncentiveTx = await dragonswapV2Staker.createIncentive( | ||
incentiveKey, | ||
rewardAmount | ||
); | ||
|
||
const createIncentiveTxReceipt = await createIncentiveTx.wait(); | ||
|
||
console.log("Incentive created. Transaction hash:", createIncentiveTxReceipt.transactionHash); | ||
|
||
// Save the incentive details | ||
saveJson( | ||
jsons.incentives, | ||
network.name, | ||
"latestIncentive", | ||
{ | ||
rewardToken, | ||
pool, | ||
startTime, | ||
endTime, | ||
refundee, | ||
rewardAmount: rewardAmount.toString() | ||
} | ||
); | ||
} else { | ||
console.log(`Creating incentive on ${networkName} network is not supported...`); | ||
} | ||
}; | ||
|
||
main() | ||
.then(() => process.exit(0)) | ||
.catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { saveJson, jsons } from './utils'; | ||
import { ethers , network, run } from "hardhat"; | ||
|
||
|
||
async function main() { | ||
// Compile contracts. | ||
await run("compile"); | ||
console.log("Compiled contracts..."); | ||
|
||
const name = "MockToken"; | ||
const symbol = "MTKN"; | ||
const decimals = 6; | ||
|
||
const mockTokenFactory = await ethers.getContractFactory('Token'); | ||
const mockToken = await mockTokenFactory.deploy(name, symbol, decimals); | ||
await mockToken.deployed(); | ||
console.log(`MockToken address: ${mockToken.address}`); | ||
|
||
saveJson(jsons.addresses, network.name, 'MockToken', mockToken.address); | ||
|
||
console.log('Done!'); | ||
} | ||
|
||
// We recommend this pattern to be able to use async/await everywhere | ||
// and properly handle errors. | ||
main() | ||
.then(() => process.exit(0)) | ||
.catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { ethers, network, run } from "hardhat"; | ||
import config from "../config"; | ||
import { jsons, sleep, getJson } from "./utils"; | ||
|
||
const wait = async () => { | ||
await sleep(3000); | ||
}; | ||
|
||
const main = async () => { | ||
// Get network data from Hardhat config | ||
const networkName = network.name; | ||
|
||
// Check if the network is supported | ||
if (networkName === "testnet" || networkName === "mainnet") { | ||
console.log(`Ending incentive on ${networkName} network...`); | ||
|
||
// Compile contracts | ||
await run("compile"); | ||
console.log("Compiled contracts..."); | ||
|
||
const dragonswapV2StakerAddress = config.dragonswapV2Staker[networkName]; | ||
|
||
const dragonswapV2Staker = await ethers.getContractAt( | ||
"DragonswapV2Staker", | ||
dragonswapV2StakerAddress, | ||
); | ||
|
||
// Load the incentive to end details from config | ||
const incentiveFromConfig = { | ||
rewardToken: config.rewardToken[networkName], | ||
pool: config.pool[networkName], | ||
startTime: config.startTime[networkName], | ||
endTime: config.endTime[networkName], | ||
refundee: config.refundee[networkName] | ||
}; | ||
|
||
await wait(); | ||
// End the incentive | ||
const endIncentiveTx = await dragonswapV2Staker.endIncentive(incentiveFromConfig); | ||
|
||
const endIncentiveTxReceipt = await endIncentiveTx.wait(); | ||
|
||
console.log("Incentive ended. Transaction hash:", endIncentiveTxReceipt.transactionHash); | ||
|
||
// Get the refund amount from the transaction logs | ||
const refundEvent = endIncentiveTxReceipt.events?.find(e => e.event === "IncentiveEnded"); | ||
const refundAmount = refundEvent?.args?.refund; | ||
|
||
const rewardTokenContract = await ethers.getContractAt("Token", incentiveFromConfig.rewardToken); | ||
const rewardTokenDecimals = await rewardTokenContract.decimals(); | ||
|
||
console.log("Refund amount:", ethers.utils.formatUnits(refundAmount, rewardTokenDecimals)); | ||
|
||
} else { | ||
console.log(`Ending incentive on ${networkName} network is not supported...`); | ||
} | ||
}; | ||
|
||
main() | ||
.then(() => process.exit(0)) | ||
.catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |
Oops, something went wrong.