eco-solver 0.0.1-security → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of eco-solver might be problematic. Click here for more details.
- package/.eslintignore +8 -0
- package/.eslintrc.js +24 -0
- package/.github/workflows/ci.yaml +38 -0
- package/.nvmrc +1 -0
- package/.prettierignore +3 -0
- package/.prettierrc +8 -0
- package/Dockerfile +11 -0
- package/LICENSE +21 -0
- package/README.md +29 -5
- package/config/default.ts +135 -0
- package/config/development.ts +95 -0
- package/config/preproduction.ts +17 -0
- package/config/production.ts +17 -0
- package/config/staging.ts +17 -0
- package/config/test.ts +7 -0
- package/index.js +43 -0
- package/jest.config.ts +14 -0
- package/nest-cli.json +8 -0
- package/package.json +115 -6
- package/src/api/api.module.ts +27 -0
- package/src/api/balance.controller.ts +41 -0
- package/src/api/quote.controller.ts +54 -0
- package/src/api/tests/balance.controller.spec.ts +113 -0
- package/src/api/tests/quote.controller.spec.ts +83 -0
- package/src/app.module.ts +74 -0
- package/src/balance/balance.module.ts +14 -0
- package/src/balance/balance.service.ts +230 -0
- package/src/balance/balance.ws.service.ts +104 -0
- package/src/balance/types.ts +16 -0
- package/src/bullmq/bullmq.helper.ts +41 -0
- package/src/bullmq/processors/eth-ws.processor.ts +47 -0
- package/src/bullmq/processors/inbox.processor.ts +55 -0
- package/src/bullmq/processors/interval.processor.ts +54 -0
- package/src/bullmq/processors/processor.module.ts +14 -0
- package/src/bullmq/processors/signer.processor.ts +41 -0
- package/src/bullmq/processors/solve-intent.processor.ts +73 -0
- package/src/bullmq/processors/tests/solve-intent.processor.spec.ts +3 -0
- package/src/bullmq/utils/queue.ts +22 -0
- package/src/chain-monitor/chain-monitor.module.ts +12 -0
- package/src/chain-monitor/chain-sync.service.ts +134 -0
- package/src/chain-monitor/tests/chain-sync.service.spec.ts +190 -0
- package/src/commander/.eslintrc.js +6 -0
- package/src/commander/balance/balance-command.module.ts +12 -0
- package/src/commander/balance/balance.command.ts +73 -0
- package/src/commander/command-main.ts +15 -0
- package/src/commander/commander-app.module.ts +31 -0
- package/src/commander/eco-config.command.ts +20 -0
- package/src/commander/safe/safe-command.module.ts +11 -0
- package/src/commander/safe/safe.command.ts +70 -0
- package/src/commander/transfer/client.command.ts +24 -0
- package/src/commander/transfer/transfer-command.module.ts +26 -0
- package/src/commander/transfer/transfer.command.ts +138 -0
- package/src/commander/utils.ts +8 -0
- package/src/common/chains/definitions/arbitrum.ts +12 -0
- package/src/common/chains/definitions/base.ts +21 -0
- package/src/common/chains/definitions/eco.ts +54 -0
- package/src/common/chains/definitions/ethereum.ts +22 -0
- package/src/common/chains/definitions/helix.ts +53 -0
- package/src/common/chains/definitions/mantle.ts +12 -0
- package/src/common/chains/definitions/optimism.ts +22 -0
- package/src/common/chains/definitions/polygon.ts +12 -0
- package/src/common/chains/supported.ts +26 -0
- package/src/common/chains/transport.ts +19 -0
- package/src/common/errors/eco-error.ts +155 -0
- package/src/common/events/constants.ts +3 -0
- package/src/common/events/viem.ts +22 -0
- package/src/common/logging/eco-log-message.ts +74 -0
- package/src/common/redis/constants.ts +55 -0
- package/src/common/redis/redis-connection-utils.ts +106 -0
- package/src/common/routes/constants.ts +3 -0
- package/src/common/utils/objects.ts +34 -0
- package/src/common/utils/strings.ts +49 -0
- package/src/common/utils/tests/objects.spec.ts +23 -0
- package/src/common/utils/tests/strings.spec.ts +22 -0
- package/src/common/viem/contracts.ts +25 -0
- package/src/common/viem/tests/utils.spec.ts +115 -0
- package/src/common/viem/utils.ts +78 -0
- package/src/contracts/ERC20.contract.ts +389 -0
- package/src/contracts/EntryPoint.V6.contract.ts +1309 -0
- package/src/contracts/KernelAccount.abi.ts +87 -0
- package/src/contracts/OwnableExecutor.abi.ts +128 -0
- package/src/contracts/SimpleAccount.contract.ts +524 -0
- package/src/contracts/inbox.ts +8 -0
- package/src/contracts/index.ts +9 -0
- package/src/contracts/intent-source.ts +55 -0
- package/src/contracts/interfaces/index.ts +1 -0
- package/src/contracts/interfaces/prover.interface.ts +22 -0
- package/src/contracts/prover.ts +9 -0
- package/src/contracts/tests/erc20.contract.spec.ts +59 -0
- package/src/contracts/utils.ts +31 -0
- package/src/decoder/decoder.interface.ts +3 -0
- package/src/decoder/tests/utils.spec.ts +36 -0
- package/src/decoder/utils.ts +24 -0
- package/src/decorators/cacheable.decorator.ts +48 -0
- package/src/eco-configs/aws-config.service.ts +75 -0
- package/src/eco-configs/eco-config.module.ts +44 -0
- package/src/eco-configs/eco-config.service.ts +220 -0
- package/src/eco-configs/eco-config.types.ts +278 -0
- package/src/eco-configs/interfaces/config-source.interface.ts +3 -0
- package/src/eco-configs/tests/aws-config.service.spec.ts +52 -0
- package/src/eco-configs/tests/eco-config.service.spec.ts +137 -0
- package/src/eco-configs/tests/utils.spec.ts +84 -0
- package/src/eco-configs/utils.ts +49 -0
- package/src/fee/fee.module.ts +10 -0
- package/src/fee/fee.service.ts +467 -0
- package/src/fee/tests/fee.service.spec.ts +909 -0
- package/src/fee/tests/utils.spec.ts +49 -0
- package/src/fee/types.ts +44 -0
- package/src/fee/utils.ts +23 -0
- package/src/flags/flags.module.ts +10 -0
- package/src/flags/flags.service.ts +112 -0
- package/src/flags/tests/flags.service.spec.ts +68 -0
- package/src/flags/utils.ts +22 -0
- package/src/health/constants.ts +1 -0
- package/src/health/health.controller.ts +23 -0
- package/src/health/health.module.ts +25 -0
- package/src/health/health.service.ts +40 -0
- package/src/health/indicators/balance.indicator.ts +196 -0
- package/src/health/indicators/eco-redis.indicator.ts +23 -0
- package/src/health/indicators/git-commit.indicator.ts +67 -0
- package/src/health/indicators/mongodb.indicator.ts +11 -0
- package/src/health/indicators/permission.indicator.ts +64 -0
- package/src/intent/create-intent.service.ts +129 -0
- package/src/intent/feasable-intent.service.ts +80 -0
- package/src/intent/fulfill-intent.service.ts +318 -0
- package/src/intent/intent.controller.ts +199 -0
- package/src/intent/intent.module.ts +49 -0
- package/src/intent/schemas/intent-call-data.schema.ts +16 -0
- package/src/intent/schemas/intent-data.schema.ts +114 -0
- package/src/intent/schemas/intent-source.schema.ts +33 -0
- package/src/intent/schemas/intent-token-amount.schema.ts +14 -0
- package/src/intent/schemas/reward-data.schema.ts +48 -0
- package/src/intent/schemas/route-data.schema.ts +52 -0
- package/src/intent/schemas/watch-event.schema.ts +32 -0
- package/src/intent/tests/create-intent.service.spec.ts +215 -0
- package/src/intent/tests/feasable-intent.service.spec.ts +155 -0
- package/src/intent/tests/fulfill-intent.service.spec.ts +564 -0
- package/src/intent/tests/utils-intent.service.spec.ts +308 -0
- package/src/intent/tests/utils.spec.ts +62 -0
- package/src/intent/tests/validate-intent.service.spec.ts +297 -0
- package/src/intent/tests/validation.service.spec.ts +337 -0
- package/src/intent/utils-intent.service.ts +168 -0
- package/src/intent/utils.ts +37 -0
- package/src/intent/validate-intent.service.ts +176 -0
- package/src/intent/validation.sevice.ts +223 -0
- package/src/interceptors/big-int.interceptor.ts +30 -0
- package/src/intervals/interval.module.ts +18 -0
- package/src/intervals/retry-infeasable-intents.service.ts +89 -0
- package/src/intervals/tests/retry-infeasable-intents.service.spec.ts +167 -0
- package/src/kms/errors.ts +0 -0
- package/src/kms/kms.module.ts +12 -0
- package/src/kms/kms.service.ts +65 -0
- package/src/kms/tests/kms.service.spec.ts +60 -0
- package/src/liquidity-manager/jobs/check-balances-cron.job.ts +229 -0
- package/src/liquidity-manager/jobs/liquidity-manager.job.ts +52 -0
- package/src/liquidity-manager/jobs/rebalance.job.ts +61 -0
- package/src/liquidity-manager/liquidity-manager.module.ts +29 -0
- package/src/liquidity-manager/processors/base.processor.ts +117 -0
- package/src/liquidity-manager/processors/eco-protocol-intents.processor.ts +34 -0
- package/src/liquidity-manager/processors/grouped-jobs.processor.ts +103 -0
- package/src/liquidity-manager/queues/liquidity-manager.queue.ts +48 -0
- package/src/liquidity-manager/schemas/rebalance-token.schema.ts +32 -0
- package/src/liquidity-manager/schemas/rebalance.schema.ts +32 -0
- package/src/liquidity-manager/services/liquidity-manager.service.ts +188 -0
- package/src/liquidity-manager/services/liquidity-provider.service.ts +25 -0
- package/src/liquidity-manager/services/liquidity-providers/LiFi/lifi-provider.service.spec.ts +125 -0
- package/src/liquidity-manager/services/liquidity-providers/LiFi/lifi-provider.service.ts +117 -0
- package/src/liquidity-manager/services/liquidity-providers/LiFi/utils/get-transaction-hashes.ts +16 -0
- package/src/liquidity-manager/tests/liquidity-manager.service.spec.ts +142 -0
- package/src/liquidity-manager/types/token-state.enum.ts +5 -0
- package/src/liquidity-manager/types/types.d.ts +52 -0
- package/src/liquidity-manager/utils/address.ts +5 -0
- package/src/liquidity-manager/utils/math.ts +9 -0
- package/src/liquidity-manager/utils/serialize.spec.ts +24 -0
- package/src/liquidity-manager/utils/serialize.ts +47 -0
- package/src/liquidity-manager/utils/token.ts +91 -0
- package/src/main.ts +63 -0
- package/src/nest-redlock/nest-redlock.config.ts +14 -0
- package/src/nest-redlock/nest-redlock.interface.ts +5 -0
- package/src/nest-redlock/nest-redlock.module.ts +64 -0
- package/src/nest-redlock/nest-redlock.service.ts +59 -0
- package/src/prover/proof.service.ts +184 -0
- package/src/prover/prover.module.ts +10 -0
- package/src/prover/tests/proof.service.spec.ts +154 -0
- package/src/quote/dto/quote.intent.data.dto.ts +35 -0
- package/src/quote/dto/quote.reward.data.dto.ts +67 -0
- package/src/quote/dto/quote.route.data.dto.ts +71 -0
- package/src/quote/dto/types.ts +18 -0
- package/src/quote/errors.ts +215 -0
- package/src/quote/quote.module.ts +17 -0
- package/src/quote/quote.service.ts +299 -0
- package/src/quote/schemas/quote-call.schema.ts +16 -0
- package/src/quote/schemas/quote-intent.schema.ts +27 -0
- package/src/quote/schemas/quote-reward.schema.ts +24 -0
- package/src/quote/schemas/quote-route.schema.ts +30 -0
- package/src/quote/schemas/quote-token.schema.ts +14 -0
- package/src/quote/tests/quote.service.spec.ts +444 -0
- package/src/sign/atomic-signer.service.ts +24 -0
- package/src/sign/atomic.nonce.service.ts +114 -0
- package/src/sign/kms-account/kmsToAccount.ts +73 -0
- package/src/sign/kms-account/signKms.ts +30 -0
- package/src/sign/kms-account/signKmsTransaction.ts +37 -0
- package/src/sign/kms-account/signKmsTypedData.ts +21 -0
- package/src/sign/nonce.service.ts +89 -0
- package/src/sign/schemas/nonce.schema.ts +36 -0
- package/src/sign/sign.controller.ts +52 -0
- package/src/sign/sign.helper.ts +23 -0
- package/src/sign/sign.module.ts +27 -0
- package/src/sign/signer-kms.service.ts +27 -0
- package/src/sign/signer.service.ts +26 -0
- package/src/solver/filters/tests/valid-smart-wallet.service.spec.ts +87 -0
- package/src/solver/filters/valid-smart-wallet.service.ts +58 -0
- package/src/solver/solver.module.ts +10 -0
- package/src/transaction/multichain-public-client.service.ts +15 -0
- package/src/transaction/smart-wallets/kernel/actions/encodeData.kernel.ts +57 -0
- package/src/transaction/smart-wallets/kernel/create-kernel-client-v2.account.ts +183 -0
- package/src/transaction/smart-wallets/kernel/create.kernel.account.ts +270 -0
- package/src/transaction/smart-wallets/kernel/index.ts +2 -0
- package/src/transaction/smart-wallets/kernel/kernel-account-client-v2.service.ts +90 -0
- package/src/transaction/smart-wallets/kernel/kernel-account-client.service.ts +107 -0
- package/src/transaction/smart-wallets/kernel/kernel-account.client.ts +105 -0
- package/src/transaction/smart-wallets/kernel/kernel-account.config.ts +34 -0
- package/src/transaction/smart-wallets/simple-account/create.simple.account.ts +19 -0
- package/src/transaction/smart-wallets/simple-account/index.ts +2 -0
- package/src/transaction/smart-wallets/simple-account/simple-account-client.service.ts +42 -0
- package/src/transaction/smart-wallets/simple-account/simple-account.client.ts +83 -0
- package/src/transaction/smart-wallets/simple-account/simple-account.config.ts +5 -0
- package/src/transaction/smart-wallets/smart-wallet.types.ts +38 -0
- package/src/transaction/smart-wallets/utils.ts +14 -0
- package/src/transaction/transaction.module.ts +25 -0
- package/src/transaction/viem_multichain_client.service.ts +100 -0
- package/src/transforms/viem-address.decorator.ts +14 -0
- package/src/utils/bigint.ts +44 -0
- package/src/utils/types.ts +18 -0
- package/src/watch/intent/tests/watch-create-intent.service.spec.ts +257 -0
- package/src/watch/intent/tests/watch-fulfillment.service.spec.ts +141 -0
- package/src/watch/intent/watch-create-intent.service.ts +106 -0
- package/src/watch/intent/watch-event.service.ts +133 -0
- package/src/watch/intent/watch-fulfillment.service.ts +115 -0
- package/src/watch/watch.module.ts +13 -0
- package/test/app.e2e-spec.ts +21 -0
- package/test/jest-e2e.json +9 -0
- package/tsconfig.build.json +4 -0
- package/tsconfig.json +29 -0
@@ -0,0 +1,31 @@
|
|
1
|
+
import { Abi, AbiStateMutability, ContractFunctionName, Hex } from 'viem'
|
2
|
+
import { TargetContractType } from '../eco-configs/eco-config.types'
|
3
|
+
import { ERC20Abi } from './ERC20.contract'
|
4
|
+
import { EcoError } from '../common/errors/eco-error'
|
5
|
+
|
6
|
+
/**
|
7
|
+
* The type for a call to a contract, used for typing multicall mappings
|
8
|
+
*/
|
9
|
+
export type ViemCall<
|
10
|
+
abi extends Abi,
|
11
|
+
mutability extends AbiStateMutability = AbiStateMutability,
|
12
|
+
> = {
|
13
|
+
address: Hex
|
14
|
+
abi: abi
|
15
|
+
functionName: ContractFunctionName<abi, mutability>
|
16
|
+
}
|
17
|
+
|
18
|
+
/**
|
19
|
+
* Get the ABI for the target ERC contract
|
20
|
+
* @param targetType
|
21
|
+
*/
|
22
|
+
export function getERCAbi(targetType: TargetContractType): Abi {
|
23
|
+
switch (targetType) {
|
24
|
+
case 'erc20':
|
25
|
+
return ERC20Abi
|
26
|
+
case 'erc721':
|
27
|
+
case 'erc1155':
|
28
|
+
default:
|
29
|
+
throw EcoError.IntentSourceUnsupportedTargetType(targetType)
|
30
|
+
}
|
31
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import { getSelectorHash, isHex } from '../utils'
|
2
|
+
|
3
|
+
describe('Decoder Utils Test', () => {
|
4
|
+
const data =
|
5
|
+
'0xa9059cbb000000000000000000000000cd80b973e7cbb93c21cc5ac0a5f45d12a32582aa00000000000000000000000000000000000000000000000000000000000004d2'
|
6
|
+
|
7
|
+
describe('isHex', () => {
|
8
|
+
it('should return false if the input is not hex', () => {
|
9
|
+
expect(isHex('16')).toEqual(false)
|
10
|
+
expect(isHex('0xqw')).toEqual(false)
|
11
|
+
})
|
12
|
+
|
13
|
+
it('should return true if the input is hex', () => {
|
14
|
+
expect(isHex(data)).toEqual(true)
|
15
|
+
expect(isHex('0xab')).toEqual(true)
|
16
|
+
})
|
17
|
+
})
|
18
|
+
describe('getSelectorHash', () => {
|
19
|
+
it('should return throw if the input is empty', () => {
|
20
|
+
expect(() => getSelectorHash(undefined)).toThrow('Data is too short')
|
21
|
+
expect(() => getSelectorHash('')).toThrow('Data is too short')
|
22
|
+
})
|
23
|
+
|
24
|
+
it('should return throw if the input is not long engough', () => {
|
25
|
+
expect(() => getSelectorHash('0x')).toThrow('Data is too short')
|
26
|
+
})
|
27
|
+
|
28
|
+
it('should return throw if the input is not hex', () => {
|
29
|
+
expect(() => getSelectorHash('adsfasdfasdfadfccdx')).toThrow('Data is not hex encoded')
|
30
|
+
})
|
31
|
+
|
32
|
+
it('should return the first 4 bytes', () => {
|
33
|
+
expect(getSelectorHash(data)).toEqual('0xa9059cbb')
|
34
|
+
})
|
35
|
+
})
|
36
|
+
})
|
@@ -0,0 +1,24 @@
|
|
1
|
+
/**
|
2
|
+
* Returns the selector hash of the data, which is the first 4 bytes of the data
|
3
|
+
*
|
4
|
+
* @param data the hex encoded data
|
5
|
+
* @returns
|
6
|
+
*/
|
7
|
+
export function getSelectorHash(data: string | undefined): string {
|
8
|
+
if (!data || data.length < 10) {
|
9
|
+
throw new Error('Data is too short')
|
10
|
+
}
|
11
|
+
if (!isHex(data)) {
|
12
|
+
throw new Error('Data is not hex encoded')
|
13
|
+
}
|
14
|
+
return '0x' + data.slice(2, 10)
|
15
|
+
}
|
16
|
+
|
17
|
+
/**
|
18
|
+
* Check if a string is valid hex
|
19
|
+
* @param hex the string to check if it is hex
|
20
|
+
* @returns
|
21
|
+
*/
|
22
|
+
export function isHex(num: string): boolean {
|
23
|
+
return Boolean(num.match(/^0x[0-9a-f]+$/i))
|
24
|
+
}
|
@@ -0,0 +1,48 @@
|
|
1
|
+
import { EcoConfigService } from '@/eco-configs/eco-config.service'
|
2
|
+
import { deserialize, serialize } from '@/liquidity-manager/utils/serialize'
|
3
|
+
import { Cache } from '@nestjs/cache-manager'
|
4
|
+
|
5
|
+
/**
|
6
|
+
* This decorator caches the result of a function for a specified time to live (ttl).
|
7
|
+
* Needs the calling class to have a cacheManager and configService injected.
|
8
|
+
*
|
9
|
+
* @param opts - ttl: time to live in seconds, bypassArgIndex: index of the argument to bypass cache
|
10
|
+
* @returns
|
11
|
+
*/
|
12
|
+
export function Cacheable(opts?: { ttl?: number; bypassArgIndex?: number }) {
|
13
|
+
return function (target: any, key: string, descriptor: PropertyDescriptor) {
|
14
|
+
const originalMethod = descriptor.value
|
15
|
+
|
16
|
+
descriptor.value = async function (...args: any[]) {
|
17
|
+
const cacheManager: Cache = this.cacheManager // Injected service
|
18
|
+
const configService: EcoConfigService = this.configService // Injected service
|
19
|
+
if (opts && !opts.ttl) {
|
20
|
+
opts.ttl = configService.getCache().ttl
|
21
|
+
} else {
|
22
|
+
opts = {
|
23
|
+
ttl: configService.getCache().ttl,
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
// Construct the cache key based on function arguments
|
28
|
+
const cacheKey = `${key}:${JSON.stringify(args)}` // Unique key for the cache
|
29
|
+
|
30
|
+
// Determine whether to bypass cache
|
31
|
+
const forceRefresh = opts.bypassArgIndex ? args[opts.bypassArgIndex] === true : false
|
32
|
+
|
33
|
+
if (!forceRefresh) {
|
34
|
+
const cachedData = await cacheManager.get(cacheKey)
|
35
|
+
if (cachedData && typeof cachedData == 'object') {
|
36
|
+
return deserialize(cachedData)
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
// Call the original method to fetch fresh data
|
41
|
+
const result = await originalMethod.apply(this, args)
|
42
|
+
await cacheManager.set(cacheKey, serialize(result), opts.ttl)
|
43
|
+
return result
|
44
|
+
}
|
45
|
+
|
46
|
+
return descriptor
|
47
|
+
}
|
48
|
+
}
|
@@ -0,0 +1,75 @@
|
|
1
|
+
import { SecretsManager } from '@aws-sdk/client-secrets-manager'
|
2
|
+
import { AwsCredential } from './eco-config.types'
|
3
|
+
import { Injectable, Logger, OnModuleInit } from '@nestjs/common'
|
4
|
+
import * as config from 'config'
|
5
|
+
import { EcoLogMessage } from '../common/logging/eco-log-message'
|
6
|
+
import { ConfigSource } from './interfaces/config-source.interface'
|
7
|
+
import { EcoError } from '../common/errors/eco-error'
|
8
|
+
import { merge } from 'lodash'
|
9
|
+
|
10
|
+
/**
|
11
|
+
* Service to retrieve AWS secrets from AWS Secrets Manager
|
12
|
+
*/
|
13
|
+
@Injectable()
|
14
|
+
export class AwsConfigService implements OnModuleInit, ConfigSource {
|
15
|
+
private logger = new Logger(AwsConfigService.name)
|
16
|
+
private _awsConfigs: Record<string, string> = {}
|
17
|
+
constructor() {}
|
18
|
+
|
19
|
+
async onModuleInit() {
|
20
|
+
await this.initConfigs()
|
21
|
+
}
|
22
|
+
|
23
|
+
/**
|
24
|
+
* @returns the aws configs
|
25
|
+
*/
|
26
|
+
getConfig() {
|
27
|
+
return this.awsConfigs
|
28
|
+
}
|
29
|
+
|
30
|
+
/**
|
31
|
+
* Initialize the configs
|
32
|
+
*/
|
33
|
+
async initConfigs() {
|
34
|
+
this.logger.debug(
|
35
|
+
EcoLogMessage.fromDefault({
|
36
|
+
message: `Initializing aws configs`,
|
37
|
+
}),
|
38
|
+
)
|
39
|
+
let awsCreds = config.get('aws') as any[]
|
40
|
+
if (!Array.isArray(awsCreds)) {
|
41
|
+
awsCreds = [awsCreds]
|
42
|
+
}
|
43
|
+
const creds = await Promise.all(
|
44
|
+
awsCreds.map(async (cred: AwsCredential) => {
|
45
|
+
return await this.getAwsSecrets(cred)
|
46
|
+
}),
|
47
|
+
)
|
48
|
+
merge(this._awsConfigs, ...creds)
|
49
|
+
}
|
50
|
+
|
51
|
+
get awsConfigs(): Record<string, string> {
|
52
|
+
return this._awsConfigs
|
53
|
+
}
|
54
|
+
|
55
|
+
/**
|
56
|
+
* Retrieve the AWS secrets from the AWS Secrets Manager
|
57
|
+
* @param awsCreds the aws credentials
|
58
|
+
* @returns
|
59
|
+
*/
|
60
|
+
private async getAwsSecrets(awsCreds: AwsCredential): Promise<Record<string, string>> {
|
61
|
+
const secretsManager = new SecretsManager({
|
62
|
+
region: awsCreds.region,
|
63
|
+
})
|
64
|
+
try {
|
65
|
+
const data = await secretsManager.getSecretValue({ SecretId: awsCreds.secretID })
|
66
|
+
if (data.SecretString) {
|
67
|
+
const secret = JSON.parse(data.SecretString)
|
68
|
+
return secret as Record<string, string>
|
69
|
+
}
|
70
|
+
} catch (err) {
|
71
|
+
this.logger.error(EcoError.getErrorMessage({ message: err.message }))
|
72
|
+
}
|
73
|
+
return {}
|
74
|
+
}
|
75
|
+
}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
import { DynamicModule, FactoryProvider, Global, Module, Provider } from '@nestjs/common'
|
2
|
+
import { EcoConfigService } from './eco-config.service'
|
3
|
+
import { AwsConfigService } from './aws-config.service'
|
4
|
+
|
5
|
+
@Global()
|
6
|
+
@Module({
|
7
|
+
providers: [EcoConfigModule.createBaseProvider(), AwsConfigService],
|
8
|
+
exports: [EcoConfigService, AwsConfigService],
|
9
|
+
})
|
10
|
+
export class EcoConfigModule {
|
11
|
+
static withAWS(): DynamicModule {
|
12
|
+
return {
|
13
|
+
global: true,
|
14
|
+
module: EcoConfigModule,
|
15
|
+
providers: [EcoConfigModule.createAwsProvider()],
|
16
|
+
exports: [EcoConfigService],
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
static base(): DynamicModule {
|
21
|
+
return {
|
22
|
+
global: true,
|
23
|
+
module: EcoConfigModule,
|
24
|
+
providers: [EcoConfigModule.createBaseProvider()],
|
25
|
+
exports: [EcoConfigService],
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
static createAwsProvider(): Provider {
|
30
|
+
const dynamicConfig: FactoryProvider<EcoConfigService> = {
|
31
|
+
provide: EcoConfigService,
|
32
|
+
useFactory: async (awsConfigService: AwsConfigService) => {
|
33
|
+
await awsConfigService.initConfigs()
|
34
|
+
return new EcoConfigService([awsConfigService])
|
35
|
+
},
|
36
|
+
inject: [AwsConfigService],
|
37
|
+
}
|
38
|
+
return dynamicConfig
|
39
|
+
}
|
40
|
+
|
41
|
+
static createBaseProvider(): Provider {
|
42
|
+
return EcoConfigService
|
43
|
+
}
|
44
|
+
}
|
@@ -0,0 +1,220 @@
|
|
1
|
+
import { Injectable, Logger, OnModuleInit } from '@nestjs/common'
|
2
|
+
import * as _ from 'lodash'
|
3
|
+
import * as config from 'config'
|
4
|
+
import { EcoLogMessage } from '@/common/logging/eco-log-message'
|
5
|
+
import { ConfigSource } from './interfaces/config-source.interface'
|
6
|
+
import {
|
7
|
+
AwsCredential,
|
8
|
+
KmsConfig,
|
9
|
+
EcoConfigType,
|
10
|
+
IntentSource,
|
11
|
+
Solver,
|
12
|
+
SafeType,
|
13
|
+
} from './eco-config.types'
|
14
|
+
import { entries } from 'lodash'
|
15
|
+
import { getAddress } from 'viem'
|
16
|
+
import { addressKeys, getRpcUrl } from '@/common/viem/utils'
|
17
|
+
import { ChainsSupported } from '@/common/chains/supported'
|
18
|
+
import { getChainConfig } from './utils'
|
19
|
+
|
20
|
+
/**
|
21
|
+
* Service class for getting configs for the app
|
22
|
+
*/
|
23
|
+
@Injectable()
|
24
|
+
export class EcoConfigService implements OnModuleInit {
|
25
|
+
private logger = new Logger(EcoConfigService.name)
|
26
|
+
private externalConfigs: any = {}
|
27
|
+
private ecoConfig: config.IConfig
|
28
|
+
|
29
|
+
constructor(private readonly sources: ConfigSource[]) {
|
30
|
+
this.sources.reduce((prev, curr) => {
|
31
|
+
return config.util.extendDeep(prev, curr.getConfig())
|
32
|
+
}, this.externalConfigs)
|
33
|
+
|
34
|
+
this.ecoConfig = config
|
35
|
+
this.initConfigs()
|
36
|
+
}
|
37
|
+
|
38
|
+
async onModuleInit() {}
|
39
|
+
|
40
|
+
/**
|
41
|
+
* Returns the static configs for the app, from the 'config' package
|
42
|
+
* @returns the configs
|
43
|
+
*/
|
44
|
+
static getStaticConfig(): EcoConfigType {
|
45
|
+
return config as unknown as EcoConfigType
|
46
|
+
}
|
47
|
+
|
48
|
+
// Initialize the configs
|
49
|
+
initConfigs() {
|
50
|
+
this.logger.debug(
|
51
|
+
EcoLogMessage.fromDefault({
|
52
|
+
message: `Initializing eco configs`,
|
53
|
+
}),
|
54
|
+
)
|
55
|
+
|
56
|
+
// Merge the secrets with the existing config, the external configs will be overwritten by the internal ones
|
57
|
+
this.ecoConfig = config.util.extendDeep(this.externalConfigs, this.ecoConfig)
|
58
|
+
}
|
59
|
+
|
60
|
+
// Generic getter for key/val of config object
|
61
|
+
get<T>(key: string): T {
|
62
|
+
return this.ecoConfig.get<T>(key)
|
63
|
+
}
|
64
|
+
|
65
|
+
// Returns the alchemy configs
|
66
|
+
getAlchemy(): EcoConfigType['alchemy'] {
|
67
|
+
return this.get('alchemy')
|
68
|
+
}
|
69
|
+
|
70
|
+
// Returns the aws configs
|
71
|
+
getAwsConfigs(): AwsCredential[] {
|
72
|
+
return this.get('aws')
|
73
|
+
}
|
74
|
+
|
75
|
+
// Returns the cache configs
|
76
|
+
getCache(): EcoConfigType['cache'] {
|
77
|
+
return this.get('cache')
|
78
|
+
}
|
79
|
+
|
80
|
+
// Returns the fulfill configs
|
81
|
+
getFulfill(): EcoConfigType['fulfill'] {
|
82
|
+
return this.get('fulfillment')
|
83
|
+
}
|
84
|
+
|
85
|
+
// Returns the source intents config
|
86
|
+
getIntentSources(): EcoConfigType['intentSources'] {
|
87
|
+
const intents = this.get<IntentSource[]>('intentSources').map((intent: IntentSource) => {
|
88
|
+
intent.tokens = intent.tokens.map((token: string) => {
|
89
|
+
return getAddress(token)
|
90
|
+
})
|
91
|
+
const config = getChainConfig(intent.chainID)
|
92
|
+
intent.sourceAddress = config.IntentSource
|
93
|
+
intent.provers = [config.HyperProver]
|
94
|
+
//removing storage prover per audit for hyperlane beta release
|
95
|
+
// if (config.Prover) {
|
96
|
+
// intent.provers.push(config.Prover)
|
97
|
+
// }
|
98
|
+
return intent
|
99
|
+
})
|
100
|
+
return intents
|
101
|
+
}
|
102
|
+
|
103
|
+
// Returns the intent source for a specific chain or undefined if its not supported
|
104
|
+
getIntentSource(chainID: number): IntentSource | undefined {
|
105
|
+
return this.getIntentSources().find((intent) => intent.chainID === chainID)
|
106
|
+
}
|
107
|
+
|
108
|
+
// Returns the aws configs
|
109
|
+
getKmsConfig(): KmsConfig {
|
110
|
+
return this.get('kms')
|
111
|
+
}
|
112
|
+
|
113
|
+
// Returns the safe multisig configs
|
114
|
+
getSafe(): SafeType {
|
115
|
+
const safe = this.get<SafeType>('safe')
|
116
|
+
// validate and checksum the owner address, throws if invalid/not-set
|
117
|
+
safe.owner = getAddress(safe.owner)
|
118
|
+
return safe
|
119
|
+
}
|
120
|
+
|
121
|
+
// Returns the solvers config
|
122
|
+
getSolvers(): EcoConfigType['solvers'] {
|
123
|
+
const solvers = this.get<Record<number, Solver>>('solvers')
|
124
|
+
entries(solvers).forEach(([, solver]: [string, Solver]) => {
|
125
|
+
const config = getChainConfig(solver.chainID)
|
126
|
+
solver.inboxAddress = config.Inbox
|
127
|
+
solver.targets = addressKeys(solver.targets) ?? {}
|
128
|
+
})
|
129
|
+
return solvers
|
130
|
+
}
|
131
|
+
|
132
|
+
// Returns the solver for a specific chain or undefined if its not supported
|
133
|
+
getSolver(chainID: number | bigint): Solver | undefined {
|
134
|
+
chainID = typeof chainID === 'bigint' ? Number(chainID) : chainID
|
135
|
+
return this.getSolvers()[chainID]
|
136
|
+
}
|
137
|
+
|
138
|
+
// Get the launch darkly configs
|
139
|
+
getLaunchDarkly(): EcoConfigType['launchDarkly'] {
|
140
|
+
return this.get('launchDarkly')
|
141
|
+
}
|
142
|
+
|
143
|
+
getDatabaseConfig(): EcoConfigType['database'] {
|
144
|
+
return this.get('database')
|
145
|
+
}
|
146
|
+
|
147
|
+
// Returns the eth configs
|
148
|
+
getEth(): EcoConfigType['eth'] {
|
149
|
+
return this.get('eth')
|
150
|
+
}
|
151
|
+
|
152
|
+
// Returns the intervals config, sets defaults for repeatOpts and jobTemplate if not set
|
153
|
+
getIntervals(): EcoConfigType['intervals'] {
|
154
|
+
const configs = this.get('intervals') as EcoConfigType['intervals']
|
155
|
+
for (const [, value] of Object.entries(configs)) {
|
156
|
+
_.merge(value, configs.defaults, value)
|
157
|
+
}
|
158
|
+
return configs
|
159
|
+
}
|
160
|
+
|
161
|
+
// Returns the intent configs
|
162
|
+
getIntentConfigs(): EcoConfigType['intentConfigs'] {
|
163
|
+
return this.get('intentConfigs')
|
164
|
+
}
|
165
|
+
|
166
|
+
// Returns the external APIs config
|
167
|
+
getExternalAPIs(): EcoConfigType['externalAPIs'] {
|
168
|
+
return this.get('externalAPIs')
|
169
|
+
}
|
170
|
+
|
171
|
+
getLoggerConfig(): EcoConfigType['logger'] {
|
172
|
+
return this.get('logger')
|
173
|
+
}
|
174
|
+
|
175
|
+
getMongooseUri() {
|
176
|
+
const config = this.getDatabaseConfig()
|
177
|
+
return config.auth.enabled
|
178
|
+
? `${config.uriPrefix}${config.auth.username}:${config.auth.password}@${config.uri}/${config.dbName}`
|
179
|
+
: `${config.uriPrefix}${config.uri}/${config.dbName}`
|
180
|
+
}
|
181
|
+
|
182
|
+
// Returns the redis configs
|
183
|
+
getRedis(): EcoConfigType['redis'] {
|
184
|
+
return this.get('redis')
|
185
|
+
}
|
186
|
+
|
187
|
+
// Returns the server configs
|
188
|
+
getServer(): EcoConfigType['server'] {
|
189
|
+
return this.get('server')
|
190
|
+
}
|
191
|
+
|
192
|
+
// Returns the liquidity manager config
|
193
|
+
getLiquidityManager(): EcoConfigType['liquidityManager'] {
|
194
|
+
return this.get('liquidityManager')
|
195
|
+
}
|
196
|
+
|
197
|
+
// Returns the liquidity manager config
|
198
|
+
getWhitelist(): EcoConfigType['whitelist'] {
|
199
|
+
return this.get('whitelist')
|
200
|
+
}
|
201
|
+
|
202
|
+
getChainRPCs() {
|
203
|
+
const { apiKey, networks } = this.getAlchemy()
|
204
|
+
const supportedAlchemyChainIds = _.map(networks, 'id')
|
205
|
+
|
206
|
+
const entries = ChainsSupported.map((chain) => {
|
207
|
+
const rpcApiKey = supportedAlchemyChainIds.includes(chain.id) ? apiKey : undefined
|
208
|
+
return [chain.id, getRpcUrl(chain, rpcApiKey).url]
|
209
|
+
})
|
210
|
+
return Object.fromEntries(entries) as Record<number, string>
|
211
|
+
}
|
212
|
+
|
213
|
+
/**
|
214
|
+
* Checks to see what networks we have inbox contracts for
|
215
|
+
* @returns the supported chains for the event
|
216
|
+
*/
|
217
|
+
getSupportedChains(): bigint[] {
|
218
|
+
return entries(this.getSolvers()).map(([, solver]) => BigInt(solver.chainID))
|
219
|
+
}
|
220
|
+
}
|