Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support relaying of recovery proposals/executions #2078

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/domain/alerts/alerts.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export class AlertsRepository implements IAlertsRepository {
}
}

// TODO: Refactor to use getSafeBeingRecovered from relay address limiter
private _decodeTransactionAdded(
data: Hex,
): Array<ReturnType<typeof this._decodeRecoveryTransaction>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import type { Hex } from 'viem';
import {
encodeAbiParameters,
encodeEventTopics,
encodeFunctionData,
getAbiItem,
getAddress,
keccak256,
toBytes,
} from 'viem';
import { Builder } from '@/__tests__/builder';
import { TRANSACTION_ADDED_ABI } from '@/domain/alerts/contracts/decoders/delay-modifier-decoder.helper';
import { DelayModifierAbi } from '@/domain/alerts/contracts/decoders/delay-modifier-decoder.helper';

// TransactionAdded

Expand All @@ -33,7 +34,7 @@ class TransactionAddedEventBuilder<T extends TransactionAddedEventArgs>
implements IEncoder<TransactionAddedEvent>
{
private readonly item = getAbiItem({
abi: TRANSACTION_ADDED_ABI,
abi: DelayModifierAbi,
name: 'TransactionAdded',
});

Expand All @@ -49,7 +50,7 @@ class TransactionAddedEventBuilder<T extends TransactionAddedEventArgs>
);

const topics = encodeEventTopics({
abi: TRANSACTION_ADDED_ABI,
abi: DelayModifierAbi,
eventName: 'TransactionAdded',
args: {
// Only indexed params
Expand Down Expand Up @@ -77,3 +78,67 @@ export function transactionAddedEventBuilder(): TransactionAddedEventBuilder<Tra
.with('data', '0x')
.with('operation', 0);
}

// execTransactionFromModule

type ExecTransactionFromModuleArgs = {
to: `0x${string}`;
value: bigint;
data: `0x${string}`;
operation: 0 | 1;
};

class ExecTransactionFromModuleEncoder<T extends ExecTransactionFromModuleArgs>
extends Builder<T>
implements IEncoder
{
encode(): `0x${string}` {
const args = this.build();

return encodeFunctionData({
abi: DelayModifierAbi,
functionName: 'execTransactionFromModule',
args: [args.to, args.value, args.data, args.operation],
});
}
}

export function execTransactionFromModuleEncoder(): ExecTransactionFromModuleEncoder<ExecTransactionFromModuleArgs> {
return new ExecTransactionFromModuleEncoder()
.with('to', getAddress(faker.finance.ethereumAddress()))
.with('value', faker.number.bigInt())
.with('data', faker.string.hexadecimal() as `0x${string}`)
.with('operation', faker.helpers.arrayElement([0, 1]));
}

// executeNextTx

type ExecNextTxArgs = {
to: `0x${string}`;
value: bigint;
data: `0x${string}`;
operation: 0 | 1;
};

class ExecNextTxEncoder<T extends ExecNextTxArgs>
extends Builder<T>
implements IEncoder
{
encode(): `0x${string}` {
const args = this.build();

return encodeFunctionData({
abi: DelayModifierAbi,
functionName: 'executeNextTx',
args: [args.to, args.value, args.data, args.operation],
});
}
}

export function executeNextTxEncoder(): ExecNextTxEncoder<ExecNextTxArgs> {
return new ExecNextTxEncoder()
.with('to', getAddress(faker.finance.ethereumAddress()))
.with('value', faker.number.bigInt())
.with('data', faker.string.hexadecimal() as `0x${string}`)
.with('operation', faker.helpers.arrayElement([0, 1]));
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { Injectable } from '@nestjs/common';
import { parseAbi } from 'viem';
import { AbiDecoder } from '@/domain/contracts/decoders/abi-decoder.helper';

export const TRANSACTION_ADDED_ABI = parseAbi([
export const DelayModifierAbi = parseAbi([
'event TransactionAdded(uint256 indexed queueNonce, bytes32 indexed txHash, address to, uint256 value, bytes data, uint8 operation)',
'function execTransactionFromModule(address to, uint256 value, bytes calldata data, uint8 operation)',
'function executeNextTx(address to, uint256 value, bytes calldata data, uint8 operation)',
]);

@Injectable()
export class DelayModifierDecoder extends AbiDecoder<
typeof TRANSACTION_ADDED_ABI
> {
export class DelayModifierDecoder extends AbiDecoder<typeof DelayModifierAbi> {
constructor() {
super(TRANSACTION_ADDED_ABI);
super(DelayModifierAbi);
}
}
Loading