Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Sniezka1927 committed Jul 16, 2024
1 parent 55eeaa8 commit ffd1d99
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 17 deletions.
16 changes: 8 additions & 8 deletions contracts/collections/pool_keys.ral
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ Abstract Contract PoolKeys() {
return false
}

// fn getAllPoolKeys() -> ByteVec {
// let mut poolKeysBytes = b``
fn wrappedGetAllPoolKeys() -> ByteVec {
let mut poolKeysBytes = b``

// for (let mut i = 1; i <= poolKeyCount; i = i + 1) {
// let state = poolKeys[i]
// poolKeysBytes = poolKeysBytes ++ state.tokenX ++ b`break` ++ state.tokenY ++ b`break` ++ toByteVec!(state.feeTier.fee) ++ b`break` ++ toByteVec!(state.feeTier.tickSpacing) ++ b`break`
// }
for (let mut i = 1; i <= poolKeyCount; i = i + 1) {
let state = poolKeys[i]
poolKeysBytes = poolKeysBytes ++ state.tokenX ++ b`break` ++ state.tokenY ++ b`break` ++ toByteVec!(state.feeTier.fee) ++ b`break` ++ toByteVec!(state.feeTier.tickSpacing) ++ b`break`
}

// return poolKeysBytes
// }
return poolKeysBytes
}
}
4 changes: 3 additions & 1 deletion contracts/invariant.ral
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ Contract Invariant(
checkCaller!(caller == config.admin, InvariantError.NotAdmin)

for(let mut i = 0; i < feeTierCount; i = i + 1) {
assert!( 1 != 0, 210)
if(feeTiers.feeTiers[i].fee == feeTier.fee && feeTiers.feeTiers[i].tickSpacing == feeTier.tickSpacing) {
feeTiers.feeTiers[i] = feeTiers.feeTiers[feeTierCount - 1]
feeTiers.feeTiers[feeTierCount - 1] = FeeTier{fee: 0, tickSpacing: 0}
Expand Down Expand Up @@ -552,4 +551,7 @@ Contract Invariant(

return matchingPools
}
pub fn getAllPoolKeys() -> ByteVec {
return wrappedGetAllPoolKeys()
}
}
7 changes: 5 additions & 2 deletions src/invariant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import {
deployReserve,
MAP_ENTRY_DEPOSIT,
waitTxConfirmed,
decodePools
decodePools,
decodePoolKeys
} from './utils'
import { Address, DUST_AMOUNT, SignerProvider } from '@alephium/web3'

Expand Down Expand Up @@ -315,7 +316,9 @@ export class Invariant {
// async getPositions() {}
// async getAllPositions() {}
// async getPoolKeys() {}
// async getAllPoolKeys() {}
async getAllPoolKeys() {
return decodePoolKeys((await this.instance.view.getAllPoolKeys()).returns)
}
// async swapWithSlippage() {}
// async getPositionTicks() {}
// async getRawTickmap() {}
Expand Down
19 changes: 13 additions & 6 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export async function balanceOf(tokenId: string, address: string): Promise<bigin
}

export function decodeFeeTiers(string: string) {
const parts = string.split('627265616b')
const parts = string.split(BREAK_BYTES)
const feeTiers: any[] = []

for (let i = 0; i < parts.length - 1; i += 2) {
Expand Down Expand Up @@ -170,13 +170,20 @@ export function decodePools(string: string) {
return pools
}

export const decodePoolKey = (string: string) => {
export const decodePoolKeys = (string: string) => {
const parts = string.split(BREAK_BYTES)
return {
token0: addressFromContractId(parts[0]),
token1: addressFromContractId(parts[1]),
feeTier: decodeU256(parts[2])
const poolKeys: any[] = []

for (let i = 0; i < parts.length - 1; i += 4) {
const poolKey = {
tokenX: parts[i],
tokenY: parts[i + 1],
feeTier: { fee: decodeU256(parts[i + 2]), tickSpacing: decodeU256(parts[i + 3]) }
}
poolKeys.push(poolKey)
}

return poolKeys
}

function createEntityProxy<T>(entity: T, exists: boolean) {
Expand Down
2 changes: 2 additions & 0 deletions test/query-on-pair.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,7 @@ describe('query on pair', () => {
console.log('expectedPool1', expectedPool1)
const query = await invariant.getAllPoolsForPair(tokenX.contractId, tokenY.contractId)
console.log(query)
const allPoolKeys = await invariant.getAllPoolKeys()
console.log(allPoolKeys)
})
})

0 comments on commit ffd1d99

Please sign in to comment.