Skip to content

Commit

Permalink
feat: upgrade to cairo v2.6.3 (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
xJonathanLEI authored Apr 12, 2024
1 parent 9562840 commit c31ff97
Show file tree
Hide file tree
Showing 29 changed files with 187 additions and 192 deletions.
2 changes: 1 addition & 1 deletion scripts/check_format_with_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ REPO_ROOT=$( cd -- "$( dirname $( dirname "$0" ) )" &> /dev/null && pwd )
docker run --rm \
-v "${REPO_ROOT}:/work" \
--entrypoint "cairo-format" \
starknet/cairo:2.1.0 \
starknet/cairo:2.6.3 \
-c -r /work
2 changes: 1 addition & 1 deletion scripts/compile_with_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ docker run --rm \
--env "USER_ID=$(id -u)" \
--env "GROUP_ID=$(id -g)" \
--entrypoint sh \
starknet/cairo:2.1.0 \
starknet/cairo:2.6.3 \
-c "cd /work && ./scripts/compile.sh"
2 changes: 1 addition & 1 deletion scripts/run_tests_with_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ REPO_ROOT=$( cd -- "$( dirname $( dirname "$0" ) )" &> /dev/null && pwd )
docker run --rm \
-v "${REPO_ROOT}:/work" \
--entrypoint "cairo-test" \
starknet/cairo:2.1.0 \
starknet/cairo:2.6.3 \
--starknet /work
4 changes: 2 additions & 2 deletions src/default_price_oracle.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ mod DefaultPriceOracle {
ownable::initializer(ref self, owner);
}

#[external(v0)]
#[abi(embed_v0)]
impl IPriceOracleImpl of IPriceOracle<ContractState> {
fn get_price(self: @ContractState, token: ContractAddress) -> felt252 {
let source = self.sources.read(token);
Expand All @@ -61,7 +61,7 @@ mod DefaultPriceOracle {
}
}

#[external(v0)]
#[abi(embed_v0)]
impl IDefaultPriceOracleImpl of IDefaultPriceOracle<ContractState> {
fn set_token_source(
ref self: ContractState, token: ContractAddress, source: ContractAddress
Expand Down
9 changes: 6 additions & 3 deletions src/irms/default_interest_rate_model.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ mod DefaultInterestRateModel {
self.curve_params.write(CurveParams { slope_0, slope_1, y_intercept, optimal_rate });
}

#[external(v0)]
#[abi(embed_v0)]
impl IInterestRateModelImpl of IInterestRateModel<ContractState> {
fn get_interest_rates(
self: @ContractState, reserve_balance: felt252, total_debt: felt252
Expand Down Expand Up @@ -73,8 +73,11 @@ mod DefaultInterestRateModel {
fn calculate_borrow_rate(self: @ContractState, utilization_rate: felt252) -> felt252 {
let params = self.curve_params.read();

let below_optimal_rate = Into::<_,
u256>::into(utilization_rate) <= Into::<_, u256>::into(params.optimal_rate);
let below_optimal_rate = Into::<
_, u256
>::into(utilization_rate) <= Into::<
_, u256
>::into(params.optimal_rate);

if below_optimal_rate {
let temp_1 = safe_decimal_math::div(utilization_rate, params.optimal_rate);
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/pow.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ mod tests {
}

#[test]
#[should_panic(expected: ('POW_DEC_TOO_LARGE', ))]
#[should_panic(expected: ('POW_DEC_TOO_LARGE',))]
fn test_two_pow_overflow() {
super::two_pow(252);
}
Expand All @@ -717,7 +717,7 @@ mod tests {
}

#[test]
#[should_panic(expected: ('POW_DEC_TOO_LARGE', ))]
#[should_panic(expected: ('POW_DEC_TOO_LARGE',))]
fn test_ten_pow_overflow() {
super::ten_pow(76);
}
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/safe_decimal_math.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ mod tests {
}

#[test]
#[should_panic(expected: ('SM_MUL_OF', ))]
#[should_panic(expected: ('SM_MUL_OF',))]
fn test_mul_overflow() {
super::mul(
0x400000000000000000000000000000000000000000000000000000000000000,
Expand All @@ -58,7 +58,7 @@ mod tests {
}

#[test]
#[should_panic(expected: ('SM_MUL_OF', ))]
#[should_panic(expected: ('SM_MUL_OF',))]
fn test_mul_decimals_overflow() {
super::mul_decimals(
0x400000000000000000000000000000000000000000000000000000000000000,
Expand Down
14 changes: 7 additions & 7 deletions src/libraries/safe_math.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ mod tests {
}

#[test]
#[should_panic(expected: ('SM_ADD_OF', ))]
#[should_panic(expected: ('SM_ADD_OF',))]
fn test_add_overflow_1() {
super::add(0x800000000000011000000000000000000000000000000000000000000000000, 1);
}

#[test]
#[should_panic(expected: ('SM_ADD_OF', ))]
#[should_panic(expected: ('SM_ADD_OF',))]
fn test_add_overflow_2() {
super::add(
0x800000000000011000000000000000000000000000000000000000000000000,
Expand All @@ -87,13 +87,13 @@ mod tests {
}

#[test]
#[should_panic(expected: ('SM_SUB_UF', ))]
#[should_panic(expected: ('SM_SUB_UF',))]
fn test_sub_underflow_1() {
super::sub(0, 1);
}

#[test]
#[should_panic(expected: ('SM_SUB_UF', ))]
#[should_panic(expected: ('SM_SUB_UF',))]
fn test_sub_underflow_2() {
super::sub(
0x100000000000000000000000000000000,
Expand All @@ -116,13 +116,13 @@ mod tests {
}

#[test]
#[should_panic(expected: ('SM_MUL_OF', ))]
#[should_panic(expected: ('SM_MUL_OF',))]
fn test_mul_felt_overflow() {
super::mul(0x400000000000008800000000000000000000000000000000000000000000000, 3);
}

#[test]
#[should_panic(expected: ('SM_MUL_OF', ))]
#[should_panic(expected: ('SM_MUL_OF',))]
fn test_mul_uint256_overflow() {
super::mul(0x400000000000000000000000000000000000000000000000000000000000000, 0x20);
}
Expand All @@ -147,7 +147,7 @@ mod tests {
}

#[test]
#[should_panic(expected: ('SM_DIV_ZERO', ))]
#[should_panic(expected: ('SM_DIV_ZERO',))]
fn test_div_division_by_zero() {
super::div(999, 0);
}
Expand Down
7 changes: 6 additions & 1 deletion src/market.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ mod traits;
mod errors;
mod storage;

struct UpdatedAccumulators {
lending_accumulator: felt252,
debt_accumulator: felt252
}

#[starknet::contract]
mod Market {
use starknet::{ClassHash, ContractAddress};
Expand Down Expand Up @@ -206,7 +211,7 @@ mod Market {
external::initializer(ref self, owner, oracle)
}

#[external(v0)]
#[abi(embed_v0)]
impl IMarketImpl of IMarket<ContractState> {
fn get_reserve_data(self: @ContractState, token: ContractAddress) -> MarketReserveData {
view::get_reserve_data(self, token)
Expand Down
17 changes: 9 additions & 8 deletions src/market/external.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@ use super::traits::{MarketOwnable, MarketReentrancyGuard};
use super::{errors, internal};

use super::Market as contract;
use super::UpdatedAccumulators;

use contract::ContractState;

// These are hacks that depend on compiler implementation details :(
// But they're needed for refactoring the contract code into modules like this one.
use contract::oracleContractStateTrait;
use contract::reserve_countContractStateTrait;
use contract::reserve_indicesContractStateTrait;
use contract::reserve_tokensContractStateTrait;
use contract::reservesContractStateTrait;
use contract::treasuryContractStateTrait;
use contract::oracleContractMemberStateTrait;
use contract::reserve_countContractMemberStateTrait;
use contract::reserve_indicesContractMemberStateTrait;
use contract::reserve_tokensContractMemberStateTrait;
use contract::reservesContractMemberStateTrait;
use contract::treasuryContractMemberStateTrait;

fn initializer(ref self: ContractState, owner: ContractAddress, oracle: ContractAddress) {
assert(owner.is_non_zero(), errors::ZERO_ADDRESS);
Expand Down Expand Up @@ -263,7 +264,7 @@ fn set_interest_rate_model(
internal::assert_reserve_exists(@self, token);

// Settles interest payments up until this point to prevent retrospective changes.
let UpdatedAccumulators{debt_accumulator: updated_debt_accumulator, .. } =
let UpdatedAccumulators { debt_accumulator: updated_debt_accumulator, .. } =
internal::update_accumulators(
ref self, token
);
Expand Down Expand Up @@ -339,7 +340,7 @@ fn set_reserve_factor(ref self: ContractState, token: ContractAddress, reserve_f
internal::assert_reserve_exists(@self, token);

// Settles interest payments up until this point to prevent retrospective changes.
let UpdatedAccumulators{debt_accumulator: updated_debt_accumulator, .. } =
let UpdatedAccumulators { debt_accumulator: updated_debt_accumulator, .. } =
internal::update_accumulators(
ref self, token
);
Expand Down
Loading

0 comments on commit c31ff97

Please sign in to comment.