Skip to content
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

ParaX L2 Implementation #433

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ jobs:
strategy:
matrix:
node: [18]

env:
INFURA_KEY: ${{ secrets.INFURA_KEY }}
DEPLOYER_MNEMONIC: ${{ secrets.DEPLOYER_MNEMONIC }}
ETHERSCAN_KEY: ${{ secrets.ETHERSCAN_KEY }}
MOCHA_JOBS: 0
steps:
- name: Checkout Repository
uses: actions/checkout@v3
Expand Down
16 changes: 10 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@ test-ape-staking:
test-auto-compound-ape:
make TEST_TARGET=auto_compound_ape.spec.ts test

.PHONY: test-p2p-pair-staking
test-p2p-pair-staking:
make TEST_TARGET=p2p_pair_staking.spec.ts test
.PHONY: test-para-ape-staking
test-para-aper-staking:
make TEST_TARGET=para_ape_staking.spec.ts test

.PHONY: test-sape-operation
test-sape-operation:
Expand Down Expand Up @@ -392,9 +392,9 @@ deploy-blur-exchange:
deploy-flashClaimRegistry:
make TASK_NAME=deploy:flash-claim-registry run-task

.PHONY: deploy-p2p-pair-staking
deploy-p2p-pair-staking:
make TASK_NAME=deploy:P2PPairStaking run-task
.PHONY: deploy-para-ape-staking
deploy-para-ape-staking:
make TASK_NAME=deploy:ParaApeStaking run-task

.PHONY: deploy-timelock
deploy-timelock:
Expand Down Expand Up @@ -680,6 +680,10 @@ upgrade-account-abstraction:
upgrade-p2p-pair-staking:
make TASK_NAME=upgrade:p2p-pair-staking run-task

.PHONY: upgrade-para-ape-staking
upgrade-para-ape-staking:
make TASK_NAME=upgrade:para-ape-staking run-task

.PHONY: upgrade-ntoken
upgrade-ntoken:
make TASK_NAME=upgrade:ntoken run-task
Expand Down
33 changes: 16 additions & 17 deletions contracts/apestaking/AutoCompoundApe.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ contract AutoCompoundApe is
/// @inheritdoc IAutoCompoundApe
function deposit(address onBehalf, uint256 amount) external override {
require(amount > 0, "zero amount");
uint256 amountShare = getShareByPooledApe(amount);

uint256 rewardAmount = _getRewardApeBalance();
uint256 amountShare = _getShareByPooledApe(amount, rewardAmount);
if (amountShare == 0) {
amountShare = amount;
// permanently lock the first MINIMUM_LIQUIDITY tokens to prevent getPooledApeByShares return 0
Expand All @@ -60,7 +62,7 @@ contract AutoCompoundApe is
_mint(onBehalf, amountShare);

_transferTokenIn(msg.sender, amount);
_harvest();
_harvest(rewardAmount);
_compound();

emit Transfer(address(0), onBehalf, amount);
Expand All @@ -71,10 +73,11 @@ contract AutoCompoundApe is
function withdraw(uint256 amount) external override {
require(amount > 0, "zero amount");

uint256 amountShare = getShareByPooledApe(amount);
uint256 rewardAmount = _getRewardApeBalance();
uint256 amountShare = _getShareByPooledApe(amount, rewardAmount);
_burn(msg.sender, amountShare);

_harvest();
_harvest(rewardAmount);
uint256 _bufferBalance = bufferBalance;
if (amount > _bufferBalance) {
_withdrawFromApeCoinStaking(amount - _bufferBalance);
Expand All @@ -89,21 +92,22 @@ contract AutoCompoundApe is

/// @inheritdoc IAutoCompoundApe
function harvestAndCompound() external {
_harvest();
_harvest(_getRewardApeBalance());
_compound();
}

function _getTotalPooledApeBalance()
internal
view
override
returns (uint256)
{
function _getRewardApeBalance() internal view override returns (uint256) {
uint256 rewardAmount = apeStaking.pendingRewards(
APE_COIN_POOL_ID,
address(this),
0
);
return rewardAmount;
}

function _getTotalPooledApeBalance(
uint256 rewardAmount
) internal view override returns (uint256) {
return stakingBalance + rewardAmount + bufferBalance;
}

Expand Down Expand Up @@ -135,12 +139,7 @@ contract AutoCompoundApe is
}
}

function _harvest() internal {
uint256 rewardAmount = apeStaking.pendingRewards(
APE_COIN_POOL_ID,
address(this),
0
);
function _harvest(uint256 rewardAmount) internal {
if (rewardAmount > 0) {
uint256 balanceBefore = apeCoin.balanceOf(address(this));
apeStaking.claimSelfApeCoin();
Expand Down
7 changes: 4 additions & 3 deletions contracts/apestaking/AutoYieldApe.sol
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,10 @@ contract AutoYieldApe is
address recipient,
uint256 amount
) internal override {
require(sender != recipient, Errors.SENDER_SAME_AS_RECEIVER);
_updateYieldIndex(sender, -(amount.toInt256()));
_updateYieldIndex(recipient, amount.toInt256());
if (sender != recipient) {
_updateYieldIndex(sender, -(amount.toInt256()));
_updateYieldIndex(recipient, amount.toInt256());
}
super._transfer(sender, recipient, amount);
}
}
Loading
Loading