-
Notifications
You must be signed in to change notification settings - Fork 825
/
serverless.yml
243 lines (221 loc) · 6.95 KB
/
serverless.yml
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
service: llama-apy
package:
individually: true
frameworkVersion: '3'
provider:
name: aws
runtime: nodejs16.x
stage: dev
region: eu-central-1
tracing:
apiGateway: true
lambda: true
memorySize: 1024
iam:
role:
statements:
- Effect: Allow
Action:
- xray:PutTraceSegments
- xray:PutTelemetryRecords
Resource: '*'
- Effect: Allow
Action:
- s3:ListBucket
- s3:*Object*
- sqs:SendMessage
Resource: '*'
environment:
BUCKET_DATA: { Ref: BucketData }
DATABASE_URL: ${file(./env.js):DATABASE_URL}
ZEROX_API: ${file(./env.js):ZEROX_API}
GRAPH_API_KEY: ${file(./env.js):GRAPH_API_KEY}
functions:
# ---------- TRIGGER HANDLERS
# --- top-lvl-entrypoint
triggerEntrypoint:
handler: src/handlers/triggerEntrypoint.handler
description: Lambda to launch the adaptor pipeline
timeout: 30
events:
# every new hour
- schedule: cron(0 * * * ? *)
environment:
ADAPTER_QUEUE_URL: { Ref: AdapterQueue }
# --- adaptors
triggerAdaptor:
handler: src/handlers/triggerAdaptor.handler
description: Lambda which runs adaptors
timeout: 900
events:
- sqs:
arn:
Fn::GetAtt:
- AdapterQueue
- Arn
batchSize: 4
functionResponseType: ReportBatchItemFailures
environment:
ALCHEMY_CONNECTION_ARBITRUM: ${file(./env.js):ALCHEMY_CONNECTION_ARBITRUM}
ALCHEMY_CONNECTION_ETHEREUM: ${file(./env.js):ALCHEMY_CONNECTION_ETHEREUM}
ALCHEMY_CONNECTION_POLYGON: ${file(./env.js):ALCHEMY_CONNECTION_POLYGON}
ETHEREUM_RPC: ${file(./env.js):ETHEREUM_RPC}
XDAI_RPC: ${file(./env.js):XDAI_RPC}
CRONOS_RPC: ${file(./env.js):CRONOS_RPC}
FANTOM_RPC: ${file(./env.js):FANTOM_RPC}
OPTIMISM_RPC: ${file(./env.js):OPTIMISM_RPC}
AVAX_RPC: ${file(./env.js):AVAX_RPC}
ARBITRUM_RPC: ${file(./env.js):ARBITRUM_RPC}
BASE_RPC: ${file(./env.js):BASE_RPC}
TRON_RPC: ${file(./env.js):TRON_RPC}
TVL_SPIKE_WEBHOOK: ${file(./env.js):TVL_SPIKE_WEBHOOK}
NEW_YIELDS_WEBHOOK: ${file(./env.js):NEW_YIELDS_WEBHOOK}
SMARDEX_SUBGRAPH_API_KEY: ${file(./env.js):SMARDEX_SUBGRAPH_API_KEY}
VENDOR_FINANCE: ${file(./env.js):VENDOR_FINANCE}
TRADERJOE: ${file(./env.js):TRADERJOE}
OSMOSIS_API_KEY: ${file(./env.js):OSMOSIS_API_KEY}
# --- data enrichment
triggerEnrichment:
handler: src/handlers/triggerEnrichment.handler
description: Lambda which runs enrichment process
timeout: 900
memorySize: 1024
events:
# every hour at 16 past
- schedule: cron(16 * * * ? *)
# --- stats update
triggerStat:
handler: src/handlers/triggerStat.handler
description: Lambda which updates the stat table
timeout: 600
events:
# 30min prior midnight
- schedule: cron(30 23 * * ? *)
# --- median insert
triggerMedian:
handler: src/handlers/triggerMedian.handler
description: Lambda which inserts latest value into the median table
timeout: 600
events:
# 30min prior midnight
- schedule: cron(30 23 * * ? *)
# --- save poolsEnriched as CSV
triggerCsv:
handler: src/handlers/triggerCsv.handler
description: Lambda which saves poolsEnriched as csv to s3 bucket
timeout: 300
events:
# every hour at 25 past
- schedule: cron(25 * * * ? *)
# --- trigger monitor
triggerMonitor:
handler: src/handlers/triggerMonitor.handler
description: Lambda which triggers the monitor query for logging stale adapters
timeout: 300
events:
# every hour at 30 past
- schedule: cron(30 * * * ? *)
environment:
STALE_PROJECTS_WEBHOOK: ${file(./env.js):STALE_PROJECTS_WEBHOOK}
# --- trigger perpetuals
triggerPerpertuals:
handler: src/handlers/triggerPerpetuals.handler
description: Lambda which triggers perp files
timeout: 300
events:
# every new hour
- schedule: cron(0 * * * ? *)
triggerMedianProject:
handler: src/handlers/triggerMedianProject.handler
description: Lambda which triggers daily median calculation for each project
timeout: 300
events:
# 30min prior midnight
- schedule: cron(30 23 * * ? *)
triggerLSDRates:
handler: src/handlers/triggerLSDRates.handler
description: Lambda which triggers lsd market rate and expected rate
timeout: 300
events:
# every new hour
- schedule: cron(0 * * * ? *)
environment:
ETHEREUM_RPC: ${file(./env.js):ETHEREUM_RPC}
triggerProtocolNameChange:
handler: src/handlers/triggerProtocolNameChange.handler
description: Lambda which checks for protocol renames
timeout: 300
events:
# every hour 40min past
- schedule: cron(40 * * * ? *)
environment:
STALE_PROJECTS_WEBHOOK: ${file(./env.js):STALE_PROJECTS_WEBHOOK}
resources:
Resources:
# QUEUES
# --- queue for adaptor handler
AdapterQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: ${self:service}-${self:custom.stage}-AdapterQueue
VisibilityTimeout: 960
# setting this to 9hours
MessageRetentionPeriod: 32400
RedrivePolicy:
deadLetterTargetArn:
Fn::GetAtt:
- DeadLetterQueue
- Arn
# this params is requried, otherwise cloudformation error
# means that after 3 failed runs, the message will be moved from the adaptor queue
# to the DLQ
maxReceiveCount: 3
# --- DLQ
DeadLetterQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: ${self:service}-${self:custom.stage}-DeadLetterQueue
# leaving this at max, 14days, after that msg in there will be deleted
MessageRetentionPeriod: 1209600
# --- create bucket
BucketData:
Type: AWS::S3::Bucket
Properties:
BucketName: ${self:service}-${self:custom.stage}-data
# --- alarm stuff for DLQ
DlqAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: ${self:service}-${self:custom.stage}-AdapterDLQ
AlarmDescription: There are failed messages in the dead letter queue.
Namespace: AWS/SQS
MetricName: ApproximateNumberOfMessagesVisible
Dimensions:
- Name: QueueName
Value: !GetAtt DeadLetterQueue.QueueName
Statistic: Sum
Period: 60
EvaluationPeriods: 1
Threshold: 0
ComparisonOperator: GreaterThanThreshold
AlarmActions:
- !Ref DlqAlarmEmail
DlqAlarmEmail:
Type: AWS::SNS::Topic
Properties:
Subscription:
- Endpoint: [email protected]
Protocol: email
custom:
stage: ${opt:stage, self:provider.stage}
webpack:
webpackConfig: 'webpack.config.js'
includeModules: true
packager: 'npm'
excludeFiles: src/**/*.test.js
prune:
automatic: true
number: 5
plugins:
- serverless-webpack
- serverless-prune-plugin