Skip to content
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion migrations/deprecated/__tests__/00001_accounts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import { PostgresDatabaseMigrator } from '@/datasources/db/v1/postgres-database.
import { faker } from '@faker-js/faker';
import type { Sql } from 'postgres';
import type postgres from 'postgres';
import type { Address } from 'viem';

interface AccountRow {
id: number;
group_id: number;
created_at: Date;
updated_at: Date;
address: `0x${string}`;
address: Address;
}

describe('Migration 00001_accounts', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import { waitMilliseconds } from '@/__tests__/util/retry';
import { PostgresDatabaseMigrator } from '@/datasources/db/v1/postgres-database.migrator';
import { faker } from '@faker-js/faker';
import type postgres from 'postgres';
import type { Address } from 'viem';
import { getAddress } from 'viem';

interface AccountRow {
id: number;
group_id: number;
created_at: Date;
updated_at: Date;
address: `0x${string}`;
address: Address;
}

interface AccountDataTypeRow {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,28 @@ import { waitMilliseconds } from '@/__tests__/util/retry';
import { PostgresDatabaseMigrator } from '@/datasources/db/v1/postgres-database.migrator';
import { faker } from '@faker-js/faker';
import type postgres from 'postgres';
import type { Address } from 'viem';
import { getAddress } from 'viem';

interface AccountRow {
id: number;
group_id: number;
created_at: Date;
updated_at: Date;
address: `0x${string}`;
address: Address;
}

interface CounterfactualSafesRow {
created_at: Date;
updated_at: Date;
id: number;
chain_id: string;
creator: `0x${string}`;
fallback_handler: `0x${string}`;
owners: Array<`0x${string}`>;
predicted_address: `0x${string}`;
creator: Address;
fallback_handler: Address;
owners: Array<Address>;
predicted_address: Address;
salt_nonce: string;
singleton_address: `0x${string}`;
singleton_address: Address;
threshold: number;
account_id: number;
}
Expand Down
5 changes: 3 additions & 2 deletions migrations/deprecated/__tests__/00005_notifications.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DeviceType } from '@/domain/notifications/v2/entities/device-type.entit
import type { UUID } from 'crypto';
import { faker } from '@faker-js/faker';
import type postgres from 'postgres';
import type { Address } from 'viem';
import { getAddress } from 'viem';

type PushNotificationDevicesRow = {
Expand All @@ -29,10 +30,10 @@ type NotificationTypesRow = {

type NotificationSubscriptionsRow = {
id: number;
signer_address: `0x${string}` | null;
signer_address: Address | null;
push_notification_device_id: PushNotificationDevicesRow['id'];
chain_id: string;
safe_address: `0x${string}`;
safe_address: Address;
created_at: Date;
updated_at: Date;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { waitMilliseconds } from '@/__tests__/util/retry';
import { PostgresDatabaseMigrator } from '@/datasources/db/v1/postgres-database.migrator';
import { faker } from '@faker-js/faker';
import type postgres from 'postgres';
import type { Address } from 'viem';
import { getAddress } from 'viem';

interface AccountDataTypeRow {
Expand All @@ -19,7 +20,7 @@ interface AccountRow {
group_id: number;
created_at: Date;
updated_at: Date;
address: `0x${string}`;
address: Address;
}

interface AddressBooksRow {
Expand Down
3 changes: 2 additions & 1 deletion src/config/entities/blocklist.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Address } from 'viem';
import { getAddress } from 'viem';

export function getBlocklist(): Array<`0x${string}`> {
export function getBlocklist(): Array<Address> {
// Addresses not allowed to interact with the service
// List taken from https://www.ic3.gov/PSA/2025/PSA250226
return [
Expand Down
11 changes: 6 additions & 5 deletions src/datasources/accounts/accounts.datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
import crypto from 'crypto';
import omit from 'lodash/omit';
import postgres from 'postgres';
import type { Address } from 'viem';

@Injectable()
export class AccountsDatasource implements IAccountsDatasource, OnModuleInit {
Expand Down Expand Up @@ -112,7 +113,7 @@ export class AccountsDatasource implements IAccountsDatasource, OnModuleInit {
return omit(await this.decryptAccountData(account), 'name_hash');
}

async getAccount(address: `0x${string}`): Promise<Account> {
async getAccount(address: Address): Promise<Account> {
const cacheDir = CacheRouter.getAccountCacheDir(address);
const [account] = await this.cachedQueryResolver.get<Array<Account>>({
cacheDir,
Expand All @@ -127,7 +128,7 @@ export class AccountsDatasource implements IAccountsDatasource, OnModuleInit {
return this.decryptAccountData(account);
}

async deleteAccount(address: `0x${string}`): Promise<void> {
async deleteAccount(address: Address): Promise<void> {
try {
const { count } = await this
.sql`DELETE FROM accounts WHERE address = ${address}`;
Expand Down Expand Up @@ -156,7 +157,7 @@ export class AccountsDatasource implements IAccountsDatasource, OnModuleInit {
}

async getAccountDataSettings(
address: `0x${string}`,
address: Address,
): Promise<Array<AccountDataSetting>> {
const account = await this.getAccount(address);
const cacheDir = CacheRouter.getAccountDataSettingsCacheDir(address);
Expand All @@ -182,7 +183,7 @@ export class AccountsDatasource implements IAccountsDatasource, OnModuleInit {
* @returns {Array<AccountDataSetting>} inserted account data settings.
*/
async upsertAccountDataSettings(args: {
address: `0x${string}`;
address: Address;
upsertAccountDataSettingsDto: UpsertAccountDataSettingsDto;
}): Promise<Array<AccountDataSetting>> {
const { accountDataSettings } = args.upsertAccountDataSettingsDto;
Expand Down Expand Up @@ -270,7 +271,7 @@ export class AccountsDatasource implements IAccountsDatasource, OnModuleInit {

async encryptAccountData(
createAccountDto: CreateAccountDto,
): Promise<{ address: `0x${string}`; name: string; nameHash: string }> {
): Promise<{ address: Address; name: string; nameHash: string }> {
const hash = crypto.createHash('sha256');
hash.update(createAccountDto.name);
const nameHash = hash.digest('hex');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ICounterfactualSafesDatasource } from '@/domain/interfaces/counterfactu
import { ILoggingService, LoggingService } from '@/logging/logging.interface';
import { Inject, Injectable, NotFoundException } from '@nestjs/common';
import postgres from 'postgres';
import type { Address } from 'viem';

@Injectable()
export class CounterfactualSafesDatasource
Expand Down Expand Up @@ -67,9 +68,9 @@ export class CounterfactualSafesDatasource
}

async getCounterfactualSafe(args: {
address: `0x${string}`;
address: Address;
chainId: string;
predictedAddress: `0x${string}`;
predictedAddress: Address;
}): Promise<CounterfactualSafe> {
const cacheDir = CacheRouter.getCounterfactualSafeCacheDir(
args.chainId,
Expand All @@ -95,7 +96,7 @@ export class CounterfactualSafesDatasource
}

getCounterfactualSafesForAddress(
address: `0x${string}`,
address: Address,
): Promise<Array<CounterfactualSafe>> {
const cacheDir = CacheRouter.getCounterfactualSafesCacheDir(address);
return this.cachedQueryResolver.get<Array<CounterfactualSafe>>({
Expand All @@ -110,7 +111,7 @@ export class CounterfactualSafesDatasource
async deleteCounterfactualSafe(args: {
account: Account;
chainId: string;
predictedAddress: `0x${string}`;
predictedAddress: Address;
}): Promise<void> {
try {
const { count } = await this
Expand Down
6 changes: 2 additions & 4 deletions src/datasources/balances-api/balances-api.manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { ITransactionApiManager } from '@/domain/interfaces/transaction-api.mana
import { ChainSchema } from '@/domain/chains/entities/schemas/chain.schema';
import { z } from 'zod';
import { type Raw, rawify } from '@/validation/entities/raw.entity';
import type { Address } from 'viem';

@Injectable()
export class BalancesApiManager implements IBalancesApiManager {
Expand Down Expand Up @@ -51,10 +52,7 @@ export class BalancesApiManager implements IBalancesApiManager {
this.zerionBalancesApi = zerionBalancesApi;
}

async getApi(
chainId: string,
safeAddress: `0x${string}`,
): Promise<IBalancesApi> {
async getApi(chainId: string, safeAddress: Address): Promise<IBalancesApi> {
if (this.zerionChainIds.includes(chainId)) {
return this.zerionBalancesApi;
}
Expand Down
11 changes: 6 additions & 5 deletions src/datasources/balances-api/safe-balances-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
getAssetPricesSchema,
} from '@/datasources/balances-api/entities/asset-price.entity';
import { ZodError } from 'zod';
import type { Address } from 'viem';

@Injectable()
export class SafeBalancesApi implements IBalancesApi {
Expand Down Expand Up @@ -65,7 +66,7 @@ export class SafeBalancesApi implements IBalancesApi {
}

async getBalances(args: {
safeAddress: `0x${string}`;
safeAddress: Address;
fiatCode: string;
chain: Chain;
trusted?: boolean;
Expand Down Expand Up @@ -105,7 +106,7 @@ export class SafeBalancesApi implements IBalancesApi {
}
}

async clearBalances(args: { safeAddress: `0x${string}` }): Promise<void> {
async clearBalances(args: { safeAddress: Address }): Promise<void> {
const key = CacheRouter.getBalancesCacheKey({
chainId: this.chainId,
safeAddress: args.safeAddress,
Expand All @@ -114,7 +115,7 @@ export class SafeBalancesApi implements IBalancesApi {
}

async getCollectibles(args: {
safeAddress: `0x${string}`;
safeAddress: Address;
limit?: number;
offset?: number;
trusted?: boolean;
Expand Down Expand Up @@ -145,7 +146,7 @@ export class SafeBalancesApi implements IBalancesApi {
}
}

async clearCollectibles(args: { safeAddress: `0x${string}` }): Promise<void> {
async clearCollectibles(args: { safeAddress: Address }): Promise<void> {
const key = CacheRouter.getCollectiblesKey({
chainId: this.chainId,
safeAddress: args.safeAddress,
Expand Down Expand Up @@ -176,7 +177,7 @@ export class SafeBalancesApi implements IBalancesApi {
}): Promise<Raw<Array<Balance>>> {
const tokenAddresses = args.balances
.map((balance) => balance.tokenAddress)
.filter((address): address is `0x${string}` => address !== null);
.filter((address): address is Address => address !== null);

const lowerCaseFiatCode = args.fiatCode.toLowerCase();
const assetPrices = await this.coingeckoApi
Expand Down
10 changes: 5 additions & 5 deletions src/datasources/balances-api/zerion-balances-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { IBalancesApi } from '@/domain/interfaces/balances-api.interface';
import { ILoggingService, LoggingService } from '@/logging/logging.interface';
import { rawify, type Raw } from '@/validation/entities/raw.entity';
import { Inject, Injectable } from '@nestjs/common';
import { getAddress } from 'viem';
import { Address, getAddress } from 'viem';
import { z, ZodError } from 'zod';

export const IZerionBalancesApi = Symbol('IZerionBalancesApi');
Expand Down Expand Up @@ -96,7 +96,7 @@ export class ZerionBalancesApi implements IBalancesApi {

async getBalances(args: {
chain: Chain;
safeAddress: `0x${string}`;
safeAddress: Address;
fiatCode: string;
}): Promise<Raw<Array<Balance>>> {
if (!this.fiatCodes.includes(args.fiatCode.toUpperCase())) {
Expand Down Expand Up @@ -166,7 +166,7 @@ export class ZerionBalancesApi implements IBalancesApi {
*/
async getCollectibles(args: {
chain: Chain;
safeAddress: `0x${string}`;
safeAddress: Address;
limit?: number;
offset?: number;
}): Promise<Raw<Page<Collectible>>> {
Expand Down Expand Up @@ -221,7 +221,7 @@ export class ZerionBalancesApi implements IBalancesApi {

async clearCollectibles(args: {
chainId: string;
safeAddress: `0x${string}`;
safeAddress: Address;
}): Promise<void> {
const key = CacheRouter.getZerionCollectiblesCacheKey(args);
await this.cacheService.deleteByKey(key);
Expand Down Expand Up @@ -291,7 +291,7 @@ export class ZerionBalancesApi implements IBalancesApi {

async clearBalances(args: {
chainId: string;
safeAddress: `0x${string}`;
safeAddress: Address;
}): Promise<void> {
const key = CacheRouter.getZerionBalancesCacheKey(args);
await this.cacheService.deleteByKey(key);
Expand Down
5 changes: 3 additions & 2 deletions src/datasources/bridge-api/lifi-api.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { TestLoggingModule } from '@/logging/__tests__/test.logging.module';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { Test } from '@nestjs/testing';
import configuration from '@/config/entities/__tests__/configuration';
import type { Hash } from 'viem';

const mockNetworkService = jest.mocked({
get: jest.fn(),
Expand Down Expand Up @@ -99,7 +100,7 @@ describe('LifiBridgeApi', () => {
describe('getStatus', () => {
it('should return the status', async () => {
const bridgeStatus = bridgeStatusBuilder().build();
const txHash = faker.string.hexadecimal({ length: 64 }) as `0x${string}`;
const txHash = faker.string.hexadecimal({ length: 64 }) as Hash;
const bridge = faker.helpers.arrayElement(BridgeNames);
const toChain = faker.string.numeric();
mockNetworkService.get.mockResolvedValueOnce({
Expand Down Expand Up @@ -131,7 +132,7 @@ describe('LifiBridgeApi', () => {
});

it('should forward errors', async () => {
const txHash = faker.string.hexadecimal({ length: 64 }) as `0x${string}`;
const txHash = faker.string.hexadecimal({ length: 64 }) as Hash;
const bridge = faker.helpers.arrayElement(BridgeNames);
const toChain = faker.string.numeric();
const status = faker.internet.httpStatusCode({ types: ['serverError'] });
Expand Down
3 changes: 2 additions & 1 deletion src/datasources/bridge-api/lifi-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { CacheFirstDataSource } from '@/datasources/cache/cache.first.data.
import type { IConfigurationService } from '@/config/configuration.service.interface';
import { CacheRouter } from '@/datasources/cache/cache.router';
import { type BridgeChainPage } from '@/domain/bridge/entities/bridge-chain.entity';
import type { Hash } from 'viem';

export class LifiBridgeApi implements IBridgeApi {
public static readonly LIFI_API_HEADER = 'x-lifi-api-key';
Expand Down Expand Up @@ -59,7 +60,7 @@ export class LifiBridgeApi implements IBridgeApi {
}

public async getStatus(args: {
txHash: `0x${string}`;
txHash: Hash;
bridge?: BridgeName;
toChain?: string;
}): Promise<Raw<BridgeStatus>> {
Expand Down
Loading
Loading