Skip to content

Commit

Permalink
remove unused variables from contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
zielvna committed Apr 9, 2024
1 parent ba40f4c commit 15224ad
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 55 deletions.
6 changes: 2 additions & 4 deletions contracts/collections/pools.ral
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ Contract Pools(
initSqrtPrice: U256,
initTick: I256,
currentTimestamp: U256,
feeReceiver: Address,
uints: Uints
feeReceiver: Address
) -> () {
let caller = callerAddress!()
checkCaller!((caller == invariantId || caller == positionsId || caller == swapUtilsId) && areAdminsSet, PoolsError.NotAdmin)
Expand All @@ -56,8 +55,7 @@ Contract Pools(
lastTimestamp: currentTimestamp,
feeReceiver: feeReceiver
},
clamm,
uints
clamm
)
let _ = copyCreateSubContract!{originalCaller -> ALPH: 1 alph}(
poolKey,
Expand Down
4 changes: 1 addition & 3 deletions contracts/collections/positions.ral
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ Contract Positions(
feeGrowthInsideY: U256,
lastBlockNumber: U256,
tokensOwedX: U256,
tokensOwedY: U256,
uints: Uints
tokensOwedY: U256
) -> () {
checkCaller!(callerAddress!() == invariantId && areAdminsSet, PositionsError.NotAdmin)

Expand All @@ -59,7 +58,6 @@ Contract Positions(
owner: originalCaller
},
true,
uints,
clammContract
)
let _ = copyCreateSubContract!{originalCaller -> ALPH: 1 alph}(
Expand Down
3 changes: 1 addition & 2 deletions contracts/collections/tickmap.ral
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
Contract Tickmap(
chunkTemplateContractId: ByteVec,
uints: Uints,
mut invariantId: Address,
mut swapUtilsId: Address,
mut areAdminsSet: Bool
) extends Decimal(uints) {
) extends Decimal() {
const ChunkSize = 64
const SearchRange = 256i

Expand Down
6 changes: 2 additions & 4 deletions contracts/collections/ticks.ral
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ Contract Ticks(
sqrtPrice: U256,
feeGrowthOutsideX: U256,
feeGrowthOutsideY: U256,
secondsOutside: U256,
uints: Uints
secondsOutside: U256
) -> () {
let caller = callerAddress!()
checkCaller!((caller == invariantId || caller == swapUtilsId || caller == positionsId) && areAdminsSet, TicksError.NotAdmin)
Expand All @@ -50,8 +49,7 @@ Contract Ticks(
feeGrowthOutsideX: feeGrowthOutsideX,
feeGrowthOutsideY: feeGrowthOutsideY,
secondsOutside: secondsOutside
},
uints
}
)
let _ = copyCreateSubContract!{originalCaller -> ALPH: 1 alph}(
path,
Expand Down
12 changes: 5 additions & 7 deletions contracts/invariant.ral
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ Contract Invariant(
positions: Positions,
tickmap: Tickmap,
swap: SwapUtils,
clamm: CLAMM,
uints: Uints
) extends PoolKeyHelper(), Decimal(uints) {
clamm: CLAMM
) extends PoolKeyHelper(), Decimal() {
enum InvariantError {
NotAdmin = 0
AlreadyInitialized = 1
Expand Down Expand Up @@ -106,7 +105,7 @@ Contract Invariant(
let caller = callerAddress!()
let timestamp = blockTimeStamp!()
poolKeys.add{caller -> ALPH: 1 alph}(caller, tokenX, tokenY, fee, tickSpacing)
pools.add{caller -> ALPH: 1 alph}(caller, poolKey, tokenX, tokenY, tickSpacing, initSqrtPrice, initTick, timestamp, config.admin, uints)
pools.add{caller -> ALPH: 1 alph}(caller, poolKey, tokenX, tokenY, tickSpacing, initSqrtPrice, initTick, timestamp, config.admin)
}

@using(preapprovedAssets = true)
Expand Down Expand Up @@ -191,8 +190,7 @@ Contract Invariant(
clamm.calculateSqrtPrice(index),
feeGrowthOutsideX,
feeGrowthOutsideY,
0,
uints
0
)
}

Expand Down Expand Up @@ -230,7 +228,7 @@ Contract Invariant(
createTick{caller -> ALPH: 2 alph}(caller, poolKey, tickSpacing, upperTick, currentTickindex, feeGrowthGlobalX, feeGrowthGlobalY, startTimestamp)
}

positions.add{caller -> ALPH: 2 alph}(caller, poolKey, 0, lowerTick, upperTick, 0, 0, blockTimeStamp!(), 0, 0, uints)
positions.add{caller -> ALPH: 2 alph}(caller, poolKey, 0, lowerTick, upperTick, 0, 0, blockTimeStamp!(), 0, 0)
}

@using(preapprovedAssets = true, assetsInContract = true, checkExternalCaller = false)
Expand Down
2 changes: 1 addition & 1 deletion contracts/math/decimal.ral
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Abstract Contract Decimal(uints: Uints) {
Abstract Contract Decimal() {
const SqrtPriceScale = 24
const LiquidityScale = 5
const FeeGrowthScale = 28
Expand Down
2 changes: 1 addition & 1 deletion contracts/math/log.ral
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Abstract Contract Log(uints: Uints) extends Decimal(uints) {
Abstract Contract Log(uints: Uints) extends Decimal() {
const Log2Scale = 32
const Log2DoubleScale = 64
const Log2Sqrt10001 = 309801
Expand Down
5 changes: 2 additions & 3 deletions contracts/storage/pool.ral
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ struct PoolState {
Contract Pool(
admin: Address,
mut pool: PoolState,
clamm: CLAMM,
uints: Uints
) extends Decimal(uints) {
clamm: CLAMM
) extends Decimal() {
enum PoolError {
NotAdmin = 1200
}
Expand Down
3 changes: 1 addition & 2 deletions contracts/storage/position.ral
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ Contract Position(
admin: Address,
mut position: PositionState,
mut isActive: Bool,
uints: Uints,
clammContractInstance: CLAMM
) extends Decimal(uints) {
) extends Decimal() {
enum PositionError {
NotAdmin = 900
InsufficientLiquidity = 901
Expand Down
5 changes: 2 additions & 3 deletions contracts/storage/tick.ral
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ struct TickState {

Contract Tick(
admin: Address,
mut tick: TickState,
uints: Uints
) extends Decimal(uints) {
mut tick: TickState
) extends Decimal() {
enum TickError {
NotAdmin = 1000
InvalidTickLiquidity = 1001
Expand Down
5 changes: 2 additions & 3 deletions contracts/swap.ral
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ Contract SwapUtils(
pools: Pools,
ticks: Ticks,
tickmap: Tickmap,
clamm: CLAMM,
uints: Uints
) extends Decimal(uints), PoolKeyHelper() {
clamm: CLAMM
) extends Decimal(), PoolKeyHelper() {
enum SwapError {
ZeroAmount = 10001
WrongLimit = 10002
Expand Down
34 changes: 12 additions & 22 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ export async function deployInvariant(signer: SignerProvider, protocolFee: bigin
const feeTiers = await deployFeeTiers(signer, feeTier.contractInstance.contractId)
const poolKey = await deployPoolKey(signer)
const poolKeys = await deployPoolKeys(signer, poolKey.contractInstance.contractId)
const pool = await deployPool(signer, clamm.contractInstance.contractId, uints.contractInstance.contractId)
const pool = await deployPool(signer, clamm.contractInstance.contractId)
const pools = await deployPools(signer, pool.contractInstance.contractId, clamm.contractInstance.contractId)
const tick = await deployTick(signer)
const ticks = await deployTicks(signer, tick.contractInstance.contractId)
const position = await deployPosition(signer, uints.contractInstance.contractId, clamm.contractInstance.contractId)
const position = await deployPosition(signer, uints.contractInstance.contractId)
const positionsCounter = await deployPositionsCounter(signer)
const positions = await deployPositions(
signer,
Expand All @@ -66,16 +66,15 @@ export async function deployInvariant(signer: SignerProvider, protocolFee: bigin
clamm.contractInstance.contractId
)
const chunk = await deployChunk(signer)
const tickmap = await deployTickmap(signer, chunk.contractInstance.contractId, uints.contractInstance.contractId)
const tickmap = await deployTickmap(signer, chunk.contractInstance.contractId)

const swap = await deploySwap(
signer,
clamm.contractInstance.contractId,
pools.contractInstance.contractId,
ticks.contractInstance.contractId,
tickmap.contractInstance.contractId,
protocolFee,
uints.contractInstance.contractId
protocolFee
)

const deployResult = await waitTxConfirmed(
Expand All @@ -90,8 +89,7 @@ export async function deployInvariant(signer: SignerProvider, protocolFee: bigin
positions: positions.contractInstance.contractId,
tickmap: tickmap.contractInstance.contractId,
clamm: clamm.contractInstance.contractId,
swap: swap.contractInstance.contractId,
uints: uints.contractInstance.contractId
swap: swap.contractInstance.contractId
}
})
)
Expand All @@ -113,8 +111,7 @@ export async function deploySwap(
pools: string,
ticks: string,
tickmap: string,
protocolFee: bigint,
uintsId: string
protocolFee: bigint
) {
return await waitTxConfirmed(
SwapUtils.deploy(signer, {
Expand All @@ -123,8 +120,7 @@ export async function deploySwap(
pools,
ticks,
tickmap,
protocolFee,
uints: uintsId
protocolFee
}
})
)
Expand Down Expand Up @@ -174,7 +170,7 @@ export async function deployPositions(
)
}

export async function deployPosition(signer: SignerProvider, uintsId: string, clammId: string) {
export async function deployPosition(signer: SignerProvider, clammId: string) {
return await waitTxConfirmed(
Position.deploy(signer, {
initialFields: {
Expand All @@ -192,7 +188,6 @@ export async function deployPosition(signer: SignerProvider, uintsId: string, cl
owner: ZERO_ADDRESS
},
isActive: false,
uints: uintsId,
clammContractInstance: clammId
}
})
Expand Down Expand Up @@ -236,7 +231,7 @@ export async function deployPoolKeys(signer: SignerProvider, poolKeyId: string)
)
}

export async function deployPool(signer: SignerProvider, clammId: string, uintsId: string) {
export async function deployPool(signer: SignerProvider, clammId: string) {
return await waitTxConfirmed(
Pool.deploy(signer, {
initialFields: {
Expand All @@ -256,8 +251,7 @@ export async function deployPool(signer: SignerProvider, clammId: string, uintsI
lastTimestamp: 0n,
feeReceiver: ZERO_ADDRESS
},
clamm: clammId,
uints: uintsId
clamm: clammId
}
})
)
Expand All @@ -279,8 +273,6 @@ export async function deployPools(signer: SignerProvider, poolId: string, clammI
}

export async function deployTick(signer: SignerProvider) {
const uints = await deployUints(signer)

return await waitTxConfirmed(
Tick.deploy(signer, {
initialFields: {
Expand All @@ -293,8 +285,7 @@ export async function deployTick(signer: SignerProvider) {
feeGrowthOutsideX: 0n,
feeGrowthOutsideY: 0n,
secondsOutside: 0n
},
uints: uints.contractInstance.contractId
}
}
})
)
Expand All @@ -311,12 +302,11 @@ export async function deployChunk(signer: SignerProvider) {
)
}

export async function deployTickmap(signer: SignerProvider, chunkTemplateContractId: string, uintsId: string) {
export async function deployTickmap(signer: SignerProvider, chunkTemplateContractId: string) {
return await waitTxConfirmed(
Tickmap.deploy(signer, {
initialFields: {
chunkTemplateContractId: chunkTemplateContractId,
uints: uintsId,
invariantId: ZERO_ADDRESS,
swapUtilsId: ZERO_ADDRESS,
areAdminsSet: false
Expand Down

0 comments on commit 15224ad

Please sign in to comment.