Skip to content

Commit

Permalink
Merge pull request #118 from SoarinSkySagar/sync
Browse files Browse the repository at this point in the history
feat: function claim_rewards for claiming DeFi Spring rewards
  • Loading branch information
djeck1432 authored Oct 29, 2024
2 parents 704c8d7 + c9cedfd commit 351caf8
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 55 deletions.
4 changes: 2 additions & 2 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
name = "spotnet"
version = "0.1.0"
edition = "2024_07"
cairo-version = "2.8.4"
cairo-version = "2.8.2"

# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html

[dependencies]
starknet = "2.8.4"
starknet = "2.8.2"
ekubo = { git = "https://github.com/ekuboprotocol/abis", rev = "edb6de8" }
alexandria_math = { git = "https://github.com/keep-starknet-strange/alexandria.git", rev = "8208871" }
openzeppelin_token = "0.17.0"
Expand Down
23 changes: 20 additions & 3 deletions src/deposit.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ mod Deposit {
use openzeppelin_token::erc20::interface::{ERC20ABIDispatcher, ERC20ABIDispatcherTrait};
use spotnet::constants::ZK_SCALE_DECIMALS;

use spotnet::interfaces::{IMarketDispatcher, IMarketDispatcherTrait, IDeposit};
use spotnet::types::{SwapData, SwapResult, DepositData};
use spotnet::interfaces::{
IMarketDispatcher, IMarketDispatcherTrait, IAirdropDispatcher, IAirdropDispatcherTrait,
IDeposit
};
use spotnet::types::{SwapData, SwapResult, DepositData, Claim};

use starknet::event::EventEmitter;
use starknet::storage::{StoragePointerWriteAccess, StoragePointerReadAccess};
Expand Down Expand Up @@ -85,7 +88,7 @@ mod Deposit {
#[derive(Drop, starknet::Event)]
enum Event {
LiquidityLooped: LiquidityLooped,
PositionClosed: PositionClosed
PositionClosed: PositionClosed,
}

#[generate_trait]
Expand Down Expand Up @@ -325,6 +328,20 @@ mod Deposit {
}
);
}

fn claim_rewards(
ref self: ContractState,
claim_data: Claim,
proof: Span<felt252>,
airdrop_addr: ContractAddress
) {
assert(self.is_position_open.read(), 'Position is not open');
assert(proof.len() != 0, 'Proof Span cannot be empty');

let airdrop_disp = IAirdropDispatcher { contract_address: airdrop_addr };

assert(airdrop_disp.claim(claim_data, proof), 'Claim failed');
}
}

#[abi(embed_v0)]
Expand Down
14 changes: 13 additions & 1 deletion src/interfaces.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ekubo::types::keys::PoolKey;
use spotnet::types::{MarketReserveData, DepositData};
use spotnet::types::{MarketReserveData, DepositData, Claim};
use starknet::{ContractAddress};

#[starknet::interface]
Expand All @@ -20,6 +20,13 @@ pub trait IDeposit<TContractState> {
supply_price: u256,
debt_price: u256
);

fn claim_rewards(
ref self: TContractState,
claim_data: Claim,
proof: Span<felt252>,
airdrop_addr: ContractAddress
);
}

#[starknet::interface]
Expand All @@ -38,3 +45,8 @@ pub trait IMarket<TContractState> {
fn repay(ref self: TContractState, token: ContractAddress, amount: felt252);
fn repay_all(ref self: TContractState, token: ContractAddress);
}

#[starknet::interface]
pub trait IAirdrop<TContractState> {
fn claim(ref self: TContractState, claim: Claim, proof: Span<felt252>) -> bool;
}
7 changes: 7 additions & 0 deletions src/types.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,10 @@ pub struct MarketReserveData {
liquidation_bonus: felt252,
debt_limit: felt252
}

#[derive(Copy, Drop, Serde)]
pub struct Claim {
pub id: u64,
pub claimee: ContractAddress,
pub amount: u128
}
4 changes: 2 additions & 2 deletions tests/interfaces.cairo
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use starknet::ContractAddress;
use spotnet::types::MarketReserveData;
use starknet::ContractAddress;

#[starknet::interface]
pub trait IMarketTesting<TContractState> {
fn get_reserve_data(self: @TContractState, token: ContractAddress) -> MarketReserveData;
fn get_user_debt_for_token(
self: @TContractState, user: ContractAddress, token: ContractAddress
) -> felt252;

fn liquidate(
ref self: TContractState,
user: ContractAddress,
Expand Down
Loading

0 comments on commit 351caf8

Please sign in to comment.