-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathconfiguration.ts
More file actions
972 lines (968 loc) · 33.6 KB
/
configuration.ts
File metadata and controls
972 lines (968 loc) · 33.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
// SPDX-License-Identifier: FSL-1.1-MIT
import type { RelayRules } from '@/modules/relay/domain/entities/relay.configuration';
// Custom configuration for the application
export default () => ({
about: {
name: 'safe-client-gateway',
version: process.env.APPLICATION_VERSION,
buildNumber: process.env.APPLICATION_BUILD_NUMBER,
},
amqp: {
url: process.env.AMQP_URL || 'amqp://localhost:5672',
exchange: {
name: process.env.AMQP_EXCHANGE_NAME || 'safe-transaction-service-events',
// The Safe Transaction Service AMQP Exchange mode defaults to 'fanout'.
// https://www.rabbitmq.com/tutorials/amqp-concepts#exchange-fanout
// A fanout exchange routes messages to all of the queues that are bound to it and the routing key is ignored.
mode: process.env.AMQP_EXCHANGE_MODE || 'fanout',
},
queue: process.env.AMQP_QUEUE || 'safe-client-gateway',
// The AMQP Prefetch value defaults to 0.
// Limits the number of unacknowledged messages delivered to a given channel/consumer.
prefetch:
process.env.AMQP_PREFETCH != null
? Number.parseInt(process.env.AMQP_PREFETCH, 10)
: 100,
heartbeatIntervalInSeconds: +(
process.env.AMQP_HEARBEAT_INTERVAL_SECONDS || 60
),
reconnectTimeInSeconds: +(process.env.AMQP_RECONNECT_TIME_SECONDS || 5),
},
application: {
isProduction: process.env.CGW_ENV === 'production',
isDevelopment: process.env.CGW_ENV === 'development',
// Enables/disables the execution of migrations on startup.
// Defaults to true.
runMigrations: process.env.RUN_MIGRATIONS?.toLowerCase() !== 'false',
port: process.env.APPLICATION_PORT || '3000',
allowCors: process.env.ALLOW_CORS?.toLowerCase() === 'true',
},
auth: {
token: process.env.AUTH_TOKEN,
nonceTtlSeconds: Number.parseInt(
process.env.AUTH_NONCE_TTL_SECONDS ?? `${5 * 60}`,
10,
),
maxValidityPeriodSeconds: Number.parseInt(
process.env.AUTH_VALIDITY_PERIOD_SECONDS ?? `${24 * 60 * 60}`,
10, // 24 hours
),
stateTtlMs: Number.parseInt(
process.env.AUTH_STATE_TTL_MILLISECONDS ?? `${5 * 60 * 1_000}`,
10, // 5 minutes
),
postLoginRedirectUri: process.env.AUTH_POST_LOGIN_REDIRECT_URI,
allowedRedirectDomain: process.env.AUTH_ALLOWED_REDIRECT_DOMAIN,
auth0: {
domain: process.env.AUTH0_DOMAIN,
clientId: process.env.AUTH0_CLIENT_ID,
clientSecret: process.env.AUTH0_CLIENT_SECRET,
redirectUri: process.env.AUTH0_REDIRECT_URI,
audience: process.env.AUTH0_API_AUDIENCE,
scope: process.env.AUTH0_SCOPE || 'openid',
jwksCacheMaxAgeMs: Number.parseInt(
process.env.AUTH0_JWKS_CACHE_MAX_AGE_MILLISECONDS ??
`${60 * 60 * 1_000}`,
10, // 1 hour
),
jwksCooldownMs: Number.parseInt(
process.env.AUTH0_JWKS_COOLDOWN_MILLISECONDS ?? `${30_000}`,
10, // 30 seconds
),
},
rateLimit: {
max: Number.parseInt(process.env.AUTH_RATE_LIMIT_MAX ?? `${5}`, 10),
windowSeconds: Number.parseInt(
process.env.AUTH_RATE_LIMIT_WINDOW_SECONDS ?? `${60}`,
10,
),
},
},
balances: {
providers: {
safe: {
prices: {
baseUri:
process.env.PRICES_PROVIDER_API_BASE_URI ||
'https://api.coingecko.com/api/v3',
apiKey: process.env.PRICES_PROVIDER_API_KEY,
pricesTtlSeconds: Number.parseInt(
process.env.PRICES_TTL_SECONDS ?? `${300}`,
10,
),
nativeCoinPricesTtlSeconds: Number.parseInt(
process.env.NATIVE_COINS_PRICES_TTL_SECONDS ?? `${100}`,
10,
),
notFoundPriceTtlSeconds: Number.parseInt(
process.env.NOT_FOUND_PRICE_TTL_SECONDS ?? `${72 * 60 * 60}`,
10,
),
highRefreshRateTokens:
process.env.HIGH_REFRESH_RATE_TOKENS?.split(',') ?? [],
highRefreshRateTokensTtlSeconds: Number.parseInt(
process.env.HIGH_REFRESH_RATE_TOKENS_TTL_SECONDS ?? `${30}`,
10,
),
},
},
zerion: {
apiKey: process.env.ZERION_API_KEY,
baseUri: process.env.ZERION_BASE_URI || 'https://api.zerion.io',
currencies: [
'USD',
'EUR',
'ETH',
'AUD',
'BTC',
'CAD',
'CHF',
'CNY',
'GBP',
'INR',
'JPY',
'KRW',
'NZD',
'RUB',
'TRY',
'ZAR',
],
limitPeriodSeconds: Number.parseInt(
process.env.ZERION_RATE_LIMIT_PERIOD_SECONDS ?? `${10}`,
10,
),
limitCalls: Number.parseInt(
process.env.ZERION_RATE_LIMIT_CALLS_BY_PERIOD ?? `${2}`,
10,
),
},
},
},
portfolio: {
cache: {
ttlSeconds: Number.parseInt(
process.env.PORTFOLIO_CACHE_TTL_SECONDS ?? `${10}`,
10,
),
},
filters: {
dustThresholdUsd: Number.parseFloat(
process.env.PORTFOLIO_DUST_THRESHOLD_USD ?? `${0.001}`,
),
},
},
blockchain: {
blocklistEnabled: process.env.BLOCKLIST_ENABLED?.toLowerCase() !== 'false',
blocklistSecretData: process.env.BLOCKLIST_ENCRYPTED_DATA,
blocklistSecretKey: process.env.BLOCKLIST_SECRET_KEY,
blocklistSecretSalt: process.env.BLOCKLIST_SECRET_SALT,
infura: {
apiKey: process.env.INFURA_API_KEY,
},
},
bridge: {
baseUri: 'https://li.quest',
apiKey: process.env.BRIDGE_API_KEY,
},
contracts: {
trustedForDelegateCall: {
maxSequentialPages: Number.parseInt(
process.env.TRUSTED_CONTRACTS_MAX_SEQUENTIAL_PAGES ?? `${3}`,
10,
),
},
},
db: {
migrator: {
// Determines if database migrations should be executed. By default, it will execute
executeMigrations:
process.env.DB_MIGRATIONS_EXECUTE?.toLowerCase() !== 'false',
// The number of times to retry running migrations in case of failure. Defaults to 5 retries.
numberOfRetries: process.env.DB_MIGRATIONS_NUMBER_OF_RETRIES ?? 5,
// The time interval (in milliseconds) to wait before retrying a failed migration. Defaults to 1000ms (1 second).
retryAfterMs: process.env.DB_MIGRATIONS_RETRY_AFTER_MS ?? 1000, // Milliseconds
},
orm: {
// Indicates if migrations should be automatically run when the ORM initializes. Set to false to control this behavior manually.
migrationsRun: false,
// Enables the automatic loading of entities into the ORM.
autoLoadEntities: true,
// Requires manual initialization of the database connection. Useful for controlling startup behavior.
manualInitialization: true,
// The name of the table where migrations are stored. Uses the environment variable value or defaults to '_migrations'.
migrationsTableName:
process.env.ORM_MIGRATION_TABLE_NAME || '_migrations',
cache:
process.env.ORM_CACHE_ENABLED?.toLowerCase() === 'true'
? {
type: 'redis',
options: {
socket: {
host: process.env.REDIS_HOST || 'localhost',
port: process.env.REDIS_PORT || '6379',
},
username: process.env.REDIS_USER,
password: process.env.REDIS_PASS,
},
duration: Number.parseInt(
process.env.ORM_CACHE_DURATION ?? `${1000}`,
10,
),
/**
* @todo Fix the underlying issue with the Redis client shutting down
*/
ignoreErrors: true,
}
: false,
},
connection: {
postgres: {
host: process.env.POSTGRES_HOST || 'localhost',
port: process.env.POSTGRES_PORT || '5432',
database: process.env.POSTGRES_DB || 'safe-client-gateway',
schema: process.env.POSTGRES_SCHEMA || 'main', //@TODO: use this schema
username: process.env.POSTGRES_USER || 'postgres',
password: process.env.POSTGRES_PASSWORD || 'postgres',
ssl: {
enabled: process.env.POSTGRES_SSL_ENABLED?.toLowerCase() === 'true',
requestCert:
process.env.POSTGRES_SSL_REQUEST_CERT?.toLowerCase() !== 'false',
// If the value is not explicitly set to false, default should be true
// If not false the server will reject any connection which is not authorized with the list of supplied CAs
// https://nodejs.org/docs/latest-v20.x/api/tls.html#tlscreateserveroptions-secureconnectionlistener
rejectUnauthorized:
process.env.POSTGRES_SSL_REJECT_UNAUTHORIZED?.toLowerCase() !==
'false',
caPath: process.env.POSTGRES_SSL_CA_PATH,
},
},
},
}, // TODO: Unify base URLs with staking
earn: {
testnet: {
baseUri:
process.env.STAKING_TESTNET_API_BASE_URI ||
'https://api.testnet.kiln.fi',
apiKey: process.env.EARN_TESTNET_API_KEY,
},
mainnet: {
baseUri: process.env.STAKING_API_BASE_URI || 'https://api.kiln.fi',
apiKey: process.env.EARN_MAINNET_API_KEY,
},
},
email: {
pushwoosh: {
applicationCode: process.env.EMAIL_API_APPLICATION_CODE,
baseUri: process.env.EMAIL_API_BASE_URI || 'https://api.pushwoosh.com',
apiKey: process.env.EMAIL_API_KEY,
fromEmail: process.env.EMAIL_API_FROM_EMAIL,
fromName: process.env.EMAIL_API_FROM_NAME || 'Safe',
},
// AWS SES email configuration. Enabled via FF_SES_EMAIL feature flag.
// SES region is resolved from AWS_REGION by the SDK default credential chain.
// AWS_REGION
ses: {
// Verified sender email address in SES.
fromEmail: process.env.AWS_SES_FROM_EMAIL,
// Display name shown in the "From" field. Defaults to 'Safe'.
fromName: process.env.AWS_SES_FROM_NAME || 'Safe',
// BullMQ queue configuration for email sending.
queue: {
removeOnComplete: {
// Time (in seconds) to keep completed jobs. Defaults to 3600 (1 hour).
age: Number.parseInt(
process.env.EMAIL_QUEUE_REMOVE_ON_COMPLETE_AGE ?? `${3600}`,
10,
),
// Maximum number of completed jobs to keep. Defaults to 1000.
count: Number.parseInt(
process.env.EMAIL_QUEUE_REMOVE_ON_COMPLETE_COUNT ?? `${1000}`,
10,
),
},
removeOnFail: {
// Time (in seconds) to keep failed jobs. Defaults to 86400 (24 hours).
age: Number.parseInt(
process.env.EMAIL_QUEUE_REMOVE_ON_FAIL_AGE ?? `${86400}`,
10,
),
// Maximum number of failed jobs to keep. Defaults to 500.
count: Number.parseInt(
process.env.EMAIL_QUEUE_REMOVE_ON_FAIL_COUNT ?? `${500}`,
10,
),
},
backoff: {
// Backoff strategy for retrying failed jobs. Defaults to 'exponential'.
type: process.env.EMAIL_QUEUE_BACKOFF_TYPE || 'exponential',
// Initial backoff delay in milliseconds. Defaults to 5000 (5s).
delay: Number.parseInt(
process.env.EMAIL_QUEUE_BACKOFF_DELAY ?? `${5000}`,
10,
),
},
// Maximum number of retry attempts. Defaults to 3.
attempts: Number.parseInt(
process.env.EMAIL_QUEUE_ATTEMPTS ?? `${3}`,
10,
),
// Number of concurrent workers processing email jobs. Defaults to 5.
concurrency: Number.parseInt(
process.env.EMAIL_QUEUE_CONCURRENCY ?? `${5}`,
10,
),
},
},
},
expirationTimeInSeconds: {
deviatePercent: Number.parseInt(
process.env.EXPIRATION_DEVIATE_PERCENT ?? `${10}`,
10,
),
default: Number.parseInt(
process.env.EXPIRATION_TIME_DEFAULT_SECONDS ?? `${60}`,
10,
),
rpc: Number.parseInt(
process.env.EXPIRATION_TIME_RPC_SECONDS ?? `${15}`,
10,
),
hoodi: Number.parseInt(
process.env.HOODI_EXPIRATION_TIME_SECONDS ?? `${60}`,
10,
),
indexing: Number.parseInt(
process.env.EXPIRATION_TIME_INDEXING_SECONDS ?? `${5}`,
10,
),
staking: Number.parseInt(
process.env.EXPIRATION_TIME_STAKING_SECONDS ?? `${60}`,
10,
),
zerionPositions: Number.parseInt(
process.env.EXPIRATION_TIME_POSITIONS_SECONDS ?? `${300}`,
10,
),
notFound: {
default: Number.parseInt(
process.env.DEFAULT_NOT_FOUND_EXPIRE_TIME_SECONDS ?? `${30}`,
10,
),
contract: Number.parseInt(
process.env.CONTRACT_NOT_FOUND_EXPIRE_TIME_SECONDS ?? `${60}`,
10,
),
token: Number.parseInt(
process.env.TOKEN_NOT_FOUND_EXPIRE_TIME_SECONDS ?? `${60}`,
10,
),
},
},
express: {
// Controls the maximum request body size. If this is a number, then the value
// specifies the number of bytes; if it is a string, the value is passed to the
// bytes library for parsing. Defaults to '100kb'.
// https://expressjs.com/en/resources/middleware/body-parser.html
jsonLimit: process.env.EXPRESS_JSON_LIMIT ?? '1mb',
},
features: {
email: process.env.FF_EMAIL?.toLowerCase() === 'true',
sesEmail: process.env.FF_SES_EMAIL?.toLowerCase() === 'true',
// Support both new (FF_ZERION_ENABLED) and legacy (FF_ZERION_BALANCES_CHAIN_IDS) env vars
zerionBalancesEnabled:
!!process.env.FF_ZERION_ENABLED ||
!!process.env.FF_ZERION_BALANCES_CHAIN_IDS,
zerionPositions:
process.env.FF_ZERION_POSITIONS_DISABLED?.toLowerCase() !== 'true',
debugLogs: process.env.FF_DEBUG_LOGS?.toLowerCase() === 'true',
configHooksDebugLogs:
process.env.FF_CONFIG_HOOKS_DEBUG_LOGS?.toLowerCase() === 'true',
auth: process.env.FF_AUTH?.toLowerCase() === 'true',
oidc_auth: process.env.FF_OIDC_AUTH?.toLowerCase() === 'true',
counterfactualBalances:
process.env.FF_COUNTERFACTUAL_BALANCES?.toLowerCase() === 'true',
users: process.env.FF_USERS?.toLowerCase() === 'true',
hookHttpPostEvent:
process.env.FF_HOOK_HTTP_POST_EVENT?.toLowerCase() === 'true',
improvedAddressPoisoning:
process.env.FF_IMPROVED_ADDRESS_POISONING?.toLowerCase() === 'true',
hashVerification: {
api: process.env.FF_HASH_VERIFICATION_API?.toLowerCase() === 'true',
proposal:
process.env.FF_HASH_VERIFICATION_PROPOSAL?.toLowerCase() === 'true',
},
signatureVerification: {
api: process.env.FF_SIGNATURE_VERIFICATION_API?.toLowerCase() === 'true',
proposal:
process.env.FF_SIGNATURE_VERIFICATION_PROPOSAL?.toLowerCase() ===
'true',
},
messageVerification:
process.env.FF_MESSAGE_VERIFICATION?.toLowerCase() === 'true',
ethSign: process.env.FF_ETH_SIGN?.toLowerCase() === 'true',
trustedDelegateCall:
process.env.FF_TRUSTED_DELEGATE_CALL?.toLowerCase() === 'true',
// TODO: Remove this feature flag once the feature is established.
trustedForDelegateCallContractsList:
process.env.FF_TRUSTED_FOR_DELEGATE_CALL_CONTRACTS_LIST?.toLowerCase() ===
'true',
filterValueParsing:
process.env.FF_FILTER_VALUE_PARSING?.toLowerCase() === 'true',
vaultTransactionsMapping:
process.env.FF_VAULT_TRANSACTIONS_MAPPING?.toLowerCase() === 'true',
lifiTransactionsMapping:
process.env.FF_LIFITRANSACTIONS_MAPPING?.toLowerCase() === 'true',
cacheInFlightRequests:
process.env.HTTP_CLIENT_CACHE_IN_FLIGHT_REQUESTS?.toLowerCase() ===
'true',
},
httpClient: {
// Timeout in milliseconds to be used for the HTTP client.
// A value of 0 disables the timeout.
requestTimeout: Number.parseInt(
process.env.HTTP_CLIENT_REQUEST_TIMEOUT_MILLISECONDS ?? `${5_000}`,
10,
),
ownersTimeout: Number.parseInt(
process.env.HTTP_CLIENT_REQUEST_TIMEOUT_MILLISECONDS_OWNERS ?? `${5_000}`,
10,
),
},
undici: {
// Maximum number of connections per origin. Defaults to 100.
connections: Number.parseInt(
process.env.UNDICI_CONNECTIONS ?? `${100}`,
10,
),
// Number of requests to pipeline. Defaults to 1 (no pipelining).
pipelining: Number.parseInt(process.env.UNDICI_PIPELINING ?? `${1}`, 10),
// Timeout for socket connection in milliseconds. Defaults to 10000 (10 seconds).
connectTimeout: Number.parseInt(
process.env.UNDICI_CONNECT_TIMEOUT_MILLISECONDS ?? `${10_000}`,
10,
),
// Time of inactivity on socket in milliseconds before closing. Defaults to 30000 (30 seconds).
keepAliveTimeout: Number.parseInt(
process.env.UNDICI_KEEP_ALIVE_TIMEOUT_MILLISECONDS ?? `${30_000}`,
10,
),
// Maximum time to keep a connection alive in milliseconds. Defaults to 600000 (600 seconds / 10 minutes).
keepAliveMaxTimeout: Number.parseInt(
process.env.UNDICI_KEEP_ALIVE_MAX_TIMEOUT_MILLISECONDS ?? `${600_000}`,
10,
),
},
circuitBreaker: {
// Whether the circuit breaker is enabled
enabled: process.env.CIRCUIT_BREAKER_ENABLED?.toLowerCase() !== 'false',
// Number of failures to open the circuit, and consecutive successes to close it
threshold: Number.parseInt(
process.env.CIRCUIT_BREAKER_THRESHOLD ?? `${10}`,
10,
),
// Time in milliseconds to wait before attempting to close the circuit (timeout period)
timeout: Number.parseInt(
process.env.CIRCUIT_BREAKER_TIMEOUT ?? `${30_000}`,
10,
), // 30 seconds
// Time window in milliseconds for tracking failures
rollingWindow: Number.parseInt(
process.env.CIRCUIT_BREAKER_ROLLING_WINDOW ?? `${60_000}`,
10,
), // 60 seconds
// Percentage of threshold used in HALF_OPEN state (0–100)
halfOpenFailureRateThreshold: Number.parseInt(
process.env.CIRCUIT_BREAKER_HALF_OPEN_FAILURE_RATE_THRESHOLD ?? `${30}`,
10,
),
},
jwt: {
issuer: process.env.JWT_ISSUER,
secret: process.env.JWT_SECRET,
},
locking: {
baseUri:
process.env.LOCKING_PROVIDER_API_BASE_URI ||
'https://safe-locking.safe.global',
eligibility: {
fingerprintEncryptionKey: process.env.FINGERPRINT_ENCRYPTION_KEY,
nonEligibleCountryCodes:
process.env.FINGERPRINT_NON_ELIGIBLE_COUNTRY_CODES?.split(',') ?? [
'US',
],
},
},
log: {
level: process.env.LOG_LEVEL || 'debug',
silent: process.env.LOG_SILENT?.toLowerCase() === 'true',
prettyColorize: process.env.LOG_PRETTY_COLORIZE?.toLowerCase() === 'true',
},
owners: {
// There is no hook to invalidate the owners, so defaulting 0 disables the cache
ownersTtlSeconds: Number.parseInt(
process.env.OWNERS_TTL_SECONDS ?? `${0}`,
10,
),
},
mappings: {
imitation: {
lookupDistance: Number.parseInt(
process.env.IMITATION_LOOKUP_DISTANCE ?? `${3}`,
10,
),
prefixLength: Number.parseInt(
process.env.IMITATION_PREFIX_LENGTH ?? `${3}`,
10,
),
suffixLength: Number.parseInt(
process.env.IMITATION_SUFFIX_LENGTH ?? `${4}`,
10,
),
// Note: due to high value formatted token values, we use bigint
// This means the value tolerance can only be an integer
valueTolerance: BigInt(process.env.IMITATION_VALUE_TOLERANCE ?? 1),
echoLimit: BigInt(process.env.IMITATION_ECHO_LIMIT ?? `${10}`),
},
history: {
maxNestedTransfers: Number.parseInt(
process.env.MAX_NESTED_TRANSFERS ?? `${100}`,
10,
),
},
transactionData: {
maxTokenInfoIndexSize: Number.parseInt(
process.env.MAX_TOKEN_INFO ?? `${100}`,
10,
),
},
safe: {
maxOverviews: Number.parseInt(
process.env.MAX_SAFE_OVERVIEWS ?? `${10}`,
10,
),
},
},
pushNotifications: {
baseUri:
process.env.PUSH_NOTIFICATIONS_API_BASE_URI ||
'https://fcm.googleapis.com/v1/projects',
project: process.env.PUSH_NOTIFICATIONS_API_PROJECT,
serviceAccount: {
clientEmail:
process.env.PUSH_NOTIFICATIONS_API_SERVICE_ACCOUNT_CLIENT_EMAIL,
privateKey:
process.env.PUSH_NOTIFICATIONS_API_SERVICE_ACCOUNT_PRIVATE_KEY,
},
getSubscribersBySafeTtlMilliseconds: +(
process.env.PUSH_NOTIFICATIONS_GET_SUBSCRIBERS_BY_SAFE_TTL_MILLISECONDS ||
60 * 1_000
),
oauth2TokenTtlBufferInSeconds: Number.parseInt(
process.env.PUSH_NOTIFICATIONS_API_OAUTH2_TOKEN_TTL_BUFFER_IN_SECONDS ??
`${120}`,
10,
),
queue: {
removeOnComplete: {
age: Number.parseInt(
process.env.PUSH_NOTIFICATION_QUEUE_REMOVE_ON_COMPLETE_AGE ??
`${3600}`,
10,
),
count: Number.parseInt(
process.env.PUSH_NOTIFICATION_QUEUE_REMOVE_ON_COMPLETE_COUNT ??
`${5000}`,
10,
),
},
removeOnFail: {
age: Number.parseInt(
process.env.PUSH_NOTIFICATION_QUEUE_REMOVE_ON_FAIL_AGE ?? `${43200}`,
10,
),
count: Number.parseInt(
process.env.PUSH_NOTIFICATION_QUEUE_REMOVE_ON_FAIL_COUNT ?? `${500}`,
10,
),
},
backoff: {
type: process.env.PUSH_NOTIFICATION_QUEUE_BACKOFF_TYPE || 'exponential',
delay: Number.parseInt(
process.env.PUSH_NOTIFICATION_QUEUE_BACKOFF_DELAY ?? `${1000}`,
10,
),
},
attempts: Number.parseInt(
process.env.PUSH_NOTIFICATION_QUEUE_ATTEMPTS ?? `${3}`,
10,
),
concurrency: Number.parseInt(
process.env.PUSH_NOTIFICATION_QUEUE_CONCURRENCY ?? `${5}`,
10,
),
},
},
redis: {
user: process.env.REDIS_USER,
pass: process.env.REDIS_PASS,
host: process.env.REDIS_HOST || 'localhost',
port: process.env.REDIS_PORT || '6379',
disableOfflineQueue:
process.env.REDIS_DISABLE_OFFLINE_QUEUE?.toString() === 'true',
connectTimeout: process.env.REDIS_CONNECT_TIMEOUT || 10_000,
keepAlive: process.env.REDIS_KEEP_ALIVE || 30_000,
},
relay: {
baseUri:
process.env.RELAY_PROVIDER_API_BASE_URI || 'https://api.gelato.cloud',
limit: Number.parseInt(process.env.RELAY_THROTTLE_LIMIT ?? `${5}`, 10),
ttlSeconds: Number.parseInt(
process.env.RELAY_THROTTLE_TTL_SECONDS ?? `${60 * 60 * 24}`,
10,
),
dailyLimitRelayerChainsIds:
process.env.RELAY_DAILY_LIMIT_CHAIN_IDS?.split(',') ?? [],
apiKey: {
// Ethereum Mainnet
1: process.env.RELAY_PROVIDER_API_KEY_MAINNET,
// Optimism
10: process.env.RELAY_PROVIDER_API_KEY_OPTIMISM,
// BNB
56: process.env.RELAY_PROVIDER_API_KEY_BSC,
// Gnosis
100: process.env.RELAY_PROVIDER_API_KEY_GNOSIS_CHAIN,
// Unichain
130: process.env.RELAY_PROVIDER_API_KEY_UNICHAIN,
// Polygon
137: process.env.RELAY_PROVIDER_API_KEY_POLYGON,
// Polygon zkEVM
1101: process.env.RELAY_PROVIDER_API_KEY_POLYGON_ZKEVM,
// Base
8453: process.env.RELAY_PROVIDER_API_KEY_BASE,
// Arbitrum
42161: process.env.RELAY_PROVIDER_API_KEY_ARBITRUM_ONE,
// Avalanche
43114: process.env.RELAY_PROVIDER_API_KEY_AVALANCHE,
// Linea
59144: process.env.RELAY_PROVIDER_API_KEY_LINEA,
// Blast
81457: process.env.RELAY_PROVIDER_API_KEY_BLAST,
// Sepolia
11155111: process.env.RELAY_PROVIDER_API_KEY_SEPOLIA,
},
noFeeCampaign: {
// Key is the chainId
1: {
startsAtTimeStamp: Number.parseInt(
process.env.RELAY_NO_FEE_CAMPAIGN_MAINNET_START_TIMESTAMP ?? `${0}`,
10,
),
endsAtTimeStamp: Number.parseInt(
process.env.RELAY_NO_FEE_CAMPAIGN_MAINNET_END_TIMESTAMP ?? `${0}`,
10,
),
maxGasLimit: Number.parseInt(
process.env.RELAY_NO_FEE_CAMPAIGN_MAINNET_MAX_GAS_LIMIT ?? `${0}`,
10,
),
safeTokenAddress:
process.env.RELAY_NO_FEE_CAMPAIGN_MAINNET_SAFE_TOKEN_ADDRESS,
relayRules:
parseRelayRules(
process.env.RELAY_NO_FEE_CAMPAIGN_MAINNET_RELAY_RULES,
) ?? [],
},
11155111: {
startsAtTimeStamp: Number.parseInt(
process.env.RELAY_NO_FEE_CAMPAIGN_SEPOLIA_START_TIMESTAMP ?? `${0}`,
10,
),
endsAtTimeStamp: Number.parseInt(
process.env.RELAY_NO_FEE_CAMPAIGN_SEPOLIA_END_TIMESTAMP ?? `${0}`,
10,
),
maxGasLimit: Number.parseInt(
process.env.RELAY_NO_FEE_CAMPAIGN_SEPOLIA_MAX_GAS_LIMIT ?? `${0}`,
10,
),
safeTokenAddress:
process.env.RELAY_NO_FEE_CAMPAIGN_SEPOLIA_SAFE_TOKEN_ADDRESS,
relayRules:
parseRelayRules(
process.env.RELAY_NO_FEE_CAMPAIGN_SEPOLIA_RELAY_RULES,
) ?? [],
},
},
fee: {
enabledChainIds: process.env.RELAY_FEE_CHAIN_IDS?.split(',') ?? [],
baseUri: process.env.FEE_SERVICE_BASE_URI,
feePreviewTtlSeconds: Number.parseInt(
process.env.RELAY_FEE_PREVIEW_TTL_SECONDS ?? `${10}`,
10,
),
},
},
safeConfig: {
baseUri:
process.env.SAFE_CONFIG_BASE_URI || 'https://safe-config.safe.global/',
chains: {
maxSequentialPages: Number.parseInt(
process.env.SAFE_CONFIG_CHAINS_MAX_SEQUENTIAL_PAGES ?? `${3}`,
10,
),
},
safes: {
maxSequentialPages: Number.parseInt(
process.env.SAFE_CONFIG_SAFES_MAX_SEQUENTIAL_PAGES ?? `${10}`,
10,
),
},
cgwServiceKey: process.env.SAFE_CONFIG_CGW_KEY || 'CGW',
},
safeDataDecoder: {
baseUri:
process.env.SAFE_DATA_DECODER_BASE_URI ||
'https://safe-decoder.safe.global',
},
safeTransaction: {
useVpcUrl: process.env.USE_TX_SERVICE_VPC_URL?.toLowerCase() === 'true',
apiKey: process.env.TX_SERVICE_API_KEY,
},
transactions: {
statusIndexingGracePeriodMs: Number.parseInt(
process.env.TRANSACTION_STATUS_INDEXING_GRACE_PERIOD_MS ?? `${60 * 1000}`,
10,
),
},
safeWebApp: {
baseUri: process.env.SAFE_WEB_APP_BASE_URI || 'https://app.safe.global',
},
spaces: {
addressBooks: {
maxItems: Number.parseInt(
process.env.SPACES_MAX_ADDRESS_BOOK_ITEMS_PER_SPACE ?? `${500}`,
10,
),
},
maxSafesPerSpace: Number.parseInt(
process.env.SPACES_MAX_SAFES_PER_SPACE ?? `${10}`,
10,
),
maxSpaceCreationsPerUser: Number.parseInt(
process.env.MAX_SPACE_CREATIONS_PER_USER ?? `${3}`,
10,
),
maxInvites: Number.parseInt(process.env.SPACES_MAX_INVITES ?? `${50}`, 10),
inviteExpirySeconds: Number.parseInt(
process.env.SPACES_INVITE_EXPIRY_SECONDS ?? `${7 * 24 * 60 * 60}`,
10,
),
rateLimit: {
creation: {
max: Number.parseInt(process.env.SPACES_RATE_LIMIT_MAX ?? `${10}`, 10),
windowSeconds: Number.parseInt(
process.env.SPACES_RATE_LIMIT_WINDOW_SECONDS ?? `${600}`,
10,
),
},
addressBookUpsertion: {
max: Number.parseInt(
process.env.SPACES_ADDRESS_BOOK_RATE_LIMIT_MAX ?? `${500}`,
10,
),
windowSeconds: Number.parseInt(
process.env.SPACES_ADDRESS_BOOK_RATE_LIMIT_WINDOW_SECONDS ?? `${600}`,
10,
),
},
resendInvite: {
max: Number.parseInt(
process.env.SPACES_RESEND_INVITE_RATE_LIMIT_MAX ?? `${50}`,
10,
),
windowSeconds: Number.parseInt(
process.env.SPACES_RESEND_INVITE_RATE_LIMIT_WINDOW_SECONDS ??
`${600}`,
10,
),
},
},
},
staking: {
testnet: {
baseUri:
process.env.STAKING_TESTNET_API_BASE_URI ||
'https://api.testnet.kiln.fi',
apiKey: process.env.STAKING_TESTNET_API_KEY,
},
mainnet: {
baseUri: process.env.STAKING_API_BASE_URI || 'https://api.kiln.fi',
apiKey: process.env.STAKING_API_KEY,
},
},
swaps: {
// CoW Swap API URLs for different chains
// See: https://github.com/cowprotocol/cow-sdk/blob/main/packages/order-book/src/api.ts
api: {
1: 'https://api.cow.fi/mainnet',
56: 'https://api.cow.fi/bnb',
100: 'https://api.cow.fi/xdai',
137: 'https://api.cow.fi/polygon',
8453: 'https://api.cow.fi/base',
232: 'https://api.cow.fi/lens',
42161: 'https://api.cow.fi/arbitrum_one',
43114: 'https://api.cow.fi/avalanche',
11155111: 'https://api.cow.fi/sepolia',
59144: 'https://api.cow.fi/linea',
9745: 'https://api.cow.fi/plasma',
},
explorerBaseUri:
process.env.SWAPS_EXPLORER_URI || 'https://explorer.cow.fi/',
// If set to true, it will restrict the Swap Feature to be used only
// with Apps contained in allowedApps
restrictApps: process.env.SWAPS_RESTRICT_APPS?.toLowerCase() === 'true',
// The comma-separated collection of allowed CoW Swap Apps.
// In order for this collection to take effect, restrictApps should be set to true
// The app names should match the "App Code" of the metadata provided to CoW Swap.
// See https://explorer.cow.fi/appdata?tab=encode
allowedApps: process.env.SWAPS_ALLOWED_APPS?.split(',') || [],
// Upper limit of parts we will request from CoW for TWAP orders, after
// which we return base values for those orders
// Note: 11 is the average number of parts, confirmed by CoW
maxNumberOfParts: Number.parseInt(
process.env.SWAPS_MAX_NUMBER_OF_PARTS ?? `${11}`,
10,
),
},
targetedMessaging: {
fileStorage: {
// The type of file storage to use. Defaults to 'local'.
// Supported values: 'aws', 'local'
type: process.env.TARGETED_MESSAGING_FILE_STORAGE_TYPE || 'local',
aws: {
// This will be ignored if the TARGETED_MESSAGING_FILE_STORAGE_TYPE is set to 'local'.
// For reference, these environment variables should be present in the environment,
// but they are not transferred to the memory/configuration file:
// AWS_REGION
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
bucketName:
process.env.AWS_STORAGE_BUCKET_NAME || 'safe-client-gateway',
basePath: process.env.AWS_S3_BASE_PATH || 'assets/targeted-messaging',
},
local: {
// This will be ignored if the TARGETED_MESSAGING_FILE_STORAGE_TYPE is set to 'aws'.
baseDir:
process.env.TARGETED_MESSAGING_LOCAL_BASE_DIR ||
'assets/targeted-messaging',
},
},
},
csvExport: {
fileStorage: {
// The type of file storage to use. Defaults to 'local'.
// Supported values: 'aws', 'local'
type: process.env.CSV_EXPORT_FILE_STORAGE_TYPE || 'local',
aws: {
// This will be ignored if the CSV_EXPORT_FILE_STORAGE_TYPE is set to 'local'.
// For reference, these environment variables should be present in the environment,
// but they are not transferred to the memory/configuration file:
// AWS_REGION
accessKeyId: process.env.CSV_AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.CSV_AWS_SECRET_ACCESS_KEY,
bucketName:
process.env.CSV_AWS_STORAGE_BUCKET_NAME || 'safe-client-gateway',
basePath: process.env.CSV_AWS_S3_BASE_PATH || 'assets/csv-export',
},
local: {
// This will be ignored if the CSV_EXPORT_FILE_STORAGE_TYPE is set to 'aws'.
baseDir: process.env.CSV_EXPORT_LOCAL_BASE_DIR || 'assets/csv-export',
},
},
// The time-to-live (TTL) for the signed URLs generated for CSV exports.
// Defaults to 3600 seconds (1 hour).
signedUrlTtlSeconds: Number.parseInt(
process.env.CSV_EXPORT_SIGNED_URL_TTL_SECONDS ?? `${60 * 60}`,
10,
),
// BullMq queue configuration for CSV exports.
queue: {
removeOnComplete: {
age: Number.parseInt(
process.env.CSV_EXPORT_QUEUE_REMOVE_ON_COMPLETE_AGE ?? `${86400}`,
10,
), // 24 hours
count: Number.parseInt(
process.env.CSV_EXPORT_QUEUE_REMOVE_ON_COMPLETE_COUNT ?? `${1000}`,
10,
), // last 1000
},
removeOnFail: {
age: Number.parseInt(
process.env.CSV_EXPORT_QUEUE_REMOVE_ON_FAIL_AGE ?? `${43200}`,
10,
), // 12 hours
count: Number.parseInt(
process.env.CSV_EXPORT_QUEUE_REMOVE_ON_FAIL_COUNT ?? `${100}`,
10,
), // last 100
},
backoff: {
type: process.env.CSV_EXPORT_QUEUE_BACKOFF_TYPE || 'exponential',
delay: Number.parseInt(
process.env.CSV_EXPORT_QUEUE_BACKOFF_DELAY ?? `${2000}`,
10,
), // 2 seconds
},
attempts: Number.parseInt(
process.env.CSV_EXPORT_QUEUE_ATTEMPTS ?? `${3}`,
10,
),
concurrency: Number.parseInt(
process.env.CSV_EXPORT_QUEUE_CONCURRENCY ?? `${3}`,
10,
),
},
},
safeShield: {
threatAnalysis: {
blockaid: {
apiKey: process.env.BLOCKAID_CLIENT_API_KEY,
},
},
},
etherscan: {
baseUri:
process.env.ETHERSCAN_BASE_URI || 'https://api.etherscan.io/v2/api',
apiKey: process.env.ETHERSCAN_API_KEY,
gasPriceCacheTtlSeconds: Number.parseInt(
process.env.ETHERSCAN_GAS_PRICE_CACHE_TTL_SECONDS ?? `${10}`,
10,
),
},
captcha: {
enabled: process.env.CAPTCHA_ENABLED?.toLowerCase() === 'true',
secretKey: process.env.CAPTCHA_SECRET_KEY,
},
});
// Helper function to parse relay rules from environment variable
const parseRelayRules = (
envValue: string | undefined,
): RelayRules | undefined => {
if (!envValue) {
return undefined;
}
const parsed = JSON.parse(envValue) as RelayRules;
parsed.every(
(rule) =>
typeof rule === 'object' &&
rule !== null &&
typeof rule.balanceMin === 'string' &&
typeof rule.balanceMax === 'string' &&
typeof rule.limit === 'number' &&
BigInt(rule.balanceMin) >= 0 &&
BigInt(rule.balanceMax) >= BigInt(rule.balanceMin) &&
rule.limit >= 0,
);
return parsed;
};