huginn_callisto_network_agent 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,1392 @@
1
+ module Agents
2
+ class CallistoNetworkAgent < Agent
3
+ include FormConfigurable
4
+ can_dry_run!
5
+ no_bulk_receive!
6
+ default_schedule 'every_1h'
7
+
8
+ description <<-MD
9
+ The Callisto Network Agent interacts with rpc server from Callisto Network and can create events / tasks if wanted / needed.
10
+
11
+ The `type` can be like checking the wallet's balance.
12
+
13
+ The `wallet` is needed for interaction about balance for example.
14
+
15
+ The `wallet_password` is needed for unlocking a wallet when you want to send CLO.
16
+
17
+ The `value` is needed when you want to send CLO.
18
+
19
+ The `round` is needed when you want to do CLO coldstacking.
20
+
21
+ The `wallet_dest` is needed when you want to send CLO.
22
+
23
+ The `debug` can add verbosity.
24
+
25
+ The `rpc_server` is needed for interaction with the api (per default thenode from callisto.network)
26
+
27
+ Set `expected_update_period_in_days` to the maximum amount of time that you'd expect to pass between Events being created by this Agent.
28
+
29
+ MD
30
+
31
+ event_description <<-MD
32
+ Events look like this:
33
+
34
+ {
35
+ "jsonrpc": "2.0",
36
+ "id": 1,
37
+ "result": 7116789.692103207
38
+ }
39
+ MD
40
+
41
+ def default_options
42
+ {
43
+ 'type' => '',
44
+ 'wallet' => '',
45
+ 'rpc_server' => 'https://rpc.callisto.network/',
46
+ 'debug' => 'false',
47
+ 'emit_events' => 'true',
48
+ 'expected_receive_period_in_days' => '2',
49
+ 'wallet_password' => '',
50
+ 'value' => '',
51
+ 'round' => '',
52
+ 'wallet_dest' => '',
53
+ 'changes_only' => 'true',
54
+ 'filter_for_method_id' => '',
55
+ 'last_block' => ''
56
+ }
57
+ end
58
+
59
+ form_configurable :debug, type: :boolean
60
+ form_configurable :emit_events, type: :boolean
61
+ form_configurable :expected_receive_period_in_days, type: :string
62
+ form_configurable :changes_only, type: :boolean
63
+ form_configurable :type, type: :array, values: ['get_balance', 'net_peerCount', 'net_version', 'eth_protocolVersion', 'eth_gasPrice', 'eth_getTransactionCount', 'stake_reward_clo', 'get_tokens_balance', 'eth_getBlockByNumber', 'soy_farming_soy_clo_pending_rewards', 'soy_farming_soy_cloe_pending_rewards', 'stake_reward_soy', 'soy_farming_soy_btt_pending_rewards', 'soy_cs_pending_rewards', 'clo_sendtx', 'get_tx_by_address_with_filter', 'start_cs_clo', 'withdraw_cs_clo']
64
+ form_configurable :wallet, type: :string
65
+ form_configurable :rpc_server, type: :string
66
+ form_configurable :wallet_password, type: :string
67
+ form_configurable :value, type: :string
68
+ form_configurable :round, type: :string
69
+ form_configurable :wallet_dest, type: :string
70
+ form_configurable :filter_for_method_id, type: :string
71
+ form_configurable :last_block, type: :string
72
+ def validate_options
73
+ errors.add(:base, "type has invalid value: should be 'get_balance' 'net_peerCount' 'net_version' 'eth_protocolVersion' 'eth_gasPrice' 'eth_getTransactionCount' 'stake_reward_clo' 'get_tokens_balance' 'eth_getBlockByNumber' 'soy_farming_soy_clo_pending_rewards' 'soy_farming_soy_cloe_pending_rewards' 'stake_reward_soy' 'soy_farming_soy_btt_pending_rewards' 'soy_cs_pending_rewards' 'clo_sendtx' 'get_tx_by_address_with_filter' 'start_cs_clo' 'withdraw_cs_clo'") if interpolated['type'].present? && !%w(get_balance net_peerCount net_version eth_protocolVersion eth_gasPrice eth_getTransactionCount stake_reward_clo get_tokens_balance eth_getBlockByNumber soy_farming_soy_clo_pending_rewards soy_farming_soy_cloe_pending_rewards stake_reward_soy soy_farming_soy_btt_pending_rewards soy_cs_pending_rewards clo_sendtx get_tx_by_address_with_filter start_cs_clo withdraw_cs_clo).include?(interpolated['type'])
74
+
75
+ unless options['wallet_password'].present? || !['clo_sendtx' 'start_cs_clo' 'withdraw_cs_clo'].include?(options['type'])
76
+ errors.add(:base, "wallet_password is a required field")
77
+ end
78
+
79
+ unless options['value'].present? || !['clo_sendtx' 'start_cs_clo'].include?(options['type'])
80
+ errors.add(:base, "value is a required field")
81
+ end
82
+
83
+ unless options['wallet_dest'].present? || !['clo_sendtx'].include?(options['type'])
84
+ errors.add(:base, "wallet_dest is a required field")
85
+ end
86
+
87
+ unless options['round'].present? || !['start_cs_clo'].include?(options['type'])
88
+ errors.add(:base, "round is a required field")
89
+ end
90
+
91
+ unless options['rpc_server'].present?
92
+ errors.add(:base, "rpc_server is a required field")
93
+ end
94
+
95
+ unless options['wallet'].present? || !['get_balance' 'eth_getTransactionCount' 'stake_reward_clo' 'get_tokens_balance' 'eth_getBlockByNumber' 'soy_farming_soy_clo_pending_rewards' 'soy_farming_soy_cloe_pending_rewards' 'stake_reward_soy' 'soy_farming_soy_btt_pending_rewards' 'soy_cs_pending_rewards' 'clo_sendtx' 'get_tx_by_address_with_filter' 'start_cs_clo'].include?(options['type'])
96
+ errors.add(:base, "wallet is a required field")
97
+ end
98
+
99
+ unless options['last_block'].present? || !['get_tx_by_address_with_filter'].include?(options['type'])
100
+ errors.add(:base, "last_block is a required field")
101
+ end
102
+
103
+ if options.has_key?('emit_events') && boolify(options['emit_events']).nil?
104
+ errors.add(:base, "if provided, emit_events must be true or false")
105
+ end
106
+
107
+ if options.has_key?('changes_only') && boolify(options['changes_only']).nil?
108
+ errors.add(:base, "if provided, changes_only must be true or false")
109
+ end
110
+
111
+ if options.has_key?('debug') && boolify(options['debug']).nil?
112
+ errors.add(:base, "if provided, debug must be true or false")
113
+ end
114
+
115
+ unless options['expected_receive_period_in_days'].present? && options['expected_receive_period_in_days'].to_i > 0
116
+ errors.add(:base, "Please provide 'expected_receive_period_in_days' to indicate how many days can pass before this Agent is considered to be not working")
117
+ end
118
+ end
119
+
120
+ def working?
121
+ event_created_within?(options['expected_receive_period_in_days']) && !recent_error_logs?
122
+ end
123
+
124
+ def receive(incoming_events)
125
+ incoming_events.each do |event|
126
+ interpolate_with(event) do
127
+ log event
128
+ trigger_action
129
+ end
130
+ end
131
+ end
132
+
133
+ def check
134
+ trigger_action
135
+ end
136
+
137
+ private
138
+
139
+ def to_hex(value, length = 64, with_0x = false)
140
+ log value
141
+ log value.class
142
+ hex = value.to_s(16)
143
+ hex = hex.rjust(length, '0')
144
+ hex = hex.sub(/^0x/, '') unless with_0x
145
+ hex = "0x" + hex if with_0x
146
+ hex
147
+ end
148
+
149
+ def log_curl_output(code,body)
150
+
151
+ log "request status : #{code}"
152
+
153
+ if interpolated['debug'] == 'true'
154
+ log "body"
155
+ log body
156
+ end
157
+
158
+ end
159
+
160
+ def find_symbol(contract)
161
+
162
+ case contract
163
+ when "0x9fae2529863bd691b4a7171bdfcf33c7ebb10a65"
164
+ found_symbol = 'SOY'
165
+ when "0x1eaa43544daa399b87eecfcc6fa579d5ea4a6187"
166
+ found_symbol = 'CLOE'
167
+ else
168
+ found_symbol = 'unknown'
169
+ end
170
+ return found_symbol
171
+ end
172
+
173
+ def get_tx_receipt(hash)
174
+
175
+ uri = URI.parse("#{interpolated['rpc_server']}")
176
+ request = Net::HTTP::Post.new(uri)
177
+ request.content_type = "application/json"
178
+ request.body = JSON.dump({
179
+ "method" => "eth_getTransactionReceipt",
180
+ "params" => [
181
+ "#{hash}"
182
+ ],
183
+ "id" => 1,
184
+ "jsonrpc" => "2.0"
185
+ })
186
+
187
+ req_options = {
188
+ use_ssl: uri.scheme == "https",
189
+ }
190
+
191
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
192
+ http.request(request)
193
+ end
194
+
195
+ log_curl_output(response.code,response.body)
196
+
197
+ return JSON.parse(response.body)
198
+
199
+ end
200
+
201
+
202
+ def get_data(x)
203
+ hexa_block = x.to_s(16)
204
+ uri = URI.parse("#{interpolated['rpc_server']}")
205
+ request = Net::HTTP::Post.new(uri)
206
+ request.content_type = "application/json"
207
+ request.body = JSON.dump({
208
+ "jsonrpc" => "2.0",
209
+ "method" => "eth_getBlockByNumber",
210
+ "params" => [
211
+ "0x#{hexa_block}",
212
+ true
213
+ ],
214
+ "id" => 1
215
+ })
216
+
217
+ req_options = {
218
+ use_ssl: uri.scheme == "https",
219
+ }
220
+
221
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
222
+ http.request(request)
223
+ end
224
+
225
+ log_curl_output(response.code,response.body)
226
+
227
+ tx = JSON.parse(response.body)
228
+ timestamp = tx['result']['timestamp'].to_i(16)
229
+ power = (10 ** 18).to_i
230
+ if !tx['result']['transactions'].empty?
231
+ tx['result']['transactions'].each do |transaction|
232
+ if ( !transaction['from'].nil? && interpolated['wallet'].upcase.include?(transaction['from'].upcase) ) || ( !transaction['to'].nil? && interpolated['wallet_dest'].upcase.include?(transaction['to'].upcase) )
233
+ if interpolated['filter_for_method_id'].empty? || interpolated['filter_for_method_id'].include?(transaction['input'][0, 10])
234
+ transaction['blockNumber'] = transaction['blockNumber'].to_i(16)
235
+ transaction['timestamp'] = timestamp
236
+ receipt_data = get_tx_receipt(transaction['hash'])
237
+ transaction['status'] = receipt_data['result']['status']
238
+ # transaction['input_converted_utf8'] = [transaction['input']].pack("H*")
239
+ case transaction['input'][0, 10]
240
+ when "0xb88a802f"
241
+ transaction['call_type'] = 'claimReward'
242
+ transaction['symbol'] = find_symbol(transaction['to'])
243
+ when "0xe80233c6"
244
+ transaction['call_type'] = 'activateNode'
245
+ when "0x65814455"
246
+ transaction['call_type'] = 'deactivateNode'
247
+ when "0xb199892a"
248
+ transaction['call_type'] = 'addNode'
249
+ when "0xcdfdb7dc"
250
+ transaction['call_type'] = 'setRatios'
251
+ when "0x01026099"
252
+ transaction['call_type'] = 'addTokens'
253
+ when "0xb2b99ec9"
254
+ transaction['call_type'] = 'removeNode'
255
+ when "0x095ea7b3"
256
+ transaction['call_type'] = 'approve'
257
+ when "0xf2fde38b"
258
+ transaction['call_type'] = 'transferOwnership'
259
+ when "0x38ed1739"
260
+ transaction['call_type'] = 'swapExactTokensForTokens'
261
+ when "0x2e9b3dc3"
262
+ transaction['call_type'] = 'swapExactCLOForTokens'
263
+ when "0xa6e83852"
264
+ transaction['call_type'] = 'swapTokensForExactCLO'
265
+ when "0x487cda0d"
266
+ transaction['call_type'] = 'depositTokens'
267
+ when "0x8803dbee"
268
+ transaction['call_type'] = 'swapTokensForExactTokens'
269
+ when "0xa9059cbb"
270
+ transaction['call_type'] = 'TokenTransfer'
271
+ transaction['symbol'] = find_symbol(transaction['to'])
272
+ # transaction['to'] = transaction['input'][10, 64]
273
+ transaction['to'] = "0x#{transaction['input'][34, 40]}"
274
+ transaction['value'] = "#{transaction['input'][74, 64].to_i(16) / power.to_i.to_f}"
275
+ when "0x"
276
+ transaction['call_type'] = 'Transfer'
277
+ transaction['symbol'] = "CLO"
278
+ transaction['value'] = "#{transaction['value'].to_i(16) / power.to_i.to_f}"
279
+ when "0xa2e62045"
280
+ transaction['call_type'] = 'update'
281
+ when "0x40c10f19"
282
+ transaction['call_type'] = 'mint'
283
+ else
284
+ transaction['call_type'] = 'unknown'
285
+ end
286
+ create_event payload: transaction
287
+ end
288
+ end
289
+ end
290
+ end
291
+ end
292
+
293
+ def get_tx_by_address_with_filter()
294
+
295
+ if memory['previous_block'].blank? || !memory['previous_block'].present?
296
+ x = interpolated['last_block'].to_i
297
+ if interpolated['debug'] == 'true'
298
+ log "previous_block in memory is missing or empty"
299
+ end
300
+ else
301
+ x = memory['previous_block'].to_i
302
+ x = x + 1
303
+ if interpolated['debug'] == 'true'
304
+ log "previous_block in memory is #{memory['previous_block']} so next batch will be #{x}"
305
+ end
306
+ end
307
+ y = interpolated['last_block'].to_i
308
+
309
+ while x <= y
310
+ get_data(x).to_s
311
+ if interpolated['debug'] == 'true'
312
+ log "block #{x} is parsed"
313
+ end
314
+ memory['previous_block'] = x
315
+ x = x + 1
316
+ end
317
+
318
+ end
319
+
320
+ def unlock_wallet()
321
+ uri = URI.parse("#{interpolated['rpc_server']}")
322
+ request = Net::HTTP::Post.new(uri)
323
+ request.content_type = "application/json;charset=UTF-8"
324
+ request["Accept"] = "application/json, text/plain, /"
325
+ request["Cache-Control"] = "no-cache"
326
+ request.body = JSON.dump({
327
+ "jsonrpc" => "2.0",
328
+ "method" => "personal_unlockAccount",
329
+ "params" => [
330
+ "#{interpolated['wallet']}",
331
+ "#{interpolated['wallet_password']}",
332
+ 15
333
+ ],
334
+ "id" => 67
335
+ })
336
+
337
+ req_options = {
338
+ use_ssl: uri.scheme == "https",
339
+ }
340
+
341
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
342
+ http.request(request)
343
+ end
344
+
345
+ log_curl_output(response.code,response.body)
346
+ return response.body
347
+
348
+ end
349
+
350
+ def clo_sendtx()
351
+ internal = true
352
+ if interpolated['debug'] == 'true'
353
+ log "unlocking the wallet"
354
+ end
355
+ response = JSON.parse(unlock_wallet())
356
+ log "response -> #{response}"
357
+ log "response result -> #{response['result']}"
358
+ if response['result'] == true
359
+ if interpolated['debug'] == 'true'
360
+ log "the wallet is unlocked"
361
+ end
362
+ power_of_10 = 18
363
+ final_value = interpolated['value'].to_i * 10**power_of_10
364
+ uri = URI.parse("#{interpolated['rpc_server']}")
365
+ request = Net::HTTP::Post.new(uri)
366
+ request.content_type = "application/json; charset=UTF-8"
367
+ request.body = JSON.dump({
368
+ "jsonrpc" => "2.0",
369
+ "method" => "eth_sendTransaction",
370
+ "params" => [
371
+ {
372
+ "from" => "#{interpolated['wallet']}",
373
+ "to" => "#{interpolated['wallet_dest']}",
374
+ "value" => "0x#{final_value.to_s(16)}",
375
+ "gasPrice" => "#{eth_gasPrice(internal)}"
376
+ }
377
+ ],
378
+ "id" => 1
379
+ })
380
+
381
+ req_options = {
382
+ use_ssl: uri.scheme == "https",
383
+ }
384
+
385
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
386
+ http.request(request)
387
+ end
388
+
389
+ log_curl_output(response.code,response.body)
390
+
391
+ if interpolated['emit_events'] == 'true'
392
+ create_event payload: response.body
393
+ end
394
+ end
395
+ end
396
+
397
+ def start_cs_clo()
398
+ internal = true
399
+ if interpolated['debug'] == 'true'
400
+ log "unlocking the wallet"
401
+ end
402
+ response = JSON.parse(unlock_wallet())
403
+ log "response -> #{response}"
404
+ log "response result -> #{response['result']}"
405
+ if response['result'] == true
406
+ if interpolated['debug'] == 'true'
407
+ log "the wallet is unlocked"
408
+ end
409
+ power_of_10 = 18
410
+ final_value = interpolated['value'].to_i * 10**power_of_10
411
+ uri = URI.parse("#{interpolated['rpc_server']}")
412
+ request = Net::HTTP::Post.new(uri)
413
+ request.content_type = "application/json"
414
+ request.body = JSON.dump({
415
+ "jsonrpc" => "2.0",
416
+ "method" => "eth_sendTransaction",
417
+ "params" => [
418
+ {
419
+ "from" => "#{interpolated['wallet']}",
420
+ "to" => "0x08A7c8be47773546DC5E173d67B0c38AfFfa4b84",
421
+ "data" => "0x5d8c85ef#{to_hex(interpolated['round'].to_i)}",
422
+ "value" => "0x#{final_value.to_s(16)}",
423
+ "gasPrice" => "#{eth_gasPrice(internal)}"
424
+ }
425
+ ],
426
+ "id" => 1
427
+ })
428
+
429
+ req_options = {
430
+ use_ssl: uri.scheme == "https",
431
+ }
432
+
433
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
434
+ http.request(request)
435
+ end
436
+
437
+ log_curl_output(response.code,response.body)
438
+
439
+ if interpolated['emit_events'] == 'true'
440
+ create_event payload: response.body
441
+ end
442
+ end
443
+ end
444
+
445
+ def withdraw_cs_clo()
446
+ internal = true
447
+ if interpolated['debug'] == 'true'
448
+ log "unlocking the wallet"
449
+ end
450
+ response = JSON.parse(unlock_wallet())
451
+ log "response -> #{response}"
452
+ log "response result -> #{response['result']}"
453
+ if response['result'] == true
454
+ if interpolated['debug'] == 'true'
455
+ log "the wallet is unlocked"
456
+ end
457
+ power_of_10 = 18
458
+ final_value = interpolated['value'].to_i * 10**power_of_10
459
+ uri = URI.parse("#{interpolated['rpc_server']}")
460
+ request = Net::HTTP::Post.new(uri)
461
+ request.content_type = "application/json"
462
+ request.body = JSON.dump({
463
+ "jsonrpc" => "2.0",
464
+ "method" => "eth_sendTransaction",
465
+ "params" => [
466
+ {
467
+ "from" => "#{interpolated['wallet']}",
468
+ "to" => "0x08A7c8be47773546DC5E173d67B0c38AfFfa4b84",
469
+ "data" => "0xcd948855",
470
+ "gasPrice" => "#{eth_gasPrice(internal)}"
471
+ }
472
+ ],
473
+ "id" => 1
474
+ })
475
+
476
+ req_options = {
477
+ use_ssl: uri.scheme == "https",
478
+ }
479
+
480
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
481
+ http.request(request)
482
+ end
483
+
484
+ log_curl_output(response.code,response.body)
485
+
486
+ if interpolated['emit_events'] == 'true'
487
+ create_event payload: response.body
488
+ end
489
+ end
490
+ end
491
+
492
+ def test_create(day,line,last_status,i)
493
+ power = (10 ** 18).to_i
494
+ history = (i - 1).step(last_status['result'][2..].chars.each_slice(64).map(&:join).size - 1, i).map { |b| last_status['result'][2..].chars.each_slice(64).map(&:join)[b] }
495
+ if interpolated['debug'] == 'true'
496
+ log "new -> #{line.to_i(16) / power.to_i.to_f} / history #{history[0].to_i(16) / power.to_i.to_f}"
497
+ end
498
+ if line != history[0]
499
+ create_event :payload => { 'wallet' => "#{interpolated['wallet']}", 'period_in_days' => "#{day}", 'pending_rewards' => "#{line.to_i(16) / power.to_i.to_f}"}
500
+ end
501
+ end
502
+
503
+ def soy_cs_pending_rewards()
504
+
505
+ uri = URI.parse("https://rpc.callisto.network/")
506
+ request = Net::HTTP::Post.new(uri)
507
+ request.content_type = "application/json"
508
+ request["Authority"] = "rpc.callisto.network"
509
+ request["Accept"] = "*/*"
510
+ request["Accept-Language"] = "fr;q=0.7"
511
+ request["Cache-Control"] = "no-cache"
512
+ request["Origin"] = "https://app.soy.finance"
513
+ request["Pragma"] = "no-cache"
514
+ request["Referer"] = "https://app.soy.finance/"
515
+ request["Sec-Fetch-Dest"] = "empty"
516
+ request["Sec-Fetch-Mode"] = "cors"
517
+ request["Sec-Fetch-Site"] = "cross-site"
518
+ request["Sec-Gpc"] = "1"
519
+ request["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36"
520
+ request.body = JSON.dump({
521
+ "jsonrpc" => "2.0",
522
+ "id" => 4043350105485278,
523
+ "method" => "eth_call",
524
+ "params" => [
525
+ {
526
+ "data" => "0x252dba420000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000034000000000000000000000000000000000000000000000000000000000000003e0000000000000000000000000ff9289c2656ca1d194dea1895aaf3278b744fa7000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000024f40f0f52000000000000000000000000#{interpolated['wallet'][2..-1]}0000000000000000000000000000000000000000000000000000000000000000000000000000000086f7e2ef599690b64f0063b3f978ea6ae2814f6300000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000024f40f0f52000000000000000000000000#{interpolated['wallet'][2..-1]}000000000000000000000000000000000000000000000000000000000000000000000000000000007d6c70b6561c31935e6b0dd77731fc63d5ac37f200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000024f40f0f52000000000000000000000000#{interpolated['wallet'][2..-1]}0000000000000000000000000000000000000000000000000000000000000000000000000000000019dcb402162b6937a8aceac87ed6c05219c9bef700000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000024f40f0f52000000000000000000000000#{interpolated['wallet'][2..-1]}0000000000000000000000000000000000000000000000000000000000000000000000000000000031bff88c6124e1622f81b3ba7ed219e5d78abd9800000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000024f40f0f52000000000000000000000000#{interpolated['wallet'][2..-1]}00000000000000000000000000000000000000000000000000000000000000000000000000000000eb4511c90f9387de8f8945abd8c803d5cb27550900000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000024bf92b4ef000000000000000000000000#{interpolated['wallet'][2..-1]}00000000000000000000000000000000000000000000000000000000",
527
+ "to" => "0x3c4127a01b75e3741dd40a7a044bc70e3ed4e77c"
528
+ },
529
+ "latest"
530
+ ]
531
+ })
532
+
533
+ req_options = {
534
+ use_ssl: uri.scheme == "https",
535
+ }
536
+
537
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
538
+ http.request(request)
539
+ end
540
+
541
+ log_curl_output(response.code,response.body)
542
+
543
+ payload = JSON.parse(response.body)
544
+
545
+ if interpolated['changes_only'] == 'true'
546
+ if payload.to_s != memory['soy_cs_pending_rewards']
547
+ i = 0
548
+ last_status = memory['soy_cs_pending_rewards'].gsub("=>", ": ").gsub(": nil,", ": null,")
549
+ last_status = JSON.parse(last_status)
550
+ payload['result'][2..].chars.each_slice(64).map(&:join).each do |line|
551
+ i = i + 1
552
+ case i
553
+ when 11
554
+ day = 7
555
+ if interpolated['debug'] == 'true'
556
+ log "for #{day} days"
557
+ end
558
+ test_create(day,line,last_status,i)
559
+ when 13
560
+ day = 30
561
+ if interpolated['debug'] == 'true'
562
+ log "for #{day} days"
563
+ end
564
+ test_create(day,line,last_status,i)
565
+ when 15
566
+ day = 91
567
+ if interpolated['debug'] == 'true'
568
+ log "for #{day} days"
569
+ end
570
+ test_create(day,line,last_status,i)
571
+ when 17
572
+ day = 182
573
+ if interpolated['debug'] == 'true'
574
+ log "for #{day} days"
575
+ end
576
+ test_create(day,line,last_status,i)
577
+ when 19
578
+ day = 365
579
+ if interpolated['debug'] == 'true'
580
+ log "for #{day} days"
581
+ end
582
+ test_create(day,line,last_status,i)
583
+ end
584
+ memory['soy_cs_pending_rewards'] = payload.to_s
585
+ end
586
+ end
587
+ else
588
+ memory['soy_cs_pending_rewards'] = payload.to_s
589
+ create_event payload: payload[0]
590
+ end
591
+ end
592
+
593
+ def soy_farming_soy_btt_pending_rewards()
594
+
595
+ uri = URI.parse("#{interpolated['rpc_server']}")
596
+ request = Net::HTTP::Post.new(uri)
597
+ request.content_type = "application/json; charset=UTF-8"
598
+ request["Accept"] = "application/json, text/plain, */*"
599
+ request.body = JSON.dump([
600
+ {
601
+ "id" => "d21a3c1c25918de198ed446c67b5983f",
602
+ "jsonrpc" => "2.0",
603
+ "method" => "eth_call",
604
+ "params" => [
605
+ {
606
+ "to" => "0x8967a2adc0e1b7b0422426e350fe389a4745ec78",
607
+ "data" => "0xf40f0f52000000000000000000000000#{interpolated['wallet'][2..-1]}"
608
+ },
609
+ "latest"
610
+ ]
611
+ }
612
+ ])
613
+
614
+ req_options = {
615
+ use_ssl: uri.scheme == "https",
616
+ }
617
+
618
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
619
+ http.request(request)
620
+ end
621
+
622
+ log_curl_output(response.code,response.body)
623
+
624
+ payload = JSON.parse(response.body)
625
+
626
+ if interpolated['changes_only'] == 'true'
627
+ if payload.to_s != memory['soy_farming_soy_btt']
628
+ memory['soy_farming_soy_btt'] = payload.to_s
629
+ power = (10 ** 18).to_i
630
+ payload[0]['result'] = payload[0]['result'].to_i(16) / power.to_i.to_f
631
+ log payload
632
+ create_event payload: payload[0]
633
+ end
634
+ else
635
+ memory['soy_farming_soy_btt'] = payload.to_s
636
+ create_event payload: payload[0]
637
+ end
638
+ end
639
+
640
+ def stake_reward_soy()
641
+
642
+ uri = URI.parse("#{interpolated['rpc_server']}")
643
+ request = Net::HTTP::Post.new(uri)
644
+ request.content_type = "application/json"
645
+ request.body = JSON.dump([
646
+ {
647
+ "id" => "788b52b2b4c0b03223e11841036a32fe",
648
+ "jsonrpc" => "2.0",
649
+ "method" => "eth_call",
650
+ "params" => [
651
+ {
652
+ "to" => "0xeB4511C90F9387De8F8945ABD8C803d5cB275509",
653
+ "data" => "0xbf92b4ef000000000000000000000000#{interpolated['wallet'][2..-1]}"
654
+ },
655
+ "latest"
656
+ ]
657
+ }
658
+ ])
659
+
660
+ req_options = {
661
+ use_ssl: uri.scheme == "https",
662
+ }
663
+
664
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
665
+ http.request(request)
666
+ end
667
+
668
+ log_curl_output(response.code,response.body)
669
+
670
+ payload = JSON.parse(response.body)
671
+
672
+ if interpolated['changes_only'] == 'true'
673
+ if payload.to_s != memory['stake_reward_soy']
674
+ memory['stake_reward_soy'] = payload.to_s
675
+ if payload[0].key?("result")
676
+ power = (10 ** 18).to_i
677
+ payload[0]['result'] = payload[0]['result'].to_i(16) / power.to_i.to_f
678
+ payload[0]['name'] = "soy"
679
+ payload[0]['symbol'] = "SOY"
680
+ end
681
+ create_event payload: payload[0]
682
+ end
683
+ else
684
+ if payload.to_s != memory['stake_reward_soy']
685
+ memory['stake_reward_soy'] = payload.to_s
686
+ end
687
+ power = (10 ** 18).to_i
688
+ payload[0]['result'] = payload[0]['result'].to_i(16) / power.to_i.to_f
689
+ payload[0]['name'] = "soy"
690
+ payload[0]['symbol'] = "SOY"
691
+ create_event payload: payload[0]
692
+ end
693
+ end
694
+
695
+ def soy_farming_soy_clo_pending_rewards()
696
+ # payload = {}
697
+ # callisto_rpc = Eth::Client.create "#{interpolated['rpc_server']}"
698
+ # ens_registry_abi = '[{"type":"constructor","stateMutability":"nonpayable","inputs":[{"type":"address","name":"_rewardsDistribution","internalType":"address"},{"type":"address","name":"_rewardsToken","internalType":"address"},{"type":"address","name":"_lpToken","internalType":"address"}]},{"type":"event","name":"EmergencyWithdraw","inputs":[{"type":"address","name":"user","internalType":"address","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"previousOwner","internalType":"address","indexed":true},{"type":"address","name":"newOwner","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"RewardAdded","inputs":[{"type":"uint256","name":"reward","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"RewardPaid","inputs":[{"type":"address","name":"user","internalType":"address","indexed":true},{"type":"uint256","name":"reward","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"Staked","inputs":[{"type":"address","name":"user","internalType":"address","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"Withdraw","inputs":[{"type":"address","name":"user","internalType":"address","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"accumulatedRewardPerShare","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"emergencyWithdraw","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getAllocationX1000","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getRewardPerSecond","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"globalFarm","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isOwner","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"lastRewardTimestamp","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"limitAmount","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract IERC223"}],"name":"lpToken","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"notifyRewardAmount","inputs":[{"type":"uint256","name":"reward","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"pendingReward","inputs":[{"type":"address","name":"_user","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceOwnership","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"rescueERC20","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"address","name":"to","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract IERC223"}],"name":"rewardsToken","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"tokenReceived","inputs":[{"type":"address","name":"_from","internalType":"address"},{"type":"uint256","name":"_amount","internalType":"uint256"},{"type":"bytes","name":"_data","internalType":"bytes"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"update","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"amount","internalType":"uint256"},{"type":"uint256","name":"rewardDebt","internalType":"uint256"}],"name":"userInfo","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"withdraw","inputs":[{"type":"uint256","name":"_amount","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"withdrawInactiveReward","inputs":[]}]'
699
+ # ens_registry_address = "0xf43Db9BeC8F8626Cb5ADD409C7EBc7272c8f5F8f"
700
+ # ens_registry_name = "SOYLocalFarm"
701
+ # ens_registry = Eth::Contract.from_abi(name: ens_registry_name, address: ens_registry_address, abi: ens_registry_abi)
702
+ # power = (10 ** 18).to_i
703
+ # payload['pending_rewards'] = callisto_rpc.call(ens_registry, "pendingReward", "#{interpolated['wallet']}") / power.to_i.to_f
704
+ # payload['staked_token'] = callisto_rpc.call(ens_registry, "userInfo", "#{interpolated['wallet']}")[0] / power.to_i.to_f
705
+ #
706
+ # if interpolated['debug'] == 'true'
707
+ # log "payload"
708
+ # log payload
709
+ # end
710
+
711
+ uri = URI.parse("#{interpolated['rpc_server']}")
712
+ request = Net::HTTP::Post.new(uri)
713
+ request.content_type = "application/json; charset=UTF-8"
714
+ request["Accept"] = "application/json, text/plain, */*"
715
+ request.body = JSON.dump([
716
+ {
717
+ "id" => "0f206bc0047f6b44cb8f118240b8e351",
718
+ "jsonrpc" => "2.0",
719
+ "method" => "eth_call",
720
+ "params" => [
721
+ {
722
+ "to" => "0xf43Db9BeC8F8626Cb5ADD409C7EBc7272c8f5F8f",
723
+ "data" => "0xf40f0f52000000000000000000000000#{interpolated['wallet'][2..-1]}"
724
+ },
725
+ "latest"
726
+ ]
727
+ }
728
+ ])
729
+
730
+ req_options = {
731
+ use_ssl: uri.scheme == "https",
732
+ }
733
+
734
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
735
+ http.request(request)
736
+ end
737
+
738
+ log_curl_output(response.code,response.body)
739
+
740
+ payload = JSON.parse(response.body)
741
+
742
+ if interpolated['changes_only'] == 'true'
743
+ if payload.to_s != memory['soy_farming_soy_clo']
744
+ memory['soy_farming_soy_clo'] = payload.to_s
745
+ power = (10 ** 18).to_i
746
+ payload[0]['result'] = payload[0]['result'].to_i(16) / power.to_i.to_f
747
+ log payload
748
+ create_event payload: payload[0]
749
+ end
750
+ else
751
+ memory['soy_farming_soy_clo'] = payload.to_s
752
+ create_event payload: payload[0]
753
+ end
754
+ end
755
+
756
+ def soy_farming_soy_cloe_pending_rewards()
757
+
758
+ uri = URI.parse("#{interpolated['rpc_server']}")
759
+ request = Net::HTTP::Post.new(uri)
760
+ request.content_type = "application/json; charset=UTF-8"
761
+ request["Accept"] = "application/json, text/plain, */*"
762
+ request.body = JSON.dump([
763
+ {
764
+ "id" => "0f206bc0047f6b44cb8f118240b8e351",
765
+ "jsonrpc" => "2.0",
766
+ "method" => "eth_call",
767
+ "params" => [
768
+ {
769
+ "to" => "0x8c0a982a4193c6bf8eea6637db0cf9160dcf91fd",
770
+ "data" => "0xf40f0f52000000000000000000000000#{interpolated['wallet'][2..-1]}"
771
+ },
772
+ "latest"
773
+ ]
774
+ }
775
+ ])
776
+
777
+ req_options = {
778
+ use_ssl: uri.scheme == "https",
779
+ }
780
+
781
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
782
+ http.request(request)
783
+ end
784
+
785
+ log_curl_output(response.code,response.body)
786
+
787
+ payload = JSON.parse(response.body)
788
+
789
+ if interpolated['changes_only'] == 'true'
790
+ if payload.to_s != memory['soy_farming_soy_cloe']
791
+ memory['soy_farming_soy_cloe'] = payload.to_s
792
+ power = (10 ** 18).to_i
793
+ payload[0]['result'] = payload[0]['result'].to_i(16) / power.to_i.to_f
794
+ log payload
795
+ create_event payload: payload[0]
796
+ end
797
+ else
798
+ memory['soy_farming_soy_cloe'] = payload.to_s
799
+ create_event payload: payload[0]
800
+ end
801
+ end
802
+
803
+ def eth_getBlockByNumber()
804
+
805
+ uri = URI.parse("#{interpolated['rpc_server']}")
806
+ request = Net::HTTP::Post.new(uri)
807
+ request.content_type = "application/json"
808
+ request.body = JSON.dump({
809
+ "jsonrpc" => "2.0",
810
+ "method" => "eth_getBlockByNumber",
811
+ "params" => [
812
+ "latest",
813
+ false
814
+ ],
815
+ "id" => 1
816
+ })
817
+
818
+ req_options = {
819
+ use_ssl: uri.scheme == "https",
820
+ }
821
+
822
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
823
+ http.request(request)
824
+ end
825
+
826
+ log_curl_output(response.code,response.body)
827
+
828
+ payload = JSON.parse(response.body)
829
+
830
+ if interpolated['changes_only'] == 'true'
831
+ if payload != memory['eth_getBlockByNumber']
832
+ memory['eth_getBlockByNumber'] = payload
833
+ if payload.key?("result")
834
+ payload['result']['number'] = payload['result']['number'].to_i(16)
835
+ payload['result']['timestamp'] = payload['result']['timestamp'].to_i(16)
836
+ payload['result']['difficulty'] = payload['result']['difficulty'].to_i(16)
837
+ payload['result']['extraData'] = payload['result']['extraData'].to_i(16)
838
+ payload['result']['gasLimit'] = payload['result']['gasLimit'].to_i(16)
839
+ payload['result']['gasUsed'] = payload['result']['gasUsed'].to_i(16)
840
+ payload['result']['nonce'] = payload['result']['nonce'].to_i(16)
841
+ payload['result']['size'] = payload['result']['size'].to_i(16)
842
+ payload['result']['totalDifficulty'] = payload['result']['totalDifficulty'].to_i(16)
843
+ payload['result']['name'] = "callisto"
844
+ payload['result']['symbol'] = "CLO"
845
+ end
846
+ create_event payload: payload
847
+ end
848
+ else
849
+ if payload != memory['eth_getBlockByNumber']
850
+ memory['eth_getBlockByNumber'] = payload
851
+ end
852
+ payload['result']['number'] = payload['result']['number'].to_i(16)
853
+ payload['result']['timestamp'] = payload['result']['timestamp'].to_i(16)
854
+ payload['result']['difficulty'] = payload['result']['difficulty'].to_i(16)
855
+ payload['result']['extraData'] = payload['result']['extraData'].to_i(16)
856
+ payload['result']['gasLimit'] = payload['result']['gasLimit'].to_i(16)
857
+ payload['result']['gasUsed'] = payload['result']['gasUsed'].to_i(16)
858
+ payload['result']['nonce'] = payload['result']['nonce'].to_i(16)
859
+ payload['result']['size'] = payload['result']['size'].to_i(16)
860
+ payload['result']['totalDifficulty'] = payload['result']['totalDifficulty'].to_i(16)
861
+ payload['result']['name'] = "callisto"
862
+ payload['result']['symbol'] = "CLO"
863
+ create_event payload: payload
864
+ end
865
+ end
866
+
867
+ def get_tokens_balance()
868
+
869
+ uri = URI.parse("#{interpolated['rpc_server']}")
870
+ request = Net::HTTP::Post.new(uri)
871
+ request.content_type = "application/json; charset=UTF-8"
872
+ request["Accept"] = "application/json, text/plain, */*"
873
+ request.body = JSON.dump([
874
+ {
875
+ "id" => "65b0be964fde4eacba0c993a7bd4caaa",
876
+ "jsonrpc" => "2.0",
877
+ "method" => "eth_call",
878
+ "params" => [
879
+ {
880
+ "to" => "0x1eAa43544dAa399b87EEcFcC6Fa579D5ea4A6187",
881
+ "data" => "0x70a08231000000000000000000000000#{interpolated['wallet'][2..-1]}"
882
+ },
883
+ "latest"
884
+ ]
885
+ },
886
+ {
887
+ "id" => "e2a10af788ec1d4afa57558a857b9319",
888
+ "jsonrpc" => "2.0",
889
+ "method" => "eth_call",
890
+ "params" => [
891
+ {
892
+ "to" => "0x6182d2cd59227c20B486a53976dcEeAF38e76Eed",
893
+ "data" => "0x70a08231000000000000000000000000#{interpolated['wallet'][2..-1]}"
894
+ },
895
+ "latest"
896
+ ]
897
+ },
898
+ {
899
+ "id" => "b4bef730614cb7cbc6585c7e963029d3",
900
+ "jsonrpc" => "2.0",
901
+ "method" => "eth_call",
902
+ "params" => [
903
+ {
904
+ "to" => "0xcC00860947035a26Ffe24EcB1301ffAd3a89f910",
905
+ "data" => "0x70a08231000000000000000000000000#{interpolated['wallet'][2..-1]}"
906
+ },
907
+ "latest"
908
+ ]
909
+ },
910
+ {
911
+ "id" => "dfab9e50ca9e48c1fb9f2ca9c009ea58",
912
+ "jsonrpc" => "2.0",
913
+ "method" => "eth_call",
914
+ "params" => [
915
+ {
916
+ "to" => "0xCC78D0A86B0c0a3b32DEBd773Ec815130F9527CF",
917
+ "data" => "0x70a08231000000000000000000000000#{interpolated['wallet'][2..-1]}"
918
+ },
919
+ "latest"
920
+ ]
921
+ },
922
+ {
923
+ "id" => "a891c856974b2c71d7b99f2c056585d6",
924
+ "jsonrpc" => "2.0",
925
+ "method" => "eth_call",
926
+ "params" => [
927
+ {
928
+ "to" => "0xbf6c50889d3a620eb42C0F188b65aDe90De958c4",
929
+ "data" => "0x70a08231000000000000000000000000#{interpolated['wallet'][2..-1]}"
930
+ },
931
+ "latest"
932
+ ]
933
+ },
934
+ {
935
+ "id" => "1b3b1a0f2c708f8c71bf3d94246ec698",
936
+ "jsonrpc" => "2.0",
937
+ "method" => "eth_call",
938
+ "params" => [
939
+ {
940
+ "to" => "0x9FaE2529863bD691B4A7171bDfCf33C7ebB10a65",
941
+ "data" => "0x70a08231000000000000000000000000#{interpolated['wallet'][2..-1]}"
942
+ },
943
+ "latest"
944
+ ]
945
+ },
946
+ {
947
+ "id" => "ab9c68381989f3e3e47fb163244d7bf2",
948
+ "jsonrpc" => "2.0",
949
+ "method" => "eth_call",
950
+ "params" => [
951
+ {
952
+ "to" => "0x83736D58F496afab4cF7D8453575ab59279810ec",
953
+ "data" => "0x70a08231000000000000000000000000#{interpolated['wallet'][2..-1]}"
954
+ },
955
+ "latest"
956
+ ]
957
+ }
958
+ ])
959
+
960
+ req_options = {
961
+ use_ssl: uri.scheme == "https",
962
+ }
963
+
964
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
965
+ http.request(request)
966
+ end
967
+
968
+ log_curl_output(response.code,response.body)
969
+
970
+ payload = JSON.parse(response.body)
971
+ fixed_payload = JSON.parse(response.body)
972
+
973
+ if interpolated['changes_only'] == 'true'
974
+ if payload != memory['get_tokens_balance']
975
+ if "#{memory['get_tokens_balance']}" == ''
976
+ payload.each do | token |
977
+ case token['id']
978
+ when "65b0be964fde4eacba0c993a7bd4caaa"
979
+ token['name'] = "Callisto Enterprise"
980
+ token['symbol'] = "CLOE"
981
+ when "1b3b1a0f2c708f8c71bf3d94246ec698"
982
+ token['name'] = "SOY Finance"
983
+ token['symbol'] = "SOY"
984
+ when "a891c856974b2c71d7b99f2c056585d6"
985
+ token['name'] = "Bulls USD"
986
+ token['symbol'] = "BUSDT"
987
+ else
988
+ token['name'] = "Unknown"
989
+ token['symbol'] = "Unknown"
990
+ end
991
+ power = (10 ** 18).to_i
992
+ token['result'] = token['result'].to_i(16) / power.to_i.to_f
993
+ create_event payload: token
994
+ end
995
+ else
996
+ last_status = memory['get_tokens_balance']
997
+ payload.each do | token |
998
+ found = false
999
+ if interpolated['debug'] == 'true'
1000
+ log found
1001
+ end
1002
+ last_status.each do | tokenbis|
1003
+ if token == tokenbis
1004
+ found = true
1005
+ end
1006
+ if interpolated['debug'] == 'true'
1007
+ log found
1008
+ end
1009
+ end
1010
+ if found == false
1011
+ case token['id']
1012
+ when "65b0be964fde4eacba0c993a7bd4caaa"
1013
+ token['name'] = "Callisto Enterprise"
1014
+ token['symbol'] = "CLOE"
1015
+ when "1b3b1a0f2c708f8c71bf3d94246ec698"
1016
+ token['name'] = "SOY Finance"
1017
+ token['symbol'] = "SOY"
1018
+ else
1019
+ token['name'] = "Unknown"
1020
+ token['symbol'] = "Unknown"
1021
+ end
1022
+ power = (10 ** 18).to_i
1023
+ token['result'] = token['result'].to_i(16) / power.to_i.to_f
1024
+ create_event payload: token
1025
+ end
1026
+ end
1027
+ end
1028
+ memory['get_tokens_balance'] = fixed_payload
1029
+ end
1030
+ else
1031
+ if payload != memory['get_tokens_balance']
1032
+ memory['get_tokens_balance']= fixed_payload
1033
+ end
1034
+ power = (10 ** 18).to_i
1035
+ payload.each do | token |
1036
+ token['result'] = token['result'].to_i(16) / power.to_i.to_f
1037
+ create_event payload: token
1038
+ end
1039
+ end
1040
+ end
1041
+
1042
+ def stake_reward_clo()
1043
+
1044
+ uri = URI.parse("#{interpolated['rpc_server']}")
1045
+ request = Net::HTTP::Post.new(uri)
1046
+ request.content_type = "application/json"
1047
+ request.body = JSON.dump([
1048
+ {
1049
+ "id" => "baccb9edcfeaacc09f666621eac70e72",
1050
+ "jsonrpc" => "2.0",
1051
+ "method" => "eth_call",
1052
+ "params" => [
1053
+ {
1054
+ "to" => "0x08A7c8be47773546DC5E173d67B0c38AfFfa4b84",
1055
+ "data" => "0xbf92b4ef000000000000000000000000#{interpolated['wallet'][2..-1]}"
1056
+ },
1057
+ "latest"
1058
+ ]
1059
+ }
1060
+ ])
1061
+
1062
+ req_options = {
1063
+ use_ssl: uri.scheme == "https",
1064
+ }
1065
+
1066
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
1067
+ http.request(request)
1068
+ end
1069
+
1070
+ log_curl_output(response.code,response.body)
1071
+
1072
+ payload = JSON.parse(response.body)
1073
+
1074
+ if interpolated['changes_only'] == 'true'
1075
+ if payload.to_s != memory['stake_reward_clo']
1076
+ memory['stake_reward_clo'] = payload.to_s
1077
+ if payload[0].key?("result")
1078
+ power = (10 ** 18).to_i
1079
+ payload[0]['result'] = payload[0]['result'].to_i(16) / power.to_i.to_f
1080
+ payload[0]['name'] = "callisto"
1081
+ payload[0]['symbol'] = "CLO"
1082
+ end
1083
+ create_event payload: payload[0]
1084
+ end
1085
+ else
1086
+ if payload.to_s != memory['stake_reward_clo']
1087
+ memory['stake_reward_clo'] = payload.to_s
1088
+ end
1089
+ power = (10 ** 18).to_i
1090
+ payload[0]['result'] = payload[0]['result'].to_i(16) / power.to_i.to_f
1091
+ payload[0]['name'] = "callisto"
1092
+ payload[0]['symbol'] = "CLO"
1093
+ create_event payload: payload[0]
1094
+ end
1095
+ end
1096
+
1097
+ def eth_getTransactionCount()
1098
+
1099
+ uri = URI.parse("#{interpolated['rpc_server']}")
1100
+ request = Net::HTTP::Post.new(uri)
1101
+ request.content_type = "application/json"
1102
+ request.body = JSON.dump({
1103
+ "method" => "eth_getTransactionCount",
1104
+ "params" => [
1105
+ "#{interpolated['wallet']}",
1106
+ "latest"
1107
+ ],
1108
+ "id" => 1,
1109
+ "jsonrpc" => "2.0"
1110
+ })
1111
+
1112
+ req_options = {
1113
+ use_ssl: uri.scheme == "https",
1114
+ }
1115
+
1116
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
1117
+ http.request(request)
1118
+ end
1119
+
1120
+ log_curl_output(response.code,response.body)
1121
+
1122
+ payload = JSON.parse(response.body)
1123
+
1124
+ if interpolated['changes_only'] == 'true'
1125
+ if payload.to_s != memory['eth_getTransactionCount']
1126
+ memory['eth_getTransactionCount'] = payload.to_s
1127
+ payload['result'] = payload['result'].to_i(16)
1128
+ create_event payload: payload
1129
+ end
1130
+ else
1131
+ if payload.to_s != memory['eth_getTransactionCount']
1132
+ memory['eth_getTransactionCount'] = payload.to_s
1133
+ end
1134
+ payload['result'] = payload['result'].to_i(16)
1135
+ create_event payload: payload
1136
+ end
1137
+ end
1138
+
1139
+ def eth_gasPrice(internal=false)
1140
+
1141
+ uri = URI.parse("#{interpolated['rpc_server']}")
1142
+ request = Net::HTTP::Post.new(uri)
1143
+ request.content_type = "application/json"
1144
+ request.body = JSON.dump({
1145
+ "method" => "eth_gasPrice",
1146
+ "params" => [],
1147
+ "id" => 67,
1148
+ "jsonrpc" => "2.0"
1149
+ })
1150
+
1151
+ req_options = {
1152
+ use_ssl: uri.scheme == "https",
1153
+ }
1154
+
1155
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
1156
+ http.request(request)
1157
+ end
1158
+
1159
+ log_curl_output(response.code,response.body)
1160
+
1161
+ payload = JSON.parse(response.body)
1162
+
1163
+ if internal == false
1164
+ if interpolated['changes_only'] == 'true'
1165
+ if payload.to_s != memory['eth_gasPrice']
1166
+ memory['eth_gasPrice'] = payload.to_s
1167
+ payload['result'] = payload['result'].to_i(16)
1168
+ create_event payload: payload
1169
+ end
1170
+ else
1171
+ if payload.to_s != memory['eth_gasPrice']
1172
+ memory['eth_gasPrice'] = payload.to_s
1173
+ end
1174
+ payload['result'] = payload['result'].to_i(16)
1175
+ create_event payload: payload
1176
+ end
1177
+ else
1178
+ output = JSON.parse(response.body)
1179
+
1180
+ return output['result']
1181
+
1182
+ end
1183
+ end
1184
+
1185
+ def eth_protocolVersion()
1186
+
1187
+ uri = URI.parse("#{interpolated['rpc_server']}")
1188
+ request = Net::HTTP::Post.new(uri)
1189
+ request.content_type = "application/json"
1190
+ request.body = JSON.dump({
1191
+ "method" => "eth_protocolVersion",
1192
+ "params" => [],
1193
+ "id" => 67,
1194
+ "jsonrpc" => "2.0"
1195
+ })
1196
+
1197
+ req_options = {
1198
+ use_ssl: uri.scheme == "https",
1199
+ }
1200
+
1201
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
1202
+ http.request(request)
1203
+ end
1204
+
1205
+ log_curl_output(response.code,response.body)
1206
+
1207
+ payload = JSON.parse(response.body)
1208
+
1209
+ if interpolated['changes_only'] == 'true'
1210
+ if payload.to_s != memory['eth_protocolVersion']
1211
+ memory['eth_protocolVersion'] = payload.to_s
1212
+ payload['result'] = payload['result'].to_i(16)
1213
+ create_event payload: payload
1214
+ end
1215
+ else
1216
+ if payload.to_s != memory['eth_protocolVersion']
1217
+ memory['eth_protocolVersion'] = payload.to_s
1218
+ end
1219
+ payload['result'] = payload['result'].to_i(16)
1220
+ create_event payload: payload
1221
+ end
1222
+ end
1223
+
1224
+ def net_version()
1225
+
1226
+ uri = URI.parse("#{interpolated['rpc_server']}")
1227
+ request = Net::HTTP::Post.new(uri)
1228
+ request.content_type = "application/json"
1229
+ request.body = JSON.dump({
1230
+ "method" => "net_version",
1231
+ "params" => [],
1232
+ "id" => 67,
1233
+ "jsonrpc" => "2.0"
1234
+ })
1235
+
1236
+ req_options = {
1237
+ use_ssl: uri.scheme == "https",
1238
+ }
1239
+
1240
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
1241
+ http.request(request)
1242
+ end
1243
+
1244
+ log_curl_output(response.code,response.body)
1245
+
1246
+ payload = JSON.parse(response.body)
1247
+
1248
+ if interpolated['changes_only'] == 'true'
1249
+ if payload.to_s != memory['net_version']
1250
+ memory['net_version'] = payload.to_s
1251
+ payload['result'] = payload['result'].to_i(16)
1252
+ create_event payload: payload
1253
+ end
1254
+ else
1255
+ if payload.to_s != memory['net_version']
1256
+ memory['net_version'] = payload.to_s
1257
+ end
1258
+ payload['result'] = payload['result'].to_i(16)
1259
+ create_event payload: payload
1260
+ end
1261
+ end
1262
+
1263
+ def net_peerCount()
1264
+
1265
+ uri = URI.parse("#{interpolated['rpc_server']}")
1266
+ request = Net::HTTP::Post.new(uri)
1267
+ request.content_type = "application/json"
1268
+ request.body = JSON.dump({
1269
+ "method" => "net_peerCount",
1270
+ "params" => [],
1271
+ "id" => 74,
1272
+ "jsonrpc" => "2.0"
1273
+ })
1274
+
1275
+ req_options = {
1276
+ use_ssl: uri.scheme == "https",
1277
+ }
1278
+
1279
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
1280
+ http.request(request)
1281
+ end
1282
+
1283
+ log_curl_output(response.code,response.body)
1284
+
1285
+ payload = JSON.parse(response.body)
1286
+
1287
+ if interpolated['changes_only'] == 'true'
1288
+ if payload.to_s != memory['net_peerCount']
1289
+ memory['net_peerCount'] = payload.to_s
1290
+ payload['result'] = payload['result'].to_i(16)
1291
+ create_event payload: payload
1292
+ end
1293
+ else
1294
+ if payload.to_s != memory['net_peerCount']
1295
+ memory['net_peerCount'] = payload.to_s
1296
+ end
1297
+ payload['result'] = payload['result'].to_i(16)
1298
+ create_event payload: payload
1299
+ end
1300
+ end
1301
+
1302
+ def get_balance()
1303
+
1304
+ uri = URI.parse("#{interpolated['rpc_server']}")
1305
+ request = Net::HTTP::Post.new(uri)
1306
+ request.content_type = "application/json"
1307
+ request.body = JSON.dump({
1308
+ "method" => "eth_getBalance",
1309
+ "params" => [
1310
+ "#{interpolated['wallet']}",
1311
+ "latest"
1312
+ ],
1313
+ "id" => 1,
1314
+ "jsonrpc" => "2.0"
1315
+ })
1316
+
1317
+ req_options = {
1318
+ use_ssl: uri.scheme == "https",
1319
+ }
1320
+
1321
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
1322
+ http.request(request)
1323
+ end
1324
+
1325
+ log_curl_output(response.code,response.body)
1326
+
1327
+ payload = JSON.parse(response.body)
1328
+
1329
+ if interpolated['changes_only'] == 'true'
1330
+ if payload != memory['get_balance']
1331
+ memory['get_balance'] = payload
1332
+ power = (10 ** 18).to_i
1333
+ payload['name'] = "callisto"
1334
+ payload['symbol'] = "CLO"
1335
+ payload['result'] = payload['result'].to_i(16) / power.to_i.to_f
1336
+ create_event payload: payload
1337
+ end
1338
+ else
1339
+ if payload.to_s != memory['get_balance']
1340
+ memory['get_balance'] = payload
1341
+ end
1342
+ power = (10 ** 18).to_i
1343
+ payload['result'] = payload['result'].to_i(16) / power.to_i.to_f
1344
+ create_event payload: payload
1345
+ end
1346
+ end
1347
+
1348
+ def trigger_action
1349
+
1350
+ case interpolated['type']
1351
+ when "get_balance"
1352
+ get_balance()
1353
+ when "net_peerCount"
1354
+ net_peerCount()
1355
+ when "net_version"
1356
+ net_version()
1357
+ when "eth_protocolVersion"
1358
+ eth_protocolVersion()
1359
+ when "eth_gasPrice"
1360
+ eth_gasPrice()
1361
+ when "eth_getTransactionCount"
1362
+ eth_getTransactionCount()
1363
+ when "stake_reward_clo"
1364
+ stake_reward_clo()
1365
+ when "get_tokens_balance"
1366
+ get_tokens_balance()
1367
+ when "eth_getBlockByNumber"
1368
+ eth_getBlockByNumber()
1369
+ when "soy_farming_soy_clo_pending_rewards"
1370
+ soy_farming_soy_clo_pending_rewards()
1371
+ when "soy_farming_soy_cloe_pending_rewards"
1372
+ soy_farming_soy_cloe_pending_rewards()
1373
+ when "stake_reward_soy"
1374
+ stake_reward_soy()
1375
+ when "soy_farming_soy_btt_pending_rewards"
1376
+ soy_farming_soy_btt_pending_rewards()
1377
+ when "soy_cs_pending_rewards"
1378
+ soy_cs_pending_rewards()
1379
+ when "clo_sendtx"
1380
+ clo_sendtx()
1381
+ when "start_cs_clo"
1382
+ start_cs_clo()
1383
+ when "withdraw_cs_clo"
1384
+ withdraw_cs_clo()
1385
+ when "get_tx_by_address_with_filter"
1386
+ get_tx_by_address_with_filter()
1387
+ else
1388
+ log "Error: type has an invalid value (#{type})"
1389
+ end
1390
+ end
1391
+ end
1392
+ end