Skip to content

Commit

Permalink
chore: update apestaking doc and delegation implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoujia6139 committed Dec 25, 2023
1 parent f8dd494 commit 11a94c1
Show file tree
Hide file tree
Showing 20 changed files with 685 additions and 275 deletions.
13 changes: 0 additions & 13 deletions contracts/cross-chain/BridgeDefine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
pragma solidity ^0.8.0;

enum MessageType {
AddNewCrossChainERC721,
BridgeERC721,
ERC721DELEGATION
}

Expand All @@ -12,20 +10,9 @@ struct BridgeMessage {
bytes data;
}

struct BridgeERC721Message {
address asset;
uint256[] tokenIds;
address receiver;
}

struct ERC721DelegationMessage {
address asset;
address delegateTo;
uint256[] tokenIds;
bool value;
}

//library BridgeDefine {
//
//
//}
12 changes: 0 additions & 12 deletions contracts/cross-chain/L1/IParaxBridgeNFTVault.sol

This file was deleted.

6 changes: 1 addition & 5 deletions contracts/cross-chain/L1/IParaxL1MessageHandler.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {MessageType, BridgeMessage, BridgeERC721Message} from "../BridgeDefine.sol";

interface IParaxL1MessageHandler {
function addBridgeAsset(address asset) external;

function bridgeAsset(BridgeERC721Message calldata message) external;
function migration(address asset) external;
}
56 changes: 52 additions & 4 deletions contracts/cross-chain/L1/IVaultApeStaking.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {BridgeERC721Message, ERC721DelegationMessage} from "../BridgeDefine.sol";

interface IVaultApeStaking {
struct TokenStatus {
//record tokenId reward debt position
Expand Down Expand Up @@ -152,38 +150,88 @@ interface IVaultApeStaking {
*/
function compoundBAKC(BAKCPairActionInfo calldata actionInfo) external;

/**
* @notice enter ape staking pool when bayc/mayc/bakc transferred to vault contract.
* It's an interceptor call, can only be called by vault self.
* @param nft Identify pool
* @param tokenId The tokenId of the nft
* @param beneficiary The reward beneficiary for the pool position
*/
function onboardCheckApeStakingPosition(
address nft,
uint32 tokenId,
address beneficiary
) external;

/**
* @notice exit ape staking pool when bayc/mayc/bakc transferred out from vault contract.
* It's an interceptor call, can only be called by vault self.
* @param nft Identify pool
* @param tokenId The tokenId of the nft
*/
function offboardCheckApeStakingPosition(
address nft,
uint32 tokenId
) external;

/**
* @notice unstake the ape coin position on the ape. can only be called by the bot.
* @param isBAYC if Ape is BAYC
* @param tokenIds Ape token ids
*/
function unstakeApe(bool isBAYC, uint32[] calldata tokenIds) external;

/**
* @notice set ape coin staking bot address. can only be called by pool admin.
*/
function setApeStakingBot(address _apeStakingBot) external;

/**
* @notice set compound fee rate. can only be called by pool admin.
*/
function setCompoundFeeRate(uint32 _compoundFeeRate) external;

/**
* @notice set cApe income rate. can only be called by pool admin.
* @param nft Identify pool
* @param rate new cApe income rate
*/
function setCApeIncomeRate(address nft, uint32 rate) external;

/**
* @notice claim compound fee. can only be called by bot.
*/
function claimCompoundFee(address receiver) external;

/**
* @notice update the position reward beneficiary. can only be called by bridge.
*Nft owner can launch the cross-chain calling from L2
* @param nft Identify pool
* @param tokenIds The tokenIds of the nft
*/
function updateBeneficiary(
address nft,
uint32[] calldata tokenIds,
address newBenificiary
) external;

/**
* @notice Pauses the contract. Only pool admin or emergency admin can call this function
**/
function pause() external;

/**
* @notice Unpause the contract. Only pool admin can call this function
**/
function unpause() external;

/**
* @notice initialization operation for the vault
**/
function initialize() external;

/**
* @notice fetch accumulated compound fee.
**/
function compoundFee() external view returns (uint256);

function setCApeIncomeRate(address nft, uint32 rate) external;
}
11 changes: 11 additions & 0 deletions contracts/cross-chain/L1/IVaultParaX.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IVaultParaX {
function updateTokenDelegation(
address delegateTo,
address asset,
uint256[] calldata tokenIds,
bool value
) external;
}
90 changes: 0 additions & 90 deletions contracts/cross-chain/L1/ParaxBridgeNFTVault.sol

This file was deleted.

42 changes: 16 additions & 26 deletions contracts/cross-chain/L1/ParaxL1MessageHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,38 @@
pragma solidity ^0.8.0;
pragma abicoder v2;

import {MessageType, BridgeMessage, BridgeERC721Message} from "../BridgeDefine.sol";
import {MessageType, BridgeMessage, ERC721DelegationMessage} from "../BridgeDefine.sol";
import {Errors} from "../../protocol/libraries/helpers/Errors.sol";
import "./IParaxBridgeNFTVault.sol";
import "./IVaultParaX.sol";

contract ParaxL1MessageHandler {
IParaxBridgeNFTVault internal immutable nftVault;
address immutable bridgeImpl;
address internal immutable vault;
address public immutable socket;

constructor(IParaxBridgeNFTVault vault, address bridge) {
nftVault = vault;
bridgeImpl = bridge;
}

modifier onlyVault() {
require(msg.sender == address(nftVault), Errors.ONLY_VAULT);
_;
constructor(address vault_, address bridge) {
vault = vault_;
socket = bridge;
}

modifier onlyBridge() {
require(msg.sender == address(bridgeImpl), Errors.ONLY_BRIDGE);
require(msg.sender == socket, Errors.ONLY_BRIDGE);
_;
}

function addBridgeAsset(address asset) external onlyVault {}

function bridgeAsset(
BridgeERC721Message calldata message
) external onlyVault {}
function migration(address asset) external {}

function bridgeReceive(BridgeMessage calldata message) external onlyBridge {
if (message.msgType == MessageType.BridgeERC721) {
BridgeERC721Message memory erc721Message = abi.decode(
message.data,
(BridgeERC721Message)
);
nftVault.releaseNFT(erc721Message);
} else if (message.msgType == MessageType.ERC721DELEGATION) {
if (message.msgType == MessageType.ERC721DELEGATION) {
ERC721DelegationMessage memory delegationMsg = abi.decode(
message.data,
(ERC721DelegationMessage)
);
nftVault.updateTokenDelegation(delegationMsg);
IVaultParaX(vault).updateTokenDelegation(
delegationMsg.delegateTo,
delegationMsg.asset,
delegationMsg.tokenIds,
delegationMsg.value
);
}
}
}
Loading

0 comments on commit 11a94c1

Please sign in to comment.