Skip to content

Commit

Permalink
Fix basic dd logic (#219)
Browse files Browse the repository at this point in the history
* Add COMMITMENT_WATCHER_DIRECT_DEPOSIT_PARAMS_PATH

* Fix dd indexing logic

* Support both formats
  • Loading branch information
AllFi authored Jun 27, 2024
1 parent b52416b commit b29ef3c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions zp-relayer/configs/commitmentWatcherConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const zSchema = z.object({
COMMITMENT_WATCHER_TOKEN_ADDRESS: z.string(),
COMMITMENT_WATCHER_PRECOMPUTE_PARAMS: zBooleanString().default('false'),
COMMITMENT_WATCHER_TREE_UPDATE_PARAMS_PATH: z.string().default('../params/tree_params.bin'),
COMMITMENT_WATCHER_DIRECT_DEPOSIT_PARAMS_PATH: z.string().default('../params/delegated_deposit_params.bin'),
COMMITMENT_WATCHER_STATE_DIR_PATH: z.string().default('./POOL_STATE'),
COMMITMENT_WATCHER_TX_VK_PATH: z.string().default('../params/transfer_verification_key.json'),
COMMITMENT_WATCHER_FETCH_INTERVAL: z.coerce.number().default(10000),
Expand Down
17 changes: 16 additions & 1 deletion zp-relayer/pool/BasePool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,11 @@ export abstract class BasePool<N extends Network = Network> {

async addTxToState(txHash: string, newPoolIndex: number, message: string, state: 'optimistic' | 'confirmed' | 'all') {
const transactSelector = '0xaf989083'
const directDepositSelector = '0x1dc4cb33'
const transactV2Selector = '0x5fd28f8c'

const directDepositOldSelector = '0x1dc4cb33'
const directDepositSelector = '0xe6b14272'

const input = await this.network.getTxCalldata(txHash)

const prevPoolIndex = newPoolIndex - OUTPLUSONE
Expand All @@ -254,6 +256,19 @@ export abstract class BasePool<N extends Network = Network> {

if (input.startsWith(directDepositSelector)) {
// Direct deposit case
const res = AbiCoder.decodeParameters(
[
'uint256[]', // Indices
'uint256', // Out commit
'uint256[8]', // Deposit proof
'address', // Prover
],
input.slice(10) // Cut off selector
)
outCommit = res[1]
memo = truncateHexPrefix(message || '')
} else if (input.startsWith(directDepositOldSelector)) {
// Old direct deposit case
const res = AbiCoder.decodeParameters(
[
'uint256', // Root after
Expand Down
2 changes: 1 addition & 1 deletion zp-relayer/services/commitment-watcher/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export async function init() {
const directDepositProver = buildProver(
Circuit.DirectDeposit,
ProverType.Local,
config.COMMITMENT_WATCHER_TREE_UPDATE_PARAMS_PATH as string
config.COMMITMENT_WATCHER_DIRECT_DEPOSIT_PARAMS_PATH as string
)

if (!config.base.COMMON_INDEXER_URL) {
Expand Down

0 comments on commit b29ef3c

Please sign in to comment.