-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 2.0.1 Co-authored-by: Jan-Paul Azucena <[email protected]> Co-authored-by: Nathan Sala <[email protected]>
- Loading branch information
1 parent
f4f73c2
commit 0cf3ffb
Showing
15 changed files
with
172 additions
and
423 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
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,109 +1,42 @@ | ||
const program = require('commander'); | ||
const { NFCollectionMaskLength } = require('../src').constants; | ||
const { BN } = require('@openzeppelin/test-helpers'); | ||
const { fromWei, toWei } = require('web3-utils'); | ||
const { fromWei } = require('web3-utils'); | ||
const { DefaultNFMaskLength } = require('@animoca/ethereum-contracts-assets_inventory').constants; | ||
const { DefaultCycleLengthInSeconds, DefaultPeriodLengthInCycles, ExamplePayoutSchedule, ExampleWeightsByRarity } = require('../src/constants'); | ||
const { rewardsPoolFromSchedule } = require('../src/utils'); | ||
|
||
const NftStaking = artifacts.require("NftStakingMock"); | ||
const AssetsInventory = artifacts.require("AssetsInventoryMock"); | ||
const ERC20 = artifacts.require("ERC20WithOperatorsMock"); | ||
|
||
const DayInSeconds = 86400; | ||
const CycleLengthInSeconds = new BN(DayInSeconds); | ||
const PeriodLengthInCycles = new BN(7); | ||
|
||
const RewardsTokenInitialBalance = toWei('320000000'); | ||
const PayoutSchedule = [ // payouts are expressed in decimal form and need to be converted to wei | ||
{ startPeriod: 1, endPeriod: 4, payoutPerCycle: '2700000' }, | ||
{ startPeriod: 5, endPeriod: 5, payoutPerCycle: '2200000' }, | ||
{ startPeriod: 6, endPeriod: 6, payoutPerCycle: '2150000' }, | ||
{ startPeriod: 7, endPeriod: 7, payoutPerCycle: '2100000' }, | ||
{ startPeriod: 8, endPeriod: 8, payoutPerCycle: '2050000' }, | ||
{ startPeriod: 9, endPeriod: 9, payoutPerCycle: '2000000' }, | ||
{ startPeriod: 10, endPeriod: 10, payoutPerCycle: '1950000' }, | ||
{ startPeriod: 11, endPeriod: 11, payoutPerCycle: '1900000' }, | ||
{ startPeriod: 12, endPeriod: 12, payoutPerCycle: '1850000' }, | ||
{ startPeriod: 13, endPeriod: 13, payoutPerCycle: '1800000' }, | ||
{ startPeriod: 14, endPeriod: 14, payoutPerCycle: '1750000' }, | ||
{ startPeriod: 15, endPeriod: 15, payoutPerCycle: '1700000' }, | ||
{ startPeriod: 16, endPeriod: 16, payoutPerCycle: '1650000' }, | ||
{ startPeriod: 17, endPeriod: 17, payoutPerCycle: '1600000' }, | ||
{ startPeriod: 18, endPeriod: 18, payoutPerCycle: '1550000' }, | ||
{ startPeriod: 19, endPeriod: 19, payoutPerCycle: '1500000' }, | ||
{ startPeriod: 20, endPeriod: 20, payoutPerCycle: '1475000' }, | ||
{ startPeriod: 21, endPeriod: 21, payoutPerCycle: '1450000' }, | ||
{ startPeriod: 22, endPeriod: 22, payoutPerCycle: '1425000' }, | ||
{ startPeriod: 23, endPeriod: 23, payoutPerCycle: '1400000' }, | ||
{ startPeriod: 24, endPeriod: 24, payoutPerCycle: '1375000' }, | ||
]; // total ~ 320,000,000 | ||
|
||
const RarityToWeightsMap = { | ||
0: 500,// Apex, | ||
1: 100,// Legendary, | ||
2: 50,// Epic, | ||
3: 50,// Epic, | ||
4: 10,// Rare, | ||
5: 10,// Rare, | ||
6: 10,// Rare, | ||
7: 1,// Common, | ||
8: 1,// Common, | ||
9: 1// Common, | ||
}; | ||
const RewardsPool = rewardsPoolFromSchedule(ExamplePayoutSchedule, DefaultPeriodLengthInCycles); | ||
|
||
module.exports = async (deployer, network, accounts) => { | ||
|
||
switch (network) { | ||
case "ganache": | ||
await deployer.deploy(AssetsInventory, NFCollectionMaskLength); | ||
this.nftContract = await AssetsInventory.deployed(); | ||
await deployer.deploy(ERC20, RewardsTokenInitialBalance); | ||
this.rewardsTokenContract = await ERC20.deployed(); | ||
break; | ||
case "rinkeby": | ||
const nftContractAddressRinkeby = program.nftContractAddressRinkeby; | ||
const ERC20BaseAddressRinkeby = program.ERC20BaseAddressRinkeby; | ||
|
||
this.nftContract = | ||
nftContractAddressRinkeby ? | ||
await AssetsInventory.at(nftContractAddressRinkeby) : | ||
await AssetsInventory.new(NFCollectionMaskLength); | ||
|
||
this.rewardsTokenContract = | ||
ERC20BaseAddressRinkeby ? | ||
await ERC20.at(ERC20BaseAddressRinkeby) : | ||
await ERC20.new(RewardsTokenInitialBalance); | ||
|
||
break; | ||
case "mainnet": | ||
|
||
break; | ||
default: | ||
console.log(`Unknown network '${network}', stopping...`); | ||
return; | ||
|
||
} | ||
|
||
this.inventoryContract = await AssetsInventory.new(DefaultNFMaskLength); | ||
this.erc20Contract = await ERC20.new(RewardsPool); | ||
|
||
await deployer.deploy(NftStaking, | ||
CycleLengthInSeconds, | ||
PeriodLengthInCycles, | ||
this.nftContract.address, | ||
this.rewardsTokenContract.address, | ||
Object.keys(RarityToWeightsMap), | ||
Object.values(RarityToWeightsMap), | ||
DefaultCycleLengthInSeconds, | ||
DefaultPeriodLengthInCycles, | ||
this.inventoryContract.address, | ||
this.erc20Contract.address, | ||
Object.keys(ExampleWeightsByRarity), | ||
Object.values(ExampleWeightsByRarity), | ||
); | ||
|
||
this.stakingContract = await NftStaking.deployed(); | ||
|
||
// Enough to cover the whole payout schedule needs to be approved and will be transferred to the contract at start | ||
await this.rewardsTokenContract.approve(this.stakingContract.address, RewardsTokenInitialBalance); | ||
|
||
for (schedule of PayoutSchedule) { | ||
for (schedule of ExamplePayoutSchedule) { | ||
console.log(`Setting schedule: ${fromWei(schedule.payoutPerCycle)} ERC20s per-cycle for periods ${schedule.startPeriod} to ${schedule.endPeriod}`); | ||
await this.stakingContract.setRewardsForPeriods( | ||
schedule.startPeriod, | ||
schedule.endPeriod, | ||
toWei(schedule.payoutPerCycle) | ||
schedule.payoutPerCycle | ||
); | ||
} | ||
|
||
console.log(`Approving ${fromWei(RewardsPool)} ERC20s to the staking contract for the reward pool before starting`); | ||
await this.erc20Contract.approve(this.stakingContract.address, RewardsPool); | ||
|
||
console.log('Starting the staking schedule'); | ||
await this.stakingContract.start(); | ||
} |
Oops, something went wrong.