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

Ape Staking V2 #403

Merged
merged 106 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
2aca3a0
feat: improve auto compound
GopherJ May 4, 2023
09205a5
chore: fallback to onchain slippage
GopherJ May 4, 2023
4935ac5
feat: change p2p fee logic
GopherJ May 4, 2023
35f9863
feat: seperate compoundBot & matchingOperator
GopherJ May 6, 2023
807b966
feat: put slippage offchain
GopherJ May 6, 2023
7b42745
fix: lint
GopherJ May 6, 2023
6e1c2dd
fix: typo
GopherJ May 6, 2023
c686c37
chore: gas optimize
GopherJ May 6, 2023
cc60418
fix: gas optimize
GopherJ May 6, 2023
4270ed3
fix: check swapAmount before transfer
GopherJ May 6, 2023
a174e33
fix: part of tests
GopherJ May 8, 2023
ec2dc1c
fix: auto compound tests
GopherJ May 8, 2023
b6a3b37
chore: cleanup
GopherJ May 8, 2023
ffef685
fix: remove unused bot params
GopherJ May 8, 2023
4f21916
fix: increase precision
GopherJ May 8, 2023
a372a1a
chore: use real price
GopherJ May 8, 2023
5980e00
chore: use swapPercent instead
GopherJ May 8, 2023
0d81db9
Merge branch 'main' into improve/auto-compound
GopherJ May 10, 2023
c33aee9
chore: update verify docs & add shelljs
GopherJ May 10, 2023
f03f9c7
Merge remote-tracking branch 'origin/main' into improve/auto-compound
GopherJ May 16, 2023
922e77a
chore: update submodules
GopherJ May 16, 2023
3a3f074
chore: add safe owner interface
GopherJ May 16, 2023
52ca0b2
chore: use https for ethereumjs-abi
GopherJ May 16, 2023
734ae74
chore: try fix ci
GopherJ May 16, 2023
3322f6e
chore: add missing phantom enum items
GopherJ May 19, 2023
833bf75
chore: remove matching operator feature
zhoujia6139 Jun 13, 2023
8992d77
chore: allow transfer to sender address
zhoujia6139 Jun 13, 2023
efb8f0d
chore: add pause and ACL for P2P
zhoujia6139 Jun 13, 2023
4c51fac
chore: fix FUN-POOL-05: User can withdraw $APE without timeLock
zhoujia6139 Jun 15, 2023
400fae0
chore: fix bakc owner check
zhoujia6139 Jun 15, 2023
ad58564
chore: cache storage variable to save gas
zhoujia6139 Jun 15, 2023
a21896e
chore: small gas optimization
zhoujia6139 Jun 15, 2023
8fbb200
chore: fix some code style
zhoujia6139 Jun 15, 2023
7ecd60c
chore: update some storage variable to immutable to save gas.
zhoujia6139 Jun 15, 2023
16848c3
chore: cache reward amount to avoid fetch from ApeCoinStaking twice.
zhoujia6139 Jun 19, 2023
f29f946
chore: allow user set sape as collateral
zhoujia6139 Jun 20, 2023
54288cb
chore: fix lint and rename variable
zhoujia6139 Jun 20, 2023
0b0cc6a
chore: add p2p pause and test case
zhoujia6139 Jun 20, 2023
e0a113f
chore: don't need to check hf if sApe is not set as collateral
zhoujia6139 Jun 20, 2023
3cf5ed9
chore: small fix
zhoujia6139 Jun 21, 2023
317a9b9
chore: add test case and gas optimization
zhoujia6139 Jun 21, 2023
cd61586
chore: basic logic for pair staking
zhoujia6139 Jul 3, 2023
797849d
chore: pair staking test case
zhoujia6139 Jul 5, 2023
e4765ec
chore: bayc + mayc + bakc base logic and test case
zhoujia6139 Jul 6, 2023
7498945
chore: spit logic contact to reduce contract size
zhoujia6139 Jul 7, 2023
e439449
chore: add owner interface
zhoujia6139 Jul 7, 2023
9774dcf
chore: compound fee
zhoujia6139 Jul 7, 2023
ad76019
chore: fix compound fee
zhoujia6139 Jul 8, 2023
dec78f6
chore: refactor and add test case
zhoujia6139 Jul 10, 2023
a47977c
chore: add pending reward interface
zhoujia6139 Jul 10, 2023
ac73a54
chore: add multicall
zhoujia6139 Jul 11, 2023
e8404ca
chore: small optimization
zhoujia6139 Jul 12, 2023
dd4e2bb
chore: fix bakc single pool issue
zhoujia6139 Jul 12, 2023
ee5b36b
chore: gas optimization
zhoujia6139 Jul 12, 2023
610e8ed
chore: refactor and gas optimization
zhoujia6139 Jul 13, 2023
73a73ec
chore: fix p2p logic
zhoujia6139 Jul 13, 2023
91cd6f0
chore: use one-time approve
zhoujia6139 Jul 14, 2023
78cbb45
chore: rename script
zhoujia6139 Jul 14, 2023
ee177cb
chore: add comment and small optimization
zhoujia6139 Jul 14, 2023
8d0c5cb
chore: remove unused storage
zhoujia6139 Jul 17, 2023
2d382b0
chore: vault optimization and fix
zhoujia6139 Jul 18, 2023
7c82970
chore: Ape coin pool
zhoujia6139 Jul 19, 2023
7e8079e
chore: ape coin pool logic implementation
zhoujia6139 Jul 20, 2023
2a50966
chore: add pool ape staking test case.
zhoujia6139 Jul 24, 2023
63e5244
chore: small optimization
zhoujia6139 Jul 24, 2023
82e7a24
chore: add test case and fix lint
zhoujia6139 Jul 24, 2023
08c01a8
chore: remove ApeCoinPoolState
zhoujia6139 Jul 25, 2023
1c5c943
chore: refactor pool state and bakc single pool
zhoujia6139 Jul 25, 2023
f53f163
chore: add pool borrow and stake
zhoujia6139 Jul 27, 2023
4702119
chore: auto claim reward when nToken owner change.
zhoujia6139 Jul 27, 2023
725c7a7
chore: auto claim test case
zhoujia6139 Jul 27, 2023
9924c4c
chore: reduce contract size
zhoujia6139 Jul 28, 2023
4a3dce9
chore: gas optimization
zhoujia6139 Jul 28, 2023
d954418
chore: add time lock for sApe
zhoujia6139 Jul 29, 2023
1e5a776
chore: reduce contract size
zhoujia6139 Jul 31, 2023
31ea327
chore:support ape coin order as sApe balance
zhoujia6139 Aug 1, 2023
5839f00
chore: update constant hash value
zhoujia6139 Aug 1, 2023
86a15f1
chore: ApeCoin Order sApe liquidation
zhoujia6139 Aug 1, 2023
a7dc3ee
chore: small optimization
zhoujia6139 Aug 1, 2023
5843b04
chore: add query interface
zhoujia6139 Aug 2, 2023
4093145
chore: remove burn callback
zhoujia6139 Aug 2, 2023
9810d8b
chore: optimization
zhoujia6139 Aug 2, 2023
2dbac09
chore: fix compound fee.
zhoujia6139 Aug 2, 2023
26ee4df
chore: refactor query and claim pendign reward
zhoujia6139 Aug 2, 2023
6d03eec
chore: update token status query interface
zhoujia6139 Aug 3, 2023
7a4142a
chore: simplify poolTokenStatus
zhoujia6139 Aug 3, 2023
8b85cbc
chore: add comment
zhoujia6139 Aug 3, 2023
c4b0cec
chore: fix review issue and some optimization
zhoujia6139 Aug 4, 2023
cbdf4be
chore: unstake user ape staking position when hf < 1
zhoujia6139 Aug 7, 2023
eaf96e2
chore: fix review issue
zhoujia6139 Aug 7, 2023
13516b3
chore: add event definition and remove P2P contract
zhoujia6139 Aug 8, 2023
a784db1
chore: fix lint
zhoujia6139 Aug 8, 2023
940cb09
merge main branch
zhoujia6139 Aug 15, 2023
82b12d8
chore: fix typo
zhoujia6139 Aug 15, 2023
94dde81
chore: merge main
zhoujia6139 Sep 5, 2023
411eac7
chore: merge main
zhoujia6139 Sep 6, 2023
9fdd1e7
chore: merge v1 and v2 logic
zhoujia6139 Sep 6, 2023
e28bf3e
chore: keep deprecated data slot
zhoujia6139 Sep 6, 2023
57e6b26
chore: pool ape staking migration
zhoujia6139 Sep 8, 2023
c108a66
chore: p2p migration
zhoujia6139 Sep 13, 2023
02e0ee2
chore: small optimization
zhoujia6139 Sep 13, 2023
9aaaab7
chore: check ntoken owner when migration
zhoujia6139 Oct 13, 2023
88f5805
chore: merge main
zhoujia6139 Oct 13, 2023
7272557
chore: fix test case
zhoujia6139 Oct 13, 2023
0f9b99b
chore: add gas test case
zhoujia6139 Nov 9, 2023
9f0e634
chore: merge apestakingV2
zhoujia6139 Dec 11, 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
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