Skip to content

Commit

Permalink
chore: prepare rewards contract for implementation start
Browse files Browse the repository at this point in the history
Signed-off-by: Urban Vidovič <[email protected]>
  • Loading branch information
pseudobun committed Jan 7, 2025
1 parent 2ceba1c commit c30f7a9
Show file tree
Hide file tree
Showing 9 changed files with 244 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Forc.lock
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ dependencies = [
"std",
]

[[package]]
name = "rewards"
source = "member"
dependencies = [
"market_abi",
"rewards_abi",
"standards git+https://github.com/FuelLabs/sway-standards?tag=v0.6.1#792639cdf391565e6e6a02482ea8a46d9604a6f5",
"std",
"sway_libs",
]

[[package]]
name = "rewards_abi"
source = "member"
dependencies = ["std"]

[[package]]
name = "src-20"
source = "member"
Expand Down
2 changes: 2 additions & 0 deletions Forc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
members = [
# ABIs
"abis/market_abi",
"abis/rewards_abi",
# Contracts
"contracts/market",
"contracts/rewards",
"contracts/src-20",
"contracts/token",
"contracts/pyth-mock",
Expand Down
6 changes: 6 additions & 0 deletions abis/rewards_abi/Forc.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[project]
entry = "abi.sw"
license = "Apache-2.0"
name = "rewards_abi"

[dependencies]
52 changes: 52 additions & 0 deletions abis/rewards_abi/src/abi.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
library;

pub mod structs;

use structs::*;

abi Rewards {
// Get version of the smart contract
fn get_version() -> u8;

// # 0. Activate contract
#[storage(write)]
fn activate_contract(owner: Identity);

// # 1. Set the reward configs to rewardConfig for specific market instance
#[storage(write)]
fn set_reward_config_with_multiplier(market: ContractId, token: AssetId, multiplier: u256);

// # 2. Set the reward token for a swaylend market instance
#[storage(write)]
fn set_reward_config(market: ContractId, token: AssetId);

// # 3. Set the rewards claimed for a list of users - this is for management only
// the rewards claimed are updated in claimInternal function
#[storage(write)]
fn set_rewards_claimed(market: ContractId, users: Vec<Identity>, claimed_amounts: Vec<u256>);

// # 4. Withdraw tokens from the contract
#[storage(read)]
fn withdraw_token(token: AssetId, to: Identity, amount: u256);

// # 5. Transfers the governor rights to a new address
#[storage(write)]
fn transfer_governor(new_governor: Identity);

// # 6. Calculates the amount of a reward token owed to an account
#[storage(read)]
fn get_reward_owed(market: ContractId, account: Identity) -> RewardOwed;

// # 7. Claim rewards of token type from a swaylend market instance to owner address
// This one calls internal claimInternal
#[storage(read, write)]
fn claim(market: ContractId, src: Identity, should_accrue: bool);

// # 8. Claim rewards of token type from a swaylend market instance to a target address
#[storage(read, write)]
fn claim_to(market: ContractId, src: Identity, to: Identity, should_accrue: bool);

// # 9. Set ownership to zero address
#[storage(write)]
fn renounce_ownership();
}
44 changes: 44 additions & 0 deletions abis/rewards_abi/src/structs.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
library;

/// This struct contains config details for a specific market
pub struct RewardConfiguration {
/// Token to use for compounding rewards
token: AssetId,
rescale_factor: u64,
should_upscale: bool,
multiplier: u256,
}

impl RewardConfiguration {
pub fn default() -> Self {
RewardConfiguration {
token: AssetId::zero(),
rescale_factor: 0,
should_upscale: false,
multiplier: 0,
}
}
}

pub struct RewardOwed {
token: AssetId,
owed: u256,
}

impl RewardOwed {
pub fn default() -> Self {
RewardOwed {
token: AssetId::zero(),
owed: 0,
}
}
}

pub enum Error {
AlreadyConfigured: (),
BadData: (),
InvalidUInt64: (),
NotPermitted: (),
NotSupported: (),
TransferOutFailed: (),
}
2 changes: 2 additions & 0 deletions contracts/rewards/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
out
target
11 changes: 11 additions & 0 deletions contracts/rewards/Forc.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[project]
authors = ["Urban Vidovič"]
entry = "main.sw"
license = "Apache-2.0"
name = "rewards"

[dependencies]
market_abi = { path = "../../abis/market_abi" }
rewards_abi = { path = "../../abis/rewards_abi" }
standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.6.1" }
sway_libs = { git = "https://github.com/FuelLabs/sway-libs", tag = "v0.24.0" }
20 changes: 20 additions & 0 deletions contracts/rewards/src/events.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
library;


pub struct GovernorTransferred {
pub old_governor: Identity,
pub new_governor: Identity,
}

pub struct RewardsClaimedSet {
pub user: Identity,
pub market: ContractId,
pub amount: u256,
}

pub struct RewardsClaimed {
pub src: Identity,
pub recipient: Identity,
pub token: AssetId,
pub amount: u256,
}
91 changes: 91 additions & 0 deletions contracts/rewards/src/main.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// SPDX-License-Identifier: MIT

contract;

//
// @title Swaylend's Market Contract
// @notice An efficient monolithic money market protocol
// @author Reserve Labs LTD
//

mod events;

use events::*;
use market_abi::{Market, structs::*,};
use rewards_abi::{Rewards, structs::*,};
use standards::src5::{SRC5, State};
use sway_libs::ownership::*;

// version of the smart contract
const VERSION: u8 = 1_u8;

impl Rewards for Contract {
// Get version of the smart contract
fn get_version() -> u8 {
VERSION
}

// # 0. Activate contract
#[storage(write)]
fn activate_contract(owner: Identity) {
initialize_ownership(owner);
}

// # 1. Set the reward configs to rewardConfig for specific market instance
#[storage(write)]
fn set_reward_config_with_multiplier(market: ContractId, token: AssetId, multiplier: u256) {}

// # 2. Set the reward token for a swaylend market instance
#[storage(write)]
fn set_reward_config(market: ContractId, token: AssetId) {}

// # 3. Set the rewards claimed for a list of users - this is for management only
// the rewards claimed are updated in claimInternal function
#[storage(write)]
fn set_rewards_claimed(market: ContractId, users: Vec<Identity>, claimed_amounts: Vec<u256>) {}

// # 4. Withdraw tokens from the contract
#[storage(read)]
fn withdraw_token(token: AssetId, to: Identity, amount: u256) {}

// # 5. Transfers the governor rights to a new address
#[storage(write)]
fn transfer_governor(new_governor: Identity) {}

// # 6. Calculates the amount of a reward token owed to an account
#[storage(read)]
fn get_reward_owed(market: ContractId, account: Identity) -> RewardOwed {
RewardOwed::default()
}

// # 7. Claim rewards of token type from a swaylend market instance to owner address
// This one calls internal claimInternal
#[storage(read, write)]
fn claim(market: ContractId, src: Identity, should_accrue: bool) {}

// # 8. Claim rewards of token type from a swaylend market instance to a target address
#[storage(read, write)]
fn claim_to(market: ContractId, src: Identity, to: Identity, should_accrue: bool) {}

// # 9. Set ownership to zero address
#[storage(write)]
fn renounce_ownership() {}
}

impl SRC5 for Contract {
#[storage(read)]
fn owner() -> State {
_owner()
}
}

// Claim to, assuming permitted
fn claim_internal(market: ContractId, src: Identity, to: Identity, should_accrue: bool) {}

// Calculates the reward accrued for an account on a Comet deployment
fn get_reward_accrued(market: ContractId, account: Identity, config: RewardConfiguration) -> u256 {
u256::zero()
}

// Safe ERC20 transfer out
fn transfer_out(token: AssetId, to: Identity, amount: u256) {}

0 comments on commit c30f7a9

Please sign in to comment.