Skip to content

Receiver pot #68

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

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2d832bc
Add Extra Rewards Feature by Receiver
akshay111meher May 12, 2023
6319f81
remove feature to withdraw unused tokens
akshay111meher May 15, 2023
ac3cdfd
fix tests (few pending)
akshay111meher May 15, 2023
ed889b5
remove removeBalances in cluster rewards and relevant tests
akshay111meher May 15, 2023
ae81fa2
fix benchmarks
akshay111meher May 17, 2023
d00314b
update
akshay111meher Jun 3, 2023
d41c97b
update
akshay111meher Jun 3, 2023
c7e8ac0
fix benchmarks
akshay111meher Jun 3, 2023
0d9d31b
fix the receiver balance and recheck coverage
akshay111meher Jun 5, 2023
4fe9625
remove _processReceiverTickets func params
akshay111meher Jun 5, 2023
70ce257
receiver extra rewards
akshay111meher Jun 6, 2023
fa10959
add-waffle-file
akshay111meher Jun 6, 2023
bc87a82
update
akshay111meher Jun 7, 2023
fdb185f
Combine rewards and rewardsPerEpoch into a struct
akshay111meher Jun 12, 2023
ffaefd8
update
akshay111meher Jun 12, 2023
adb9cc5
lint cluster-rewards
akshay111meher Jun 13, 2023
a0b2d4e
update
akshay111meher Jun 14, 2023
5b88725
freeze tests
akshay111meher Jun 14, 2023
dc438a7
update
akshay111meher Jun 14, 2023
0c54502
remove feed related operations, fix tests for the same
akshay111meher Jun 15, 2023
3d9238d
change delta to percentage
akshay111meher Jun 19, 2023
773f53a
Merge pull request #71 from marlinprotocol/feed-remove
prateekreddy Jun 19, 2023
deccd9b
cast in issueTickets to uint128 without checks to save gas
prateekreddy Jun 19, 2023
c0151a4
Remove unused imports in ClusterRewards
prateekreddy Jun 19, 2023
245f186
update unused var names to match nomenculature in rest of contracts
prateekreddy Jun 19, 2023
ba900e8
save gas by removing safemath checks in _getRewardShare
prateekreddy Jun 19, 2023
c8965b3
cast in issueTickets to uint128 without checks to save gas
prateekreddy Jun 19, 2023
5b35d40
Remove unnecessary casting in _processReceiverTickets
prateekreddy Jun 19, 2023
8763c0b
remove multiple calculations of rewardToGive in issueTickets
prateekreddy Jun 19, 2023
ecb8c67
allow rewardPerEpoch to be set to 0 by receiver
prateekreddy Jun 19, 2023
f8dd479
Call issueTickets(bytes) twice in benchmarks
akshay111meher Jun 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ coverage.json
.openzeppelin/*-9876543210.json
.gitsigners
typechain-types/*
*.log
*.log
custom_flatten
*.dot
*.png
454 changes: 232 additions & 222 deletions benchmarks/ClusterRewards.ts

Large diffs are not rendered by default.

202 changes: 109 additions & 93 deletions benchmarks/fixtures/ClusterRewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,102 +4,118 @@ import { deploy as deployClusterRewards } from "../../deployments/staking/Cluste
import { deploy as deployClusterSelector } from "../../deployments/staking/ClusterSelector";
import { deploy as deployReceiverStaking } from "../../deployments/staking/ReceiverStaking";

const EPOCH_LENGTH = 15*60;
import { ArbGasInfo__factory } from "../../typechain-types"

export async function deployFixture() {
const signers = await ethers.getSigners();
const addrs = await Promise.all(signers.map((a) => a.getAddress()));

const blockNum = await ethers.provider.getBlockNumber();
const blockData = await ethers.provider.getBlock(blockNum);

const Pond = await ethers.getContractFactory("Pond");
const pond = await upgrades.deployProxy(Pond, ["Marlin POND", "POND"], {
kind: "uups",
});

const receiverStaking = await deployReceiverStaking(addrs[0], blockData.timestamp, EPOCH_LENGTH, pond.address, true);
const EPOCH_LENGTH = 15 * 60;

const clusterSelector = await deployClusterSelector("ETH", addrs[1], "0x000000000000000000000000000000000000006C", addrs[0], blockData.timestamp, EPOCH_LENGTH, ethers.utils.parseEther('1').toString(), true);

const clusterRewards = await deployClusterRewards(addrs[1], receiverStaking.address, {
"ETH": clusterSelector.address
}, addrs[0], true);

return {
pond,
receiverStaking,
clusterSelector,
clusterRewards,
admin: signers[0],
rewardDelegatorsMock: signers[1]
};
export async function deployFixture() {
const signers = await ethers.getSigners();
const addrs = await Promise.all(signers.map((a) => a.getAddress()));

const blockNum = await ethers.provider.getBlockNumber();
const blockData = await ethers.provider.getBlock(blockNum);

const Pond = await ethers.getContractFactory("Pond");
const pond = await upgrades.deployProxy(Pond, ["Marlin POND", "POND"], {
kind: "uups",
});

const mockArbGas = await new ArbGasInfo__factory().connect(signers[0]).deploy()
mockArbGas.setPrices(10000, 10000 ,10000);

const receiverStaking = await deployReceiverStaking(addrs[0], blockData.timestamp, EPOCH_LENGTH, pond.address, true);

const clusterSelector = await deployClusterSelector(
"ETH",
addrs[1],
mockArbGas.address,
addrs[0],
blockData.timestamp,
EPOCH_LENGTH,
"10000000",
ethers.utils.parseEther("1").toString(),
true
);

const clusterRewards = await deployClusterRewards(
addrs[1], // reward delegators is mocked, ideally this should be reward delegators
receiverStaking.address,
{
ETH: clusterSelector.address,
},
pond.address,
addrs[0],
true
);

return {
pond,
receiverStaking,
clusterSelector,
clusterRewards,
admin: signers[0],
rewardDelegatorsMock: signers[1],
};
}

export async function initDataFixture() {
const nodesToInsert: number = 75;
const receiverCount: number = 100;

const signers = await ethers.getSigners();
const preAllocEthSigner = signers[8];

const {
pond,
receiverStaking,
clusterSelector,
clusterRewards,
admin,
rewardDelegatorsMock
} = await deployFixture();

const tokenSupply: BigNumber = await pond.totalSupply();

const clusters: string[] = [];
const balances: BigNumberish[] = [];
const receivers: Signer[] = [];
const receiverSigners: Signer[] = [];

// generate clusters and balance data
for(let i=0; i < nodesToInsert; i++) {
const address = Wallet.createRandom().address;
clusters.push(address);
balances.push(BigNumber.from(ethers.utils.randomBytes(32)).mod(tokenSupply.div(utils.parseEther(nodesToInsert+""))));
}

// insert clusterData into selector
for(let i=0; i < clusters.length; i+=50) {
await clusterSelector.connect(rewardDelegatorsMock).upsertMultiple(clusters.slice(i, i+50), balances.slice(i, i+50));
}

for(let i=0; i < receiverCount; i++) {
// create receiver and stake
const receiver = Wallet.createRandom().connect(ethers.provider);
const receiverSigner = Wallet.createRandom().connect(ethers.provider);
receivers.push(receiver);
receiverSigners.push(receiverSigner);
const depositAmount = BigNumber.from(ethers.utils.randomBytes(32)).mod(tokenSupply.div(receiverCount));
await preAllocEthSigner.sendTransaction({
to: receiver.address,
value: utils.parseEther("0.5").toString()
});
await preAllocEthSigner.sendTransaction({
to: receiverSigner.address,
value: utils.parseEther("0.5").toString()
});
await pond.transfer(receiver.address, depositAmount);
await pond.connect(receiver).approve(receiverStaking.address, depositAmount);
await receiverStaking.connect(receiver)["depositFor(uint256,address)"](depositAmount, receiverSigner.address);
}

return {
pond,
receiverStaking,
clusterSelector,
clusterRewards,
admin,
rewardDelegatorsMock,
nodesInserted: nodesToInsert,
receivers,
receiverSigners
};
const nodesToInsert: number = 75;
const receiverCount: number = 100;

const signers = await ethers.getSigners();
const preAllocEthSigner = signers[8];

const { pond, receiverStaking, clusterSelector, clusterRewards, admin, rewardDelegatorsMock } = await deployFixture();

const tokenSupply: BigNumber = await pond.totalSupply();

const clusters: string[] = [];
const balances: BigNumberish[] = [];
const receivers: Signer[] = [];
const receiverSigners: Signer[] = [];

// generate clusters and balance data
for (let i = 0; i < nodesToInsert; i++) {
const address = Wallet.createRandom().address;
clusters.push(address);
balances.push(BigNumber.from(ethers.utils.randomBytes(32)).mod(tokenSupply.div(utils.parseEther(nodesToInsert + ""))));
}

// insert clusterData into selector
for (let i = 0; i < clusters.length; i += 50) {
await clusterSelector.connect(rewardDelegatorsMock).upsertMultiple(clusters.slice(i, i + 50), balances.slice(i, i + 50));
}

for (let i = 0; i < receiverCount; i++) {
// create receiver and stake
const receiver = Wallet.createRandom().connect(ethers.provider);
const receiverSigner = Wallet.createRandom().connect(ethers.provider);
receivers.push(receiver);
receiverSigners.push(receiverSigner);
const depositAmount = BigNumber.from(ethers.utils.randomBytes(32)).mod(tokenSupply.div(receiverCount));
await preAllocEthSigner.sendTransaction({
to: receiver.address,
value: utils.parseEther("0.5").toString(),
});
await preAllocEthSigner.sendTransaction({
to: receiverSigner.address,
value: utils.parseEther("0.5").toString(),
});
await pond.transfer(receiver.address, depositAmount);
await pond.connect(receiver).approve(receiverStaking.address, depositAmount);
await receiverStaking.connect(receiver)["depositFor(uint256,address)"](depositAmount, receiver.address);
await receiverStaking.connect(receiver).setSigner(receiverSigner.address);
}

return {
pond,
receiverStaking,
clusterSelector,
clusterRewards,
admin,
rewardDelegatorsMock,
nodesInserted: nodesToInsert,
receivers,
receiverSigners,
};
}
24 changes: 24 additions & 0 deletions contracts/mocks/ArbGasInfo.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../staking/interfaces/IArbGasInfo.sol";

contract ArbGasInfo is IArbGasInfo {

uint256 public perL2Tx;
uint256 public gasForL1Calldata;
uint256 public storageArbGas;

constructor(){}

function setPrices(uint256 _perL2Tx,uint256 _gasForL1Calldata,uint256 _storageArbGas) public {
perL2Tx = _perL2Tx;
gasForL1Calldata = _gasForL1Calldata;
storageArbGas = _storageArbGas;
}

function getPricesInArbGas() external view override returns (uint, uint, uint) {
return (perL2Tx, gasForL1Calldata, storageArbGas);
}
}
Loading