Skip to content
Merged
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
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,5 +252,39 @@ function getCurrentCollateralRatio(address who, address currencyId) external vie
function getDebitExchangeRate(address currencyId) external view returns (uint256);
```

### Incentives
- Incentives contract address: `ADDRESS.Incentives`
```
enum PoolId { LOANS, DEX }

// Gets reward amount in `rewardCurrency` added per period
// Returns (reward_amount)
function getIncentiveRewardAmount(PoolId pool, address poolCurrencyId, address rewardCurrencyId) external view returns (uint256);

// Fixed reward rate for dex reward pool per period
// Returns (dex_reward_rate) as a FixedU128 representing a decimal
function getDexRewardRate(address currencyId) external view returns (uint256);

// Stake LP token to add shares to PoolId::Dex
// Returns a boolean value indicating whether the operation succeeded.
function depositDexShare(address currencyId, uint256 amount) external returns (bool);

// Unstake LP token to remove shares from PoolId::Dex
// Returns a boolean value indicating whether the operation succeeded.
function withdrawDexShare(address currencyId, uint256 amount) external returns (bool);

// Claim all avalible multi currencies rewards for specific PoolId
// Returns a boolean value indicating whether the operation succeeded.
function claimRewards(PoolId pool, address poolCurrencyId) external returns (bool);

// Gets deduction rate for claiming reward early
// returns (claim_reward_deduction_rate) as a FixedU128 representing a decimal value
function getClaimRewardDeductionRate(PoolId pool, address poolCurrencyId) external view returns (uint256);

// Gets the pending rewards for a pool, actual reward could be deducted.
// returns (balances), an array of reward balances corresponding to currencyIds
function getPendingRewards(address[] calldata currencyIds, PoolId pool, address poolCurrencyId, address who) external view returns (uint256[] memory);
```

## DeFi Contracts (Coming Soon)
These contracts will make Acala's DeFi primitives (stablecoin, staking derivative, and DeX) available in Acala EVM.
146 changes: 146 additions & 0 deletions contracts/incentives/Incentives.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity ^0.8.0;

import "./InterfaceIncentives.sol";

contract Incentives is InterfaceIncentives {
address constant private precompile = address(0x000000000000000000000000000000000000040A);

/**
* @dev Gets reward amount in `rewardCurrency` added per period
* Returns (reward_amount)
*/
function getIncentiveRewardAmount(PoolId pool, address poolCurrencyId, address rewardCurrencyId)
public
view
override
returns (uint256) {
(bool success, bytes memory returnData) = precompile.staticcall(abi.encodeWithSignature("getIncentiveRewardAmount(PoolId,address,address)", pool, poolCurrencyId, rewardCurrencyId));
assembly {
if eq(success, 0) {
revert(add(returnData, 0x20), returndatasize())
}
}

return abi.decode(returnData, (uint256));
}

/**
* @dev Fixed reward rate for dex reward pool per period
* returns (dex_reward_rate) as a FixedU128 representing a decimal value
*/
function getDexRewardRate(address currencyId)
public
view
override
returns (uint256) {
(bool success, bytes memory returnData) = precompile.staticcall(abi.encodeWithSignature("getDexRewardRate(address)", currencyId));
assembly {
if eq(success, 0) {
revert(add(returnData, 0x20), returndatasize())
}
}

return abi.decode(returnData, (uint256));
}

/**
* @dev Stake LP token to add shares to PoolId::Dex
* Returns a boolean value indicating whether the operation succeeded.
*/
function depositDexShare(address currencyId, uint256 amount)
public
override
returns (bool) {
require(amount != 0, "Incentives: amount is zero");

(bool success, bytes memory returnData) = precompile.call(abi.encodeWithSignature("depositDexShare(address,address,uint256)", msg.sender, currencyId, amount));
assembly {
if eq(success, 0) {
revert(add(returnData, 0x20), returndatasize())
}
}

emit DepositedShare(msg.sender, currencyId, amount);
return true;
}

/**
* @dev Unstake LP token to remove shares from PoolId::Dex
* Returns a boolean value indicating whether the operation succeeded.
*/
function withdrawDexShare(address currencyId, uint256 amount)
public
override
returns (bool) {
require(amount != 0, "Incentives: amount is zero");

(bool success, bytes memory returnData) = precompile.call(abi.encodeWithSignature("withdrawDexShare(address,address,uint256)", msg.sender, currencyId, amount));
assembly {
if eq(success, 0) {
revert(add(returnData, 0x20), returndatasize())
}
}

emit WithdrewShare(msg.sender, currencyId, amount);
return true;
}

/**
* @dev Claim all avalible multi currencies rewards for specific PoolId
* Returns a boolean value indicating whether the operation succeeded.
*/
function claimRewards(PoolId pool, address poolCurrencyId)
public
override
returns (bool) {
(bool success, bytes memory returnData) = precompile.call(abi.encodeWithSignature("claimRewards(address,PoolId,address)", msg.sender, pool, poolCurrencyId));
assembly {
if eq(success, 0) {
revert(add(returnData, 0x20), returndatasize())
}
}

emit ClaimedRewards(msg.sender, pool, poolCurrencyId);
return true;
}

/**
* @dev Gets deduction rate for claiming reward early
* returns (claim_reward_deduction_rate) as a FixedU128 representing a decimal value
*/
function getClaimRewardDeductionRate(PoolId pool, address poolCurrencyId)
public
view
override
returns (uint256) {
(bool success, bytes memory returnData) = precompile.staticcall(abi.encodeWithSignature("getClaimRewardDeductionRate(PoolId,address)", pool, poolCurrencyId));
assembly {
if eq(success, 0) {
revert(add(returnData, 0x20), returndatasize())
}
}

return abi.decode(returnData, (uint256));
}

/**
* @dev Gets the pending rewards for a pool, actual reward could be deducted.
* returns (balances), an array of reward balances corresponding to currencyIds
*/
function getPendingRewards(address[] calldata currencyIds, PoolId pool, address poolCurrencyId, address who)
public
view
override
returns (uint256[] memory) {
(bool success, bytes memory returnData) = precompile.staticcall(abi.encodeWithSignature("getPendingRewards(address[],PoolId,address,address)", currencyIds, pool, poolCurrencyId, who));
assembly {
if eq(success, 0) {
revert(add(returnData, 0x20), returndatasize())
}
}

return abi.decode(returnData, (uint256[]));
}
}
38 changes: 38 additions & 0 deletions contracts/incentives/InterfaceIncentives.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity ^0.8.0;

interface InterfaceIncentives {
event DepositedShare(address indexed sender, address indexed currencyId, uint256 amount);
event WithdrewShare(address indexed sender, address indexed currencyId, uint256 amount);
event ClaimedRewards(address indexed sender, PoolId indexed pool, address indexed poolCurrencyId);
enum PoolId { LOANS, DEX }

// Gets reward amount in `rewardCurrency` added per period
// Returns (reward_amount)
function getIncentiveRewardAmount(PoolId pool, address poolCurrencyId, address rewardCurrencyId) external view returns (uint256);

// Fixed reward rate for dex reward pool per period
// Returns (dex_reward_rate) as a FixedU128 representing a decimal
function getDexRewardRate(address currencyId) external view returns (uint256);

// Stake LP token to add shares to PoolId::Dex
// Returns a boolean value indicating whether the operation succeeded.
function depositDexShare(address currencyId, uint256 amount) external returns (bool);

// Unstake LP token to remove shares from PoolId::Dex
// Returns a boolean value indicating whether the operation succeeded.
function withdrawDexShare(address currencyId, uint256 amount) external returns (bool);

// Claim all avalible multi currencies rewards for specific PoolId
// Returns a boolean value indicating whether the operation succeeded.
function claimRewards(PoolId pool, address poolCurrencyId) external returns (bool);

// Gets deduction rate for claiming reward early
// returns (claim_reward_deduction_rate) as a FixedU128 representing a decimal value
function getClaimRewardDeductionRate(PoolId pool, address poolCurrencyId) external view returns (uint256);

// Gets the pending rewards for a pool, actual reward could be deducted.
// returns (balances), an array of reward balances corresponding to currencyIds
function getPendingRewards(address[] calldata currencyIds, PoolId pool, address poolCurrencyId, address who) external view returns (uint256[] memory);
}
1 change: 1 addition & 0 deletions contracts/utils/Address.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ export const DEX: "0x0000000000000000000000000000000000000803";
export const Homa: "0x0000000000000000000000000000000000000805";
export const EVMAccounts: "0x0000000000000000000000000000000000000806";
export const Honzon: "0x0000000000000000000000000000000000000807";
export const Incentives: "0x0000000000000000000000000000000000000808";
2 changes: 2 additions & 0 deletions contracts/utils/Address.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const DEX = '0x0000000000000000000000000000000000000803';
const Homa = '0x0000000000000000000000000000000000000805';
const EVMAccounts = '0x0000000000000000000000000000000000000806';
const Honzon = '0x0000000000000000000000000000000000000807';
const Incentives = '0x0000000000000000000000000000000000000808';

module.exports = {
ACA,
Expand Down Expand Up @@ -68,4 +69,5 @@ module.exports = {
Homa,
EVMAccounts,
Honzon,
Incentives,
}
1 change: 1 addition & 0 deletions contracts/utils/Address.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ contract ADDRESS {
address public constant Homa = 0x0000000000000000000000000000000000000805;
address public constant EVMAccounts = 0x0000000000000000000000000000000000000806;
address public constant Honzon = 0x0000000000000000000000000000000000000807;
address public constant Incentives = 0x0000000000000000000000000000000000000808;
}
4 changes: 4 additions & 0 deletions generate/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ const generate = async () => {
const { bytecode: honzon } = await hre.artifacts.readArtifact("Honzon");
bytecodes.push(['Honzon', ethers.utils.getAddress('0x0000000000000000000000000000000000000807'), honzon]);

// add Incentives bytecodes
const { bytecode: incentives } = await hre.artifacts.readArtifact("Incentives");
bytecodes.push(['Incentives', ethers.utils.getAddress('0x0000000000000000000000000000000000000808'), incentives]);

// Maybe each nft will deploy a contract, like the mirrored token.
// add NFT bytecodes
// const { bytecode: nft } = require(`../build/contracts/NFT.json`);
Expand Down
Loading