2021-05-13 18:21:35 +03:00
|
|
|
:: aggregator/send: send rollup tx
|
|
|
|
::
|
2021-05-21 16:07:08 +03:00
|
|
|
/- rpc=json-rpc, *aggregator
|
2021-05-13 18:21:35 +03:00
|
|
|
/+ naive, ethereum, ethio, strandio
|
|
|
|
::
|
|
|
|
=/ gas-limit=@ud 30.000 ::TODO verify, maybe scale with roll size
|
2021-05-21 13:16:57 +03:00
|
|
|
=/ batch-function=octs
|
|
|
|
%- as-octs:mimes:html
|
|
|
|
%+ rsh [3 28]
|
|
|
|
(keccak-256:keccak:crypto (as-octs:mimes:html 'batch(bytes)'))
|
2021-05-13 18:21:35 +03:00
|
|
|
::
|
|
|
|
|= args=vase
|
2021-05-21 16:07:08 +03:00
|
|
|
=+ !<(rpc-send-roll args)
|
2021-05-13 18:21:35 +03:00
|
|
|
=/ m (strand:strandio ,vase)
|
|
|
|
|^
|
|
|
|
^- form:m
|
2021-05-21 13:16:57 +03:00
|
|
|
=* not-sent (pure:m !>(%.y^next-gas-price))
|
2021-05-13 18:21:35 +03:00
|
|
|
::
|
2021-05-21 13:16:57 +03:00
|
|
|
=/ =address:ethereum (address-from-prv:key:ethereum pk)
|
2021-05-13 18:21:35 +03:00
|
|
|
;< expected-nonce=@ud bind:m
|
|
|
|
(get-next-nonce:ethio endpoint address)
|
|
|
|
:: if chain expects a different nonce, don't send this transaction
|
|
|
|
::
|
|
|
|
?. =(nonce expected-nonce)
|
|
|
|
not-sent
|
|
|
|
:: if a gas-price of 0 was specified, fetch the recommended one
|
|
|
|
::
|
|
|
|
;< use-gas-price=@ud bind:m
|
|
|
|
?: =(0 next-gas-price) fetch-gas-price
|
|
|
|
(pure:(strand:strandio @ud) next-gas-price)
|
|
|
|
:: if we cannot pay for the transaction, don't bother sending it out
|
|
|
|
::
|
|
|
|
=/ max-cost=@ud (mul gas-limit use-gas-price)
|
2021-05-29 15:22:33 +03:00
|
|
|
;< balance=@ud bind:m
|
|
|
|
(get-balance:ethio endpoint address)
|
|
|
|
?: (gth max-cost balance)
|
|
|
|
~& [%insufficient-aggregator-balance address]
|
|
|
|
not-sent
|
2021-05-13 18:21:35 +03:00
|
|
|
::
|
2021-05-21 13:16:57 +03:00
|
|
|
=/ tx-data=@ux
|
|
|
|
%+ can:naive 3
|
|
|
|
:_ [batch-function ~]
|
|
|
|
=; =cord
|
|
|
|
=/ parsed=(unit (pair @ud @ux))
|
|
|
|
(de:base16:mimes:html cord)
|
|
|
|
?~(parsed !! u.parsed)
|
|
|
|
%- crip
|
|
|
|
%- encode-args:abi:ethereum
|
|
|
|
:_ ~
|
|
|
|
:- %bytes
|
|
|
|
%+ cad:naive 3
|
|
|
|
%+ roll txs
|
|
|
|
|= [=raw-tx:naive out=(list octs)]
|
|
|
|
[raw.raw-tx 65^sig.raw-tx out]
|
2021-05-13 18:21:35 +03:00
|
|
|
=/ tx=@ux
|
|
|
|
=; tx=transaction:rpc:ethereum
|
|
|
|
(sign-transaction:key:ethereum tx pk)
|
|
|
|
:* nonce
|
|
|
|
use-gas-price
|
|
|
|
gas-limit
|
|
|
|
contract
|
|
|
|
0
|
2021-05-21 13:16:57 +03:00
|
|
|
tx-data
|
2021-05-13 18:21:35 +03:00
|
|
|
chain-id
|
|
|
|
==
|
|
|
|
::
|
|
|
|
::NOTE this fails the thread if sending fails, which in the app gives us
|
|
|
|
:: the "retry with same gas price" behavior we want
|
2021-05-22 09:10:30 +03:00
|
|
|
;< =response:rpc bind:m (send-batch endpoint tx)
|
|
|
|
%- pure:m
|
|
|
|
!> ^- (each @ud @t)
|
|
|
|
?+ -.response %.n^'unexpected rpc response'
|
|
|
|
%error %.n^message.res
|
|
|
|
:: TODO:
|
|
|
|
:: check that tx-hash in +.response is non-zero?
|
|
|
|
:: log tx-hash to getTransactionReceipt(tx-hash)?
|
|
|
|
:: enforce max here, or in app?
|
|
|
|
:: add five gwei to gas price of next attempt
|
|
|
|
::
|
|
|
|
%result %.y^(add use-gas-price 5.000.000.000)
|
|
|
|
==
|
2021-05-13 18:21:35 +03:00
|
|
|
::
|
|
|
|
::TODO should be distilled further, partially added to strandio?
|
|
|
|
++ fetch-gas-price
|
|
|
|
=/ m (strand:strandio @ud) ::NOTE return in wei
|
|
|
|
^- form:m
|
|
|
|
=/ =request:http
|
|
|
|
:* method=%'GET'
|
|
|
|
url='https://api.etherscan.io/api?module=gastracker&action=gasoracle'
|
|
|
|
header-list=~
|
|
|
|
~
|
|
|
|
==
|
|
|
|
;< ~ bind:m
|
|
|
|
(send-request:strandio request)
|
|
|
|
;< rep=(unit client-response:iris) bind:m
|
|
|
|
take-maybe-response:strandio
|
|
|
|
=* fallback
|
|
|
|
~& %fallback-gas-price
|
|
|
|
(pure:m 40.000.000.000) ::TODO maybe even lower, considering we increment?
|
|
|
|
?. ?& ?=([~ %finished *] rep)
|
|
|
|
?=(^ full-file.u.rep)
|
|
|
|
==
|
|
|
|
fallback
|
|
|
|
?~ jon=(de-json:html q.data.u.full-file.u.rep)
|
|
|
|
fallback
|
|
|
|
=; res=(unit @ud)
|
|
|
|
?~ res fallback
|
|
|
|
%- pure:m
|
|
|
|
(mul 1.000.000.000 u.res) ::NOTE gwei to wei
|
|
|
|
%. u.jon
|
|
|
|
=, dejs-soft:format
|
2021-05-21 13:16:57 +03:00
|
|
|
(ot 'result'^(ot 'FastGasPrice'^ni ~) ~)
|
2021-05-22 09:10:30 +03:00
|
|
|
::
|
|
|
|
++ send-batch
|
|
|
|
|= [endpoint=@ta batch=@ux]
|
|
|
|
=/ m (strand:strandio ,response:rpc)
|
|
|
|
^- form:m
|
|
|
|
=/ req=[(unit @t) request:rpc:ethereum]
|
|
|
|
[`'sendRawTransaction' %eth-send-raw-transaction batch]
|
|
|
|
;< res=(list response:rpc) bind:m
|
|
|
|
(request-batch-rpc-loose:ethio endpoint [req]~)
|
|
|
|
?: ?=([* ~] res)
|
|
|
|
(pure:m i.res)
|
|
|
|
%+ strand-fail:strandio
|
|
|
|
%unexpected-multiple-results
|
|
|
|
[>(lent res)< ~]
|
|
|
|
::
|
2021-05-13 18:21:35 +03:00
|
|
|
--
|