Skip to content

Commit

Permalink
mark skipped
Browse files Browse the repository at this point in the history
  • Loading branch information
DevRozaDev committed Nov 29, 2024
1 parent a2af455 commit 96bbfb6
Show file tree
Hide file tree
Showing 22 changed files with 72 additions and 24 deletions.
1 change: 0 additions & 1 deletion contracts/collections/reserves.ral
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ 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
4 changes: 3 additions & 1 deletion contracts/constants.ral
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SKIP
const GLOBAL_MAX_TICK = 547_613i
const GLOBAL_MIN_TICK = -GLOBAL_MAX_TICK

Expand All @@ -7,4 +8,5 @@ const MAX_U256 = 115792089237316195423570985008687907853269984665640564039457584

const MAX_FEE_TIERS = 32

const RESERVE_ASSET_CAPACITY = 8
const RESERVE_ASSET_CAPACITY = 8
// SKIP_END
5 changes: 3 additions & 2 deletions contracts/errors.ral
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Error codes should be unique across all contracts for clarity

// SKIP
enum InvariantError {
NotAdmin = 0
InsufficientLiquidity = 1
Expand Down Expand Up @@ -68,4 +68,5 @@ enum ArithmeticError {

enum FaucetError {
InvalidWithdrawAmount = 200000
}
}
// SKIP_END
14 changes: 9 additions & 5 deletions contracts/invariant.ral
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ Contract Invariant(
return config.protocolFee
}

// T2CHECK
@using(updateFields = true)
pub fn changeProtocolFee(newProtocolFee: Percentage) -> () {
checkCaller!(callerAddress!() == config.admin, InvariantError.NotAdmin)
assert!(newProtocolFee.v < PERCENTAGE_DENOMINATOR, InvariantError.InvalidProtocolFee)
config.protocolFee = newProtocolFee
}
// T2CHECK_END

// T2CHECK
pub fn withdrawProtocolFee(poolKey: PoolKey) -> () {
let caller = callerAddress!()
let (exist, mut pool) = wrappedGetPool(poolKey)
Expand All @@ -63,7 +66,9 @@ Contract Invariant(
Reserve(pool.reserveY).withdrawSingleAsset(caller, pool.poolKey.tokenY, y)
}
}
// T2CHECK_END

// T2CHECK
pub fn changeFeeReceiver(poolKey: PoolKey, newFeeReceiver: Address) -> () {
let caller = callerAddress!()

Expand All @@ -75,18 +80,17 @@ Contract Invariant(
pool.feeReceiver = newFeeReceiver
pools[key] = pool
}
// T2CHECK_END

// 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 Down Expand Up @@ -163,6 +167,7 @@ Contract Invariant(
feeGrowthGlobalY: FeeGrowth,
startTimestamp: U256
) -> () {

clamm.checkTick(index, poolKey.feeTier.tickSpacing)

let mut feeGrowthOutsideX = FeeGrowth{v: 0}
Expand Down Expand Up @@ -272,7 +277,6 @@ 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 @@ -298,13 +302,15 @@ Contract Invariant(
}
// T2CHECK_END

// T2CHECK - Position transfer
@using(preapprovedAssets = true, checkExternalCaller = false)
pub fn transferPosition(index: U256, newOwner: Address) -> () {
let caller = callerAddress!()
assert!(index < positionCount(caller), InvariantError.PositionNotFound)

wrappedTransferPosition{caller -> ALPH: 2 * mapEntryDeposit!()}(caller, index, newOwner)
}
// T2CHECK_END

@using(checkExternalCaller = false)
pub fn quote(
Expand Down Expand Up @@ -423,7 +429,6 @@ 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 Down Expand Up @@ -464,7 +469,6 @@ 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 Down
7 changes: 6 additions & 1 deletion contracts/math/clamm.ral
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
Contract CLAMM(admin: Address) extends Uints(), Log(){
// T1CHECK - Contract upgrade
pub fn upgrade(bytecode: ByteVec) -> () {
checkCaller!(callerAddress!() == admin, InvariantError.NotAdmin)
migrate!(bytecode)
}
// T1CHECK_END

// SKIP
pub fn computeSwapStep(
currentSqrtPrice: SqrtPrice,
targetSqrtPrice: SqrtPrice,
Expand Down Expand Up @@ -294,6 +298,7 @@ Contract CLAMM(admin: Address) extends Uints(), Log(){
return maxLiquidity
}


pub fn checkTicks(tickLower: I256, tickUpper: I256, tickSpacing: U256) -> () {
assert!(tickLower < tickUpper, CLAMMError.InvalidTickIndex)
checkTick(tickLower, tickSpacing)
Expand Down Expand Up @@ -335,5 +340,5 @@ Contract CLAMM(admin: Address) extends Uints(), Log(){
pub fn feeGrowthFromFee(liquidity: Liquidity, fee: TokenAmount) -> FeeGrowth {
return FeeGrowth{v: toU256(bigMulDiv256(fee.v, one(LIQUIDITY_SCALE + FEE_GROWTH_SCALE), liquidity.v))}
}

// SKIP_END
}
2 changes: 2 additions & 0 deletions contracts/math/decimal.ral
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SKIP
Abstract Contract Decimal() {
fn getMaxTick(tickSpacing: U256) -> I256 {
let convertedTickSpacing = toI256!(tickSpacing)
Expand Down Expand Up @@ -176,3 +177,4 @@ Abstract Contract Decimal() {
return feeGrowthInsideX, feeGrowthInsideY
}
}
// SKIP_END
4 changes: 3 additions & 1 deletion contracts/math/log.ral
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SKIP
Abstract Contract Log() extends Decimal() {
const LOG2_SCALE = 64
const LOG2_DOUBLE_SCALE = LOG2_SCALE *2
Expand Down Expand Up @@ -135,4 +136,5 @@ Abstract Contract Log() extends Decimal() {
return accurateTick
}
}
}
}
// SKIP_END
3 changes: 2 additions & 1 deletion contracts/math/types.ral
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SKIP
struct SqrtPrice{
mut v: U256
}
Expand Down Expand Up @@ -38,4 +39,4 @@ struct FixedPoint{
}
const FIXED_POINT_SCALE = 24
const FIXED_POINT_DENOMINATOR = 10**FIXED_POINT_SCALE

// SKIP_END
3 changes: 2 additions & 1 deletion contracts/math/uints.ral
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SKIP
struct U512 {
mut higher: U256,
mut lower: U256
Expand Down Expand Up @@ -222,4 +223,4 @@ Abstract Contract Uints () {
return a.higher == 0 && a.lower == 0
}
}

// SKIP_END
3 changes: 2 additions & 1 deletion contracts/math/uints_old.ral
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SKIP
Contract UintsOld () {
const WORD_SIZE = 256

Expand Down Expand Up @@ -297,4 +298,4 @@ Contract UintsOld () {
return a.higher == 0 && a.lower == 0
}
}

// SKIP_END
10 changes: 10 additions & 0 deletions contracts/scripts/invariant_tx.ral
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SKIP
TxScript AddFeeTier(invariant: Invariant, feeTier: FeeTier) {
invariant.addFeeTier{callerAddress!() -> ALPH: mapEntryDeposit!()}(feeTier)
}
Expand All @@ -21,7 +22,9 @@ TxScript ChangeFeeReceiver(invariant: Invariant, poolKey: PoolKey, newFeeReceive
TxScript WithdrawProtocolFee(invariant: Invariant, poolKey: PoolKey) {
invariant.withdrawProtocolFee(poolKey)
}
// SKIP_END

// T2CHECK
TxScript CreatePosition(
invariant: Invariant,
poolKey: PoolKey,
Expand All @@ -41,7 +44,9 @@ TxScript CreatePosition(
(poolKey, lowerTick, upperTick, liquidityDelta, slippageLimitLower, slippageLimitUpper)
}
}
// T2CHECK_END

// SKIP
TxScript RemovePosition(invariant: Invariant, index: U256) {
invariant.removePosition(index)
}
Expand All @@ -53,7 +58,9 @@ TxScript TransferPosition(invariant: Invariant, index: U256, recipient: Address)
TxScript ClaimFee(invariant: Invariant, index: U256) {
invariant.claimFee(index)
}
// SKIP_END

// T2CHECK
TxScript Swap(invariant: Invariant, poolKey: PoolKey, xToY: Bool, amount: TokenAmount, byAmountIn: Bool, sqrtPriceLimit: SqrtPrice) {
let mut swappedToken = poolKey.tokenX
let mut swappedAmount = amount.v
Expand All @@ -66,7 +73,9 @@ TxScript Swap(invariant: Invariant, poolKey: PoolKey, xToY: Bool, amount: TokenA

let _ = invariant.swap{callerAddress!() -> swappedToken: swappedAmount}(poolKey, xToY, amount, byAmountIn, sqrtPriceLimit)
}
// T2CHECK_END

// T2CHECK
TxScript CreatePoolAndPosition(
invariant: Invariant,
poolKey: PoolKey,
Expand All @@ -90,3 +99,4 @@ TxScript CreatePoolAndPosition(
(poolKey, lowerTick, upperTick, liquidityDelta, slippageLimitLower, slippageLimitUpper)
}
}
// T2CHECK_END
4 changes: 3 additions & 1 deletion contracts/scripts/reserve_tx.ral
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SKIP
TxScript IncrementAssets(reserve: Reserve, by: U256) {
reserve.incrementAssets(by)
}
Expand All @@ -20,4 +21,5 @@ TxScript WithdrawTwoAssets(reserve: Reserve, xId: ByteVec, yId: ByteVec, x: Toke

TxScript SwapAssets(reserve: Reserve, inId: ByteVec, outId: ByteVec, in: TokenAmount, out: TokenAmount) {
reserve.swap{callerAddress!() -> inId: in.v}(callerAddress!(), inId, outId, in, out)
}
}
// SKIP_END
4 changes: 3 additions & 1 deletion contracts/scripts/token_tx.ral
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SKIP
TxScript Withdraw(token: TokenFaucet, amount: U256) {
token.withdraw(amount)
}
Expand All @@ -6,4 +7,5 @@ TxScript Airdrop(tokenOne: TokenFaucet, amountOne: U256, tokenTwo: TokenFaucet,
tokenOne.withdraw(amountOne)
tokenTwo.withdraw(amountTwo)
tokenThree.withdraw(amountThree)
}
}
// SKIP_END
2 changes: 2 additions & 0 deletions contracts/storage/batch.ral
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ Abstract Contract BatchHelper() {
bitmap[key] = batch
}

// SKIP
fn getKey(chunk: U256) -> U256 {
return chunk / CHUNKS_PER_BATCH
}
// SKIP_END
}
4 changes: 4 additions & 0 deletions contracts/storage/pool.ral
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct Pool {
}

Abstract Contract PoolHelper(clamm: CLAMM) extends Decimal() {
// SKIP
fn addFee(mut pool: Pool, amount: TokenAmount, inX: Bool, protocolFee: Percentage) -> Pool {
let invariantProtocolFee = TokenAmount{v: mulUp(amount.v, protocolFee.v, PERCENTAGE_DENOMINATOR)}

Expand All @@ -36,6 +37,7 @@ Abstract Contract PoolHelper(clamm: CLAMM) extends Decimal() {

return pool
}
// SKIP_END

fn updatePoolLiquidity(mut pool: Pool, liquidityDelta: Liquidity, liquiditySign: Bool, upperTick: I256, lowerTick: I256) -> (TokenAmount, TokenAmount, Pool) {
let (x, y, updateLiq) = clamm.calculateAmountDelta(pool.currentTickIndex, pool.sqrtPrice, liquidityDelta, liquiditySign, upperTick, lowerTick)
Expand Down Expand Up @@ -109,6 +111,7 @@ Abstract Contract PoolHelper(clamm: CLAMM) extends Decimal() {
pools[key] = pool
}

// SKIP
fn serializePool(pool: Pool) -> ByteVec {
return pool.poolKey.tokenX ++ b`break`
++ pool.poolKey.tokenY ++ b`break`
Expand All @@ -127,4 +130,5 @@ Abstract Contract PoolHelper(clamm: CLAMM) extends Decimal() {
++ pool.reserveX ++ b`break`
++ pool.reserveY ++ b`break`
}
// SKIP_END
}
4 changes: 4 additions & 0 deletions contracts/storage/position.ral
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Abstract Contract PositionHelper(clamm: CLAMM) extends Decimal() {
return position
}

// SKIP
fn calculateNewLiquidity(
currentPositionLiquidity: Liquidity,
sign: Bool,
Expand All @@ -81,7 +82,9 @@ Abstract Contract PositionHelper(clamm: CLAMM) extends Decimal() {
return Liquidity{v: currentPositionLiquidity.v - liquidityDelta.v}
}
}
// SKIP_END

// SKIP
fn serializePosition(position: Position) -> ByteVec {
return position.poolKey.tokenX ++ b`break`
++ position.poolKey.tokenY ++ b`break`
Expand All @@ -97,4 +100,5 @@ Abstract Contract PositionHelper(clamm: CLAMM) extends Decimal() {
++ toByteVec!(position.tokensOwedY.v) ++ b`break`
++ toByteVec!(position.owner) ++ b`break`
}
// SKIP_END
}
5 changes: 2 additions & 3 deletions contracts/storage/reserve.ral
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ Contract Reserve(invariant: Address, mut assetsStored: U256) {
assetsStored = assetsStored + by
}

// SKIP FUNCTION
// SKIP - query
pub fn getAssetsCount() -> U256 {
return assetsStored
}
// SKIP_END

@using(preapprovedAssets = true, payToContractOnly = true)
pub fn depositSingleAsset(from: Address, id: ByteVec, amount: TokenAmount) -> () {
Expand All @@ -20,7 +21,6 @@ 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 @@ -36,7 +36,6 @@ 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
Loading

0 comments on commit 96bbfb6

Please sign in to comment.