Skip to content

Commit

Permalink
more audit picks
Browse files Browse the repository at this point in the history
  • Loading branch information
DevRozaDev committed Nov 28, 2024
1 parent 717915b commit a2af455
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion contracts/collections/reserves.ral
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Abstract Contract Reserves() {
return xId, yId
}


// SKIP FUNCTION
@using(updateFields = true, preapprovedAssets = true)
fn initReserve(caller: Address, reservePath: ByteVec, assetsToStore: U256) -> ByteVec {
let (encodedImmFields, encodedMutFields) = Reserve.encodeFields!(selfAddress!(), assetsToStore)
Expand Down
16 changes: 16 additions & 0 deletions contracts/invariant.ral
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,17 @@ Contract Invariant(
pools[key] = pool
}

// T2CHECK - Pool creation
@using(preapprovedAssets = true, checkExternalCaller = false)
pub fn createPool(token0: ByteVec, token1: ByteVec, feeTier: FeeTier, initSqrtPrice: SqrtPrice, initTick: I256) -> () {
assert!(feeTierExist(feeTier), InvariantError.FeeTierNotFound)

// SKIP
clamm.checkTick(initTick, feeTier.tickSpacing)

assert!(token0 != token1, InvariantError.TokensAreSame)

// SKIP
assert!(clamm.checkTickToSqrtPriceRelationship(initTick, feeTier.tickSpacing, initSqrtPrice), InvariantError.TickAndSqrtPriceMismatch)

let caller = callerAddress!()
Expand All @@ -93,6 +96,7 @@ Contract Invariant(
addPoolKey{caller -> ALPH: mapEntryDeposit}(caller, poolKey)
addPool{caller -> ALPH: mapEntryDeposit * 4}(caller, poolKey, initSqrtPrice, initTick, timestamp, config.admin)
}
// T2CHECK_END

@using(preapprovedAssets = true, updateFields = true)
pub fn addFeeTier(feeTier: FeeTier) -> () {
Expand Down Expand Up @@ -185,6 +189,7 @@ Contract Invariant(
)
}

// T2CHECK - Position creation
@using(preapprovedAssets = true, checkExternalCaller = false)
pub fn createPosition(
poolKey: PoolKey,
Expand Down Expand Up @@ -251,6 +256,9 @@ Contract Invariant(
Reserve(pool.reserveY).depositSingleAsset{caller -> pool.poolKey.tokenY: y.v}(caller, pool.poolKey.tokenY, y)
}
}
// T2CHECK_END

// T2CHECK - Position removal
@using(checkExternalCaller = false)
pub fn removePosition(index: U256) -> () {
let caller = callerAddress!()
Expand All @@ -264,6 +272,7 @@ Contract Invariant(

let (_, pool) = wrappedGetPool(poolKey)

// SKIP
let (mut x, mut y, mPosition, isLowerEmpty, isUpperEmpty) = modify(position, pool, lowerTick, upperTick, position.liquidity, false, blockTimeStamp!())

x.v = x.v + mPosition.tokensOwedX.v
Expand All @@ -287,6 +296,7 @@ Contract Invariant(

wrappedRemovePosition(caller, index)
}
// T2CHECK_END

@using(preapprovedAssets = true, checkExternalCaller = false)
pub fn transferPosition(index: U256, newOwner: Address) -> () {
Expand Down Expand Up @@ -403,6 +413,7 @@ Contract Invariant(
}
}

// T2CHECK - Swap
@using(preapprovedAssets = true, checkExternalCaller = false)
pub fn swap(
poolKey: PoolKey,
Expand All @@ -412,6 +423,7 @@ Contract Invariant(
sqrtPriceLimit: SqrtPrice
) -> CalculateSwapResult {
let caller = callerAddress!()
// SKIP - assume correct values
let calculateSwapResult = calculateSwap(poolKey, xToY, amount, byAmountIn, sqrtPriceLimit)

let (_, pool) = wrappedGetPool(poolKey)
Expand All @@ -436,7 +448,9 @@ Contract Invariant(

return calculateSwapResult
}
// T2CHECK_END

// T2CHECK - Fee collection
// caller is checked in `wrappedGetPosition`
@using(checkExternalCaller = false)
pub fn claimFee(index: U256) -> () {
Expand All @@ -450,6 +464,7 @@ Contract Invariant(
let (_, upperTick) = wrappedGetTick(poolKey, position.upperTickIndex)
let (_, lowerTick) = wrappedGetTick(poolKey, position.lowerTickIndex)

// SKIP
let (_, _, mut mPosition, _, _) = modify(position, pool, lowerTick, upperTick, Liquidity{v: 0}, false, blockTimeStamp!())

let tokensOwedX = mPosition.tokensOwedX
Expand All @@ -467,6 +482,7 @@ Contract Invariant(
Reserve(pool.reserveY).withdrawSingleAsset(caller, pool.poolKey.tokenY, tokensOwedY)
}
}
// T2CHECK_END

fn getSingleBatch(poolKey: PoolKey, index: U256) -> ByteVec {
let mut batch = #
Expand Down
3 changes: 3 additions & 0 deletions contracts/storage/reserve.ral
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Contract Reserve(invariant: Address, mut assetsStored: U256) {
assetsStored = assetsStored + by
}

// SKIP FUNCTION
pub fn getAssetsCount() -> U256 {
return assetsStored
}
Expand All @@ -19,6 +20,7 @@ Contract Reserve(invariant: Address, mut assetsStored: U256) {
transferTokenToSelf!(from, id, amount.v)
}

// SAME THING AS FUNCTION ABOVE
@using(preapprovedAssets = true, assetsInContract = true)
pub fn depositTwoAssets(from: Address, xId: ByteVec, yId: ByteVec, x: TokenAmount, y: TokenAmount) -> () {
let caller = callerAddress!()
Expand All @@ -34,6 +36,7 @@ Contract Reserve(invariant: Address, mut assetsStored: U256) {
transferTokenFromSelf!(to, id, amount.v)
}

// SAME THING AS FUNCTION ABOVE
@using(assetsInContract = true)
pub fn withdrawTwoAssets(to: Address, xId: ByteVec, yId: ByteVec, x: TokenAmount, y: TokenAmount) -> () {
let caller = callerAddress!()
Expand Down

0 comments on commit a2af455

Please sign in to comment.