-
Notifications
You must be signed in to change notification settings - Fork 8
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
Stakingpool unstake optimization #48
Open
pash7ka
wants to merge
12
commits into
deploy_2021-01-14
Choose a base branch
from
stakingpool_unstake_optimization
base: deploy_2021-01-14
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
65b1911
DD-1775 Gas usage test for 50 stake + unstakeAll
pash7ka a71cfdb
DD-1775 Only calculate rewards once in unstakeAllUnlocked
pash7ka f621d15
DD-1755 [wip]
pash7ka c96ff9a
DD-1812
pash7ka 771d634
DD-1812 fix typo
pash7ka aca1059
DD-1813 Add rewards to gas test
pash7ka 551d7dd
DD-1813 Fix typo, add 2nd epoch
pash7ka ad70863
DD-1813 Decrease test iterations
pash7ka 8e6f230
StakingPool rinkeby upgrade
pash7ka ab43942
Unstake fix
Pavel-Blaize 0e60382
withdrawStakes() fix
Pavel-Blaize 5d73d98
StakingPool rinkeby upgrade
pash7ka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { | ||
PoolContract, PoolInstance, | ||
StakingPoolContract,StakingPoolInstance, | ||
StakingPoolADELContract,StakingPoolADELInstance, | ||
FreeERC20Contract,FreeERC20Instance, | ||
RewardVestingModuleContract, RewardVestingModuleInstance, | ||
} from "../../../types/truffle-contracts/index"; | ||
|
||
|
||
const { BN, constants, expectEvent, shouldFail, time } = require("@openzeppelin/test-helpers"); | ||
const { deployProxy, upgradeProxy } = require('@openzeppelin/truffle-upgrades'); | ||
const UPGRADABLE_OPTS = { | ||
unsafeAllowCustomTypes: true | ||
}; | ||
|
||
import Snapshot from "./../../utils/snapshot"; | ||
const should = require("chai").should(); | ||
var expect = require("chai").expect; | ||
const expectRevert= require("./../../utils/expectRevert"); | ||
const expectEqualBN = require("./../../utils/expectEqualBN"); | ||
const w3random = require("./../../utils/w3random"); | ||
|
||
const FreeERC20 = artifacts.require("FreeERC20"); | ||
|
||
const Pool = artifacts.require("Pool"); | ||
const StakingPool = artifacts.require("StakingPool"); | ||
const RewardVestingModule = artifacts.require("RewardVestingModule"); | ||
|
||
contract("StakingPool", async ([owner, user, ...otherAccounts]) => { | ||
|
||
|
||
let pool:PoolInstance; | ||
let akro:FreeERC20Instance; | ||
let stakingPoolAkro:StakingPoolInstance; | ||
let rewardVesting:RewardVestingModuleInstance; | ||
|
||
|
||
before(async () => { | ||
//Setup system contracts | ||
pool = await Pool.new(); | ||
await pool.methods['initialize()'](); | ||
|
||
akro = await FreeERC20.new(); | ||
await akro.methods['initialize(string,string)']("Akropolis", "AKRO"); | ||
await pool.set('akro', akro.address, false); | ||
|
||
stakingPoolAkro = await StakingPool.new(); | ||
await stakingPoolAkro.methods['initialize(address,address,uint256)'](pool.address, akro.address, '0'); | ||
await pool.set('staking', stakingPoolAkro.address, false); | ||
|
||
rewardVesting = await RewardVestingModule.new(); | ||
await rewardVesting.methods['initialize(address)'](pool.address); | ||
await pool.set('reward', rewardVesting.address, false); | ||
await stakingPoolAkro.setRewardVesting(rewardVesting.address); | ||
|
||
|
||
//Prepare rewards | ||
let rewardsAmount = new BN(web3.utils.toWei('1000', 'ether')); | ||
let now = Number(await time.latest()); | ||
await rewardVesting.registerRewardToken(stakingPoolAkro.address, akro.address, String(now - 7*24*60*60), {from:owner}); | ||
await akro.methods['mint(uint256)'](rewardsAmount.muln(2), {from:owner}); | ||
await akro.approve(rewardVesting.address, rewardsAmount.muln(2), {from:owner}); | ||
await rewardVesting.createEpoch(stakingPoolAkro.address, akro.address, String(now+2*7*24*60*60), rewardsAmount, {from:owner}); | ||
await rewardVesting.createEpoch(stakingPoolAkro.address, akro.address, String(now+50*7*24*60*60), rewardsAmount, {from:owner}); | ||
|
||
//Save snapshot | ||
//snap = await Snapshot.create(web3.currentProvider); | ||
|
||
}); | ||
|
||
beforeEach(async () => { | ||
//await snap.revert(); | ||
}); | ||
|
||
|
||
it('should stake AKRO 10 times', async () => { | ||
for(let i=0; i<10; i++){ | ||
let amount = w3random.interval(10, 20, 'ether'); | ||
console.log(`Iteration ${i}: staking ${web3.utils.fromWei(amount)} AKRO.`); | ||
await prepareTokenSpending(akro, user, stakingPoolAkro.address, amount); | ||
await stakingPoolAkro.stake(amount, "0x", {from:user}); | ||
await stakingPoolAkro.claimRewardsFromVesting({from:owner}); | ||
await time.increase(7*24*60*60); | ||
} | ||
}); | ||
|
||
it('should withdraw all stakes with gas used < 200k', async () => { | ||
let tx = await stakingPoolAkro.unstakeAllUnlocked("0x", {from:user}); | ||
//console.log(tx); | ||
let gasUsed = tx.receipt.gasUsed; | ||
expect(gasUsed).to.be.lt(200000); | ||
}); | ||
|
||
|
||
|
||
async function prepareTokenSpending(token:FreeERC20Instance, sender:string, spender:string, amount: BN){ | ||
await token.allocateTo(sender, amount, {from:sender}); | ||
await token.approve(spender, amount, {from:sender}); | ||
} | ||
|
||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
There is no totalStakedFor reduction here.
Please add the line
totalStakedAmount = totalStakedAmount.sub(unstakeAmount);