From b2a7450a58b6a2e025e01664e812085853073e8c Mon Sep 17 00:00:00 2001 From: dmelotik Date: Thu, 22 Dec 2022 15:11:44 -0700 Subject: [PATCH 01/25] create token standard proto --- common/README.md | 65 +++++++++++++++++++++++ common/proto/{erc20.proto => token.proto} | 21 ++++---- eth-balance/proto/v1/eth_balance.proto | 12 ----- eth-balance/substreams.yaml | 26 ++++++--- 4 files changed, 96 insertions(+), 28 deletions(-) create mode 100644 common/README.md rename common/proto/{erc20.proto => token.proto} (60%) delete mode 100644 eth-balance/proto/v1/eth_balance.proto diff --git a/common/README.md b/common/README.md new file mode 100644 index 00000000..7f424201 --- /dev/null +++ b/common/README.md @@ -0,0 +1,65 @@ +# Common Definitions + +This folder contains common definitions for protobufs used more than once. We intentionally have this in order to standardize the way we define the data to make it easier for the end user to "plug-n-play". + +## Common Proto + +TODO + +## DEX AMM Proto + +TODO + +## Token Proto + +The token proto is designed to store the token balances of all accounts throughout the blockchains history. It is designed to be network-agnostic and support all tokens. Token's can be blockchain native, erc20s, or any other derivative. + +### Definitions + +The first part are the token definitions. This is simple, and defines the tokens that are supported in the substream implementation. + +> Note: if the token is a native token (e.g. ethereum), then the address is the `0x0` address and the other values need to be hardcoded. +```protobuf +message Tokens { + repeated Token items = 1; +} + +message Token { + string address = 1; + string name = 2; + string symbol = 3; + uint64 decimals = 4; +} +``` + +The transfers track where the tokens move to/from. In most cases we can fill in every field. A `log_index` or `log_ordinal` may not always be possible. In addition a mint or burn will have either the `to` or `from` address as the `0x0` address. + +```protobuf +message Transfers { + repeated Transfer items = 1; +} + +message Transfer { + string tx_hash = 1; + optional uint32 log_index = 2; + optional uint64 log_ordinal = 3; + Token token = 4; + string from = 5; + string to = 6; + string amount = 7; // BigInt, in token's native amount + optional string reason = 8; +} +``` + +`TokenBalance` is simple, and defines the balance of a given token in an account. +```protobuf +message TokenBalance { + string token_address = 1; + string balance = 2; // BigInt, in token's native amount +} + +message Account { + string address = 1; + repeated TokenBalance balances = 2; +} +``` diff --git a/common/proto/erc20.proto b/common/proto/token.proto similarity index 60% rename from common/proto/erc20.proto rename to common/proto/token.proto index 2c0b99cf..decb4034 100644 --- a/common/proto/erc20.proto +++ b/common/proto/token.proto @@ -1,30 +1,31 @@ syntax = "proto3"; -package messari.erc20.v1; +package messari.token.v1; -message ERC20Tokens { - repeated ERC20Token items = 1; +message Tokens { + repeated Token items = 1; } -message ERC20Token { +message Token { string address = 1; string name = 2; string symbol = 3; uint64 decimals = 4; } -message TransferEvents { - repeated TransferEvent items = 1; +message Transfers { + repeated Transfer items = 1; } -message TransferEvent { +message Transfer { string tx_hash = 1; - uint32 log_index = 2; - uint64 log_ordinal = 3; - string token_address = 4; + optional uint32 log_index = 2; + optional uint64 log_ordinal = 3; + Token token = 4; string from = 5; string to = 6; string amount = 7; // BigInt, in token's native amount + optional string reason = 8; } message TokenBalance { diff --git a/eth-balance/proto/v1/eth_balance.proto b/eth-balance/proto/v1/eth_balance.proto deleted file mode 100644 index eac68922..00000000 --- a/eth-balance/proto/v1/eth_balance.proto +++ /dev/null @@ -1,12 +0,0 @@ -syntax = "proto3"; - -package messari.eth_balance.v1; - -message EthBalance { - string address = 1; - string value = 2; -} - -message EthBalances { - repeated EthBalance items = 1; -} \ No newline at end of file diff --git a/eth-balance/substreams.yaml b/eth-balance/substreams.yaml index 2291509f..d3cf94ca 100644 --- a/eth-balance/substreams.yaml +++ b/eth-balance/substreams.yaml @@ -8,9 +8,9 @@ imports: protobuf: files: - - eth_balance.proto + - token.proto importPaths: - - proto/v1 + - ../common/proto/token.proto binaries: default: @@ -18,9 +18,23 @@ binaries: file: "../target/wasm32-unknown-unknown/release/eth_balance.wasm" modules: - - name: store_balance - kind: store - updatePolicy: set - valueType: string + - name: map_account_balances + kind: map + inputs: + - source: sf.ethereum.type.v2.Block + output: + type: proto:messari.token.v1.Account + + - name: map_transfers + kind: map inputs: - source: sf.ethereum.type.v2.Block + output: + type: proto:messari.token.v1.Transfers + + - name: store_transfers + kind: store + updatePolicy: add + valueType: int64 + inputs: + - map: map_transfers From 1767168c28ee1c87f421768e012cc1024eb6c09d Mon Sep 17 00:00:00 2001 From: dmelotik Date: Thu, 29 Dec 2022 22:08:26 -0600 Subject: [PATCH 02/25] eth-balance standard token mapping --- Cargo.toml | 5 +- README.md | 10 +- common/README.md | 4 + common/proto/dex_amm.proto | 2 +- common/proto/token.proto | 10 +- docs/images/logos/messari-logo.png | Bin 0 -> 11611 bytes eth-balance/Makefile | 2 +- eth-balance/src/lib.rs | 44 +++-- eth-balance/src/pb.rs | 8 +- eth-balance/src/pb/messari.token.v1.rs | 217 +++++++++++++++++++++++++ eth-balance/substreams.yaml | 21 +-- 11 files changed, 285 insertions(+), 38 deletions(-) create mode 100644 docs/images/logos/messari-logo.png create mode 100644 eth-balance/src/pb/messari.token.v1.rs diff --git a/Cargo.toml b/Cargo.toml index 5a1bd6a3..72d7bb2d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,8 +20,9 @@ substreams = "0.3.2" substreams-ethereum = "0.6.2" substreams-solana = "0.1.0" -[build] -target = "wasm32-unknown-unknown" +# TODO: I get a warning when this is uncommented +#[build] +#target = "wasm32-unknown-unknown" [profile.release] lto = true diff --git a/README.md b/README.md index 8704de8e..263261ab 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,12 @@ -# Messari Substreams +# Messari Substreams • [![GitHub license](https://img.shields.io/badge/license-MIT-blue)](https://github.com/messari/substreams/blob/master/LICENSE) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/messari/substreams/compare) [![Issues Report](https://img.shields.io/badge/issues-report-yellow.svg)](https://github.com/messari/substreams/issues/new) + +

+ Messari Logo +

+ +Messari substreams aim to contextualize on chain data using [streamingfast](https://www.streamingfast.io/)'s [substreams](https://substreams.streamingfast.io/) 🚀 + +> Learn more about messari substream development in our [`./docs`](./docs) ## Pre-requisites diff --git a/common/README.md b/common/README.md index 7f424201..7ddd178e 100644 --- a/common/README.md +++ b/common/README.md @@ -63,3 +63,7 @@ message Account { repeated TokenBalance balances = 2; } ``` + +### How to Use + +TODO diff --git a/common/proto/dex_amm.proto b/common/proto/dex_amm.proto index 69f84c0a..0f56dae9 100644 --- a/common/proto/dex_amm.proto +++ b/common/proto/dex_amm.proto @@ -1,7 +1,7 @@ syntax = "proto3"; import "common.proto"; -import "erc20.proto"; +import "token.proto"; package messari.dex_amm.v1; diff --git a/common/proto/token.proto b/common/proto/token.proto index decb4034..dede3ac7 100644 --- a/common/proto/token.proto +++ b/common/proto/token.proto @@ -25,11 +25,12 @@ message Transfer { string from = 5; string to = 6; string amount = 7; // BigInt, in token's native amount - optional string reason = 8; + optional string amount_usd = 8; + optional string reason = 9; } message TokenBalance { - string token_address = 1; + Token token = 1; string balance = 2; // BigInt, in token's native amount } @@ -37,3 +38,8 @@ message Account { string address = 1; repeated TokenBalance balances = 2; } + +// TODO: do we need this? +message Accounts { + repeated Account items = 1; +} \ No newline at end of file diff --git a/docs/images/logos/messari-logo.png b/docs/images/logos/messari-logo.png new file mode 100644 index 0000000000000000000000000000000000000000..0ffc2e3ffae6d9e88b233f5b83252edaf2c8ef83 GIT binary patch literal 11611 zcmeHtWmJ^k+V{{XEifRhD2OyjHwXxVfJirp(k0!fgv209Nh30Vzz|ZBBMgp$bV>_S z(mnLM$MgL4>silxKArWrmfr5U_V4O_-PhjtexZF&mFyzJMF<2!rgrD{eFy~K00P0q zCnf~HOeB8F0*?!BcZ{AuAaqpNzc?KnJ8}>R8$|84!UNxowMi{~Ce`}QAHOzyVF3h% z2BH4?!UBwxO}Ia3qgY0ecF58Gi?RBa_IS3pY#voSP1biSrCpM`(qfxJ`Sg8s)VD9+ z79}F*r0RI1uYT<~u{}9N7ieWa0#YHX3+H~**#CHQBCwB#lt42GL@0_I`?!pv1^vQnb0EGAW&>L97FDyaBGEAfOA_Q6wGU&FfNIcrXfyf%L{JECTAFd z=(Q3EG6hV>q$6=DDD@#TjzF70HOnwp?7#&((6kIQ!NNs>+3OtT@>oJJmXMBY{docK z5x^2S%LR;pI42cToY2S%JQ}caTu3^#0mM=mm*n*oAjKO<8O=bpE&)in41mnCF%fK-U9wp{ixB z4-hd3LN9NIOVUK856NK!=t0i%UI~D%X9ol^e5fQlU|S0iOE9FO7eIJw0eLPLcphL0 za#%tZQqdg{c2xl(n3#tKOK8Co;*pA?fYlLJMhiaFn*$ISv4m`7>+o}0h+QPm%9+w| zG!=NknF^@Oj7vgs31}h%G^tXy{E?2Gg^l4Fl_4e?%v!qyW@+M*gkbe`#?HEHsQ_%k z!5Zs~+xZ;0N&uU)Ra%yB*nsc|C7_iRr6C7Ml29uk!%`eS`2vWir7zHg9vWtg0y5}1 zfZHQfEiYfeLa-jSx@4&G8-fi^9ey$u7J|V-M8j;6SO^go!cUM)7aZRvWWmFVl}rvK z$F|wDpg;LxvrPOyyOjQyEAZckS=xX#Y6n&&Y>zpeKRJFeX5I*op8!Hn32Yr59uOo< zrqO@&;ro!2=y7vc3LbK=K-;eg~C)2e#1R0kx|X{s<-mYWK?h0oPy^ zY54;l#jdVXfczgY5diQ0)tVU#miYt5wims;e}`Bq^Pk~GY#nF(;~<)=KvK}(;WaQc z`#S{glb883e1KJp`R@>m_4_--VvYU|u~-m>|A~aBJn){-ACs1_b?xx)@Ff`f{T-%) zVFUF)2IpW6URC+ytt?<+`Co(mfncQfU+^0MPX7zW0br-UU=;w~6!_y024Dp8^bgoB z7J#QY{)wvmGf?E}(*H>>NE~=O&N%)t>K3RUq5OYRqE{TG#MvJ(65A(ja{duT2>L9D zRsOYqB?#ed&|LlcBbc7vogkF!kJgraN4|hn6XWtW}!vIg0X2YyO%uLgK zKY>jUXpwL6ZGUgwYjoQ>>r|(UTtUo6gxB9UmDpu*)ikw#fS)vgc~7P5A{AR!@IkKS91VI# z$!@E%GJe=OJ;tPi{Ayu_%EZdH_zBo$2OCNeS{yT1h7YK_4*Ru-q>D0nxw{TkA6ma@ zoLfcMFnJyG@(7SkM{=|MgSL9{^>uGL#-9l1Cku{SNVS+t zwDhNNp^}nAEIs1#wL);s{NvC0vi`CBVQ9ukGHcw0*1V3mma>H-dJ9@X;7?1!Yc5i*ZAVrdQ#Qia zJO*Wt3uat?JZnYzI7G15k=EO%|A*k|pdajl`r?RBg)H3zk^H(!xhg6)cO~KEf+t8w zJK0(pbyTC4X<#)-dh^c=ayAD%u(sDl=iQv|R;smQ&8?#QMZWcHu_+_rXm}lnPg!DDU+`4tSW=3X#mlY>og25OszYOWokR}q-eybKSLUzd@wQ`rO{jv0r z1~1|pVb#jL;&F9cYJpGXmFvArVWOy~>$(@YSM>9WSZa4(-6)Cgt#B1|Ba6J9trHMi#0wGOVe z6GOwo-va2XVY*nxjwJ@mhqDuyF~zYEKj^^yrI*Nqq-=uZzGY!Iruw4iJtGoui~EBQ z<~qzNNTQstWeqadV8%k#>TX@%;&$0?@Zs7F`jJP(pEq!@L{&k4);RTXTUNUR%;(8c z5!GAcwI{|Ct=04{Ium}Y%=gqm9US+EhIyL$7yycC*T1^o; z>1ShtRl-?LnC#`;t?L6}lEXXeT%|(Hc7eu{BkKXi6d~W^?TgBV-RFBaA2yMP$M*>@ zq~J9PILvdy@%Gw?v-}X^s~W1#QxWP^@a09*!^id7F_F#K(y2bQb*}+PKO1%VBV;n3#@Y>I)*K zcgv-kPY;#zx(>r7lexVHwqwk%kNSq(G14-FqoSs!7EBh(v4=cwr|p?y@|8L}F~PBS zOn0g!Pq)8yT|2nLzFc#(I@Na&$MgE-`UNeG&WCif9Vz|N4V}*XXTpZ4?b%GEt~;#gh$K=u#t)rHH@=uF@9-?!-7vRc%Kkh!yZC0MDwX_} zBGuF5dbNo}FAh7!4BY|ZHX89WqnXC~m|1l#|b0e4jW z(Ou3L=g(mYIJHfJ%!L<*;8&~4OTA0TJTGaPZlqQ2PwY?UiB=`Jt8DjGiCcJAa75dC zIBA-Gv{>dWdkiWq!~L}jws*y1D#WMeOmxFFh!|Qj2w*WWoQQbWIC%ZC2OW7mtz#;a zJ_f!#8f>y0DJT-P(0;g^n^5#|UtP}b@d+yFnEA6?x6>B-P&ZGGQ$X{z|4r(=2e9Fq zc@Z+3iL`*!3ehwNk!a-^##-atS>^Vkl;dhK?@+~VsZ^G0h;mx@d8>SA?V8sqPAFe> z{R+x~<}Pc@TI-m*ZxYm8l-aIvc5KT&pH+Z&BFJd#^ZngCzpc=B`;R}?wd$jiBG={- zGputyRSF=KprtB28!XyYB&&1>z2)iE_z$wU1==7Wzn~}9< zv=hrRn0Co?_BpXHxT!!Ik{&)*3jWAUN_axIEk8y)R0}A=ojWlRHB0WtbF^xSx^8fK zszmS$wT#6ha!;??{;1MoWyjNsjp3jtH&Xrv&>|iuwS{d zUHWeH;0aS?*+5*y+)IsWIKH!xQ2v6F*np({8;q*3iUjY{(JZF%nZ59I{pCWLw?7X- z84OPky?<0+VJ2bN@F|Fu-T2#9c2;w3zXpYJ@JHGcX);?I_o?^Q!&A>jl9T9a_O#=Z zne_vm*FTPS_^<~z^b>t@r9D3#nym@x8i)1q9MiTeYCdNVy^mlR6AG3y@B9EP7BnAU z*`21}@Ahp%1co)n>22Q4USXXTKMCZS`jB&D@FL{_@56v`+x#6rhKe8$@VcyTZ6T9d zu{`Bj46G3vt9uo3xreSZCCQZ`t3=kxn&$4B)$0h`%7iM*IplOvr|(5oTlcdgL%+;I zv(X1Puf*pa(pFSx*OrNV}yA->$PEYlBsyt z0Zq$pFxru-iuh)Y&U)REr)G|db6Qh&ve*~r&-`IOe_<2Bv@-dAuj<3Q1{V(tRXg`B zVK@7S{UDA~p-)B>0`vRyKBRV6Ns`AQ(h$ZJE$e1q_G>yqR3n!a-p*y{qn@o9>j)n% zDUgpd?CF2oBGL)SS_&p=dn4yrUM(zOCQ`dqa(!~<>{fbLaD25fpL3a%uhL0|RHIE7 zn`5{jP&WgKsZ-ScTc(QOJg(c0jj75dOvNJ4f-OjRy;&JPM%9a`+zFYmWw-~@Ov|ZLgT#7#XRP5v zG`ExUuKV>2{ga%cwWMWvd9bDfvrKD!RtOKibs=+N=f7gk#=PeY+}V-hLur>1Kh!)Z ztE^)^>h>qlJ@!aJ5cy8_ZI*OZFlj8l4JWw_GP)kV_WQSAnT#Uu`N-9*h_*gg^ znZCz+(XZg=>*y_7Py3=I@`sn^GvuuuDD!A?>tmL-KKZ+>THjze~;nC66c1eW|<>bD?J;*A@;%7cS9tB?x1$AA8 znIBZFw!4}vx?tZXMDk3c5;Z2Tf=k+?me08)1#;R%I;WVnBbx!|4)5})dUn@NyAX5R zIh|mAOy5mzBX)FZ%?5mbpulRQqB3BOIoKlu*t>h(>;bB4N)JtU%WOQRTHwB=g!`29 zU8YDmRNO*pd|Q=huPfkFD)MAqoGI3rV#Nbm*|a9)qTwiBeb(`iNsq-g1zKnpcg^|7 zS;;=MCwBDbtoj{R;thr-!vMzdC7fLj7bjL_O9}cz*I5CT3MN0}q2wy$+HJ*Y9u?jE z^i*B6)%a{`NyX`Q$!1(;o#KVaIJrc=aZ^x-X=?v-88pgn3Q=W|wPmj-*` zfkGIoimaYp4^1w|P(2R!$Cqo)BC2I|!M3E`-&k^<7sZ>Z(b+GOX;ApPY)M+)m|fWS z#7&s5UQ-!Qf;PkzDaytAUh8zg?>t~UIlpfdYsc8CSW`O`%gqVXB3w^WcH*+#cE7%B zH0gSE6GGZy{P6H`Nw|*VlAp!?&FMsK`P<2_qk{NV>o_{Y%#6|mqr#nBiyO<=vX*H` zM>S2+@>H|xrm1^%uuwTW%U( zzF~v2AQ<<^?~%WDi#3f&>6%@G;gg<0HcY?fY7}vM6nBW!#*d0VP$VfGeQNk)8-s$Mcsn}gUa<}U{4jz)EcwmIBa3tgFCVA0ehfMl65l>LJgBIz| z3wFUqmNR5!$t2kA6M3wW>9>$(`>2BTf~~|QOG`QLdUtUV&H&%p)La9h;>DEg!_mwT5BsSC}FTTr2~0 zcBH)okTZcPoXf5qFz#FHwyXZcdQsdKQY$mo=lPskgP!2kL*Xh=8XdE-*M}cJ;^LNl z>!@;IDG3etfT=P?^6L*c&x)J2CmTCD{`8jwr#;dc%NYru(2yL}KbL~nlYrrZw^vwan>(FwByDPQT%}6OKOh;~`XHio<129Itbwkz7VGg7gpaq0 zL=+X7h6cmXrE%$k(SwaFpHG(#B`>+x4i!b0R(i<<-5nv8gYQ(AD~_O&T%!u~uSbdo z?}p)(HxTm{GfuGDw4Wnn_PH}^hw!m}+g zXVQ0iDUHC<{%PHI`K5tpQ%5#LH~7g8H7r@bmVmvQ9Cv|)bh ztgo7rN;y|-wu4ZpfGATn2Pfw(y-aU=9B-g52y&BB8?9pm)4kK6FAp6kgM6(tZyr75 zUg*lFcrjgjGTj&_fG1DXALlIn(ZlApYkzC!PJ87-P1o>Q(Ovp4DNu7+LEd1REc8+@ zNYiaEq6XJeIFW>EKMA{mXredKsMWoeTzg~=+3tmxg)%~TlR+qVarp}UFJA|zBNa`F zJ|Iw%$?12b^e?>IRW$vs_+VVqC*Rjal2YKIyV5Z@Q*37JpM9Q{2)i2#ISc{^HRMhS z-+ag#32Po-8TZIaefvp$HEm4KP0DArj|jA~=@~RG>ZI9tOLr$w&9L;?XW+;$I46&Y zzFd4kUrJs&v+I!oUcDvMAmS_aMrC96$#s_C#^o92iU7(cN`o4jfoCknh1~*oESJou zjrpzlRVeDT;ncOb(;W)2aEIVA73us^<+`GrZAl5;`Lxt=4GQZjRMO--9WK`9t(HI* z974;N{kt&%(C4QTyy{}*%a=(9){wQYtUJqqdz3rTR`XP%B5hrX7jWj+zO$rwQDrqS z{BZTB%)Dga?beg=i2_=V7s12#G+TC)UHXN+q9%;RO;;+A0>3%wv0!xmkl7W}UWz*z zVh$S*h4fS?Hp53X_ne6~qL&ps)lI*H53gH8%mdHvaZ}(C7IF;NVr<(&LPY#$yq;-= zJ4`t-zA^kB5$1Y5&grnUPlrcjE^n?}8Yd^~Sp@ryQ$d-iJ}QIljIvA`a}_rn`V8W0 z4H<1&sHL!-2p1PeaYvH_ zdqi3y)5jz);x~H{3F<9zFpq;H zwzqkQHh**xo-r(Z5h{r)fl z0Vm3zEbaykgQiX%_*!XceX-27BBse#=;)!Bjf@4)j^XZN6j%hY)u<=qT2gqGDXxNMr@|Ih#}-iC1ZnL67`DIpd=xYOn+%ixU+NT zH<@~442DgmLtb$9BJwtBAZJYKO>AEb4#kEm3|T9jSI|-Ua_!Us_G&DqI(mkiiX+=+ zxBFzU9TuU1y_Pk-->1n-<{J>??xe1LrGm}9blD=0ei=%_8B&PhjisMSx32h}4x75N zs2>gP&2U_G=?;#K2@!qrXi(h#(a*j#$-}yog5Y2YuloW`b)og>AXhN}e`@>h7GhK1B>e$!p9!PRF<4cAsit3IosRX+RvG z_LuL0mMV`t`yyGF+JvFD&O{XWaFKLy$eoRsZExRh^u=3BrL0#B%qIo&TW5=UTQsSU zTI1nXo}7x)MfQpo5)1=3qM#@S)@twf4D-LGa3kFK0pb!s%nrjZG-VtGP+7J2&aj{~ zC-OQ5C?jT7t@5MO#I|jWL3=euGJcU~q7&GGy~+qG7LQ7Wh8Hi?D*v%NQx@t*G8YW4 zp2vDNC(gq^yzgtgWfJSx>8<#3DC)#d4@X@{bQtpo} zd>0qj*$90@du>vJkXvC~j`mff?7Cs^D^ESL#uo3e6O5w#A}NCTY*xHS!9@pTrgik^ zUkl!`3G?8PVarCW%Go5na=&a;&rSnvb!2pwt`hT|wlK?Zz^0{NjD8-p$6n>-YcCj$ zSS~GoMZgo*VuGE(jk+20;xAZ@Pw&7<@^x^}VQwh-cSRQ}ihFPFlbwod@@; zvn5Sb(|}>;(`akn__pY2YjyXM{lOdrl*bmMLGc!Q4aelJ7Hn9B>SPo{wq9Ia=rM#` z$$e>v5nbck?GYz8nOy#5!xVY0US=?{@}P^#AYMb0- zu6xVs=5a zrwg&fUcAG8nuk_lZwCK+cY*&G-<**MaNqEps4S~w0%@LG2sl90l<(a}C|W-Ke Result { + let mut accounts = vec![]; -#[substreams::handlers::store] -fn store_balance(block: pbeth::v2::Block, output: store::StoreSetRaw) { for transaction in &block.transaction_traces { for call in &transaction.calls { for balance_change in &call.balance_changes { @@ -21,13 +24,34 @@ fn store_balance(block: pbeth::v2::Block, output: store::StoreSetRaw) { .into() }) .unwrap_or(BigInt::zero()); - - output.set( - transaction.end_ordinal, - format!("Address:{}", Hex(&balance_change.address).to_string()), - &new_value.to_string(), - ) + let new_token_balance = vec![token::TokenBalance { + token: Some(get_eth_token()), + balance: new_value.to_string() + }]; + let account = token::Account { + address: Hex(&balance_change.address).to_string(), + balances: new_token_balance + }; + accounts.push(account); } } } + + Ok(token::Accounts {items: accounts}) +} + +////////////////////////// +//// Helper Functions //// +////////////////////////// + +fn get_eth_token() -> token::Token { + let eth_token = Token { + address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE".to_string(), // TODO: do we need to append "address: "? + name: "Ethereum".to_string(), + symbol: "ETH".to_string(), + decimals: 18 as u64 + }; + // let tokens = vec![eth_token.clone()]; // TODO: does this set the Tokens protbuf definition + + eth_token } diff --git a/eth-balance/src/pb.rs b/eth-balance/src/pb.rs index 21c620eb..c2b8777a 100644 --- a/eth-balance/src/pb.rs +++ b/eth-balance/src/pb.rs @@ -1,9 +1,9 @@ #[rustfmt::skip] -#[path = "../target/pb/messari.eth_balance.v1.rs"] -pub(in crate::pb) mod eth_balance_v1; +#[path = "../target/pb/messari.token.v1.rs"] +pub(in crate::pb) mod token_v1; -pub mod eth_balance { +pub mod token { pub mod v1 { - pub use super::super::eth_balance_v1::*; + pub use super::super::token_v1::*; } } diff --git a/eth-balance/src/pb/messari.token.v1.rs b/eth-balance/src/pb/messari.token.v1.rs new file mode 100644 index 00000000..313a1eda --- /dev/null +++ b/eth-balance/src/pb/messari.token.v1.rs @@ -0,0 +1,217 @@ +// @generated +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Tokens { + #[prost(message, repeated, tag="1")] + pub items: ::prost::alloc::vec::Vec, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Token { + #[prost(string, tag="1")] + pub address: ::prost::alloc::string::String, + #[prost(string, tag="2")] + pub name: ::prost::alloc::string::String, + #[prost(string, tag="3")] + pub symbol: ::prost::alloc::string::String, + #[prost(uint64, tag="4")] + pub decimals: u64, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Transfers { + #[prost(message, repeated, tag="1")] + pub items: ::prost::alloc::vec::Vec, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Transfer { + #[prost(string, tag="1")] + pub tx_hash: ::prost::alloc::string::String, + #[prost(uint32, optional, tag="2")] + pub log_index: ::core::option::Option, + #[prost(uint64, optional, tag="3")] + pub log_ordinal: ::core::option::Option, + #[prost(message, optional, tag="4")] + pub token: ::core::option::Option, + #[prost(string, tag="5")] + pub from: ::prost::alloc::string::String, + #[prost(string, tag="6")] + pub to: ::prost::alloc::string::String, + /// BigInt, in token's native amount + #[prost(string, tag="7")] + pub amount: ::prost::alloc::string::String, + #[prost(string, optional, tag="8")] + pub amount_usd: ::core::option::Option<::prost::alloc::string::String>, + #[prost(string, optional, tag="9")] + pub reason: ::core::option::Option<::prost::alloc::string::String>, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct TokenBalance { + #[prost(message, optional, tag="1")] + pub token: ::core::option::Option, + /// BigInt, in token's native amount + #[prost(string, tag="2")] + pub balance: ::prost::alloc::string::String, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Account { + #[prost(string, tag="1")] + pub address: ::prost::alloc::string::String, + #[prost(message, repeated, tag="2")] + pub balances: ::prost::alloc::vec::Vec, +} +/// TODO: do we need this? +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Accounts { + #[prost(message, repeated, tag="1")] + pub items: ::prost::alloc::vec::Vec, +} +/// Encoded file descriptor set for the `messari.token.v1` package +pub const FILE_DESCRIPTOR_SET: &[u8] = &[ + 0x0a, 0xb8, 0x12, 0x0a, 0x0b, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x12, 0x10, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x72, 0x69, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, + 0x76, 0x31, 0x22, 0x37, 0x0a, 0x06, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x12, 0x2d, 0x0a, 0x05, + 0x69, 0x74, 0x65, 0x6d, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x6d, 0x65, + 0x73, 0x73, 0x61, 0x72, 0x69, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x54, + 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x22, 0x69, 0x0a, 0x05, 0x54, + 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x12, + 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, + 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x06, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, + 0x63, 0x69, 0x6d, 0x61, 0x6c, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x64, 0x65, + 0x63, 0x69, 0x6d, 0x61, 0x6c, 0x73, 0x22, 0x3d, 0x0a, 0x09, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x66, + 0x65, 0x72, 0x73, 0x12, 0x30, 0x0a, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x18, 0x01, 0x20, 0x03, + 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x72, 0x69, 0x2e, 0x74, 0x6f, 0x6b, + 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 0x52, 0x05, + 0x69, 0x74, 0x65, 0x6d, 0x73, 0x22, 0xcf, 0x02, 0x0a, 0x08, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x66, + 0x65, 0x72, 0x12, 0x17, 0x0a, 0x07, 0x74, 0x78, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x06, 0x74, 0x78, 0x48, 0x61, 0x73, 0x68, 0x12, 0x20, 0x0a, 0x09, 0x6c, + 0x6f, 0x67, 0x5f, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x48, 0x00, + 0x52, 0x08, 0x6c, 0x6f, 0x67, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x88, 0x01, 0x01, 0x12, 0x24, 0x0a, + 0x0b, 0x6c, 0x6f, 0x67, 0x5f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x6c, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x04, 0x48, 0x01, 0x52, 0x0a, 0x6c, 0x6f, 0x67, 0x4f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x6c, + 0x88, 0x01, 0x01, 0x12, 0x2d, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x04, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x72, 0x69, 0x2e, 0x74, 0x6f, 0x6b, + 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x05, 0x74, 0x6f, 0x6b, + 0x65, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x72, 0x6f, 0x6d, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x04, 0x66, 0x72, 0x6f, 0x6d, 0x12, 0x0e, 0x0a, 0x02, 0x74, 0x6f, 0x18, 0x06, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x02, 0x74, 0x6f, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, + 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x22, + 0x0a, 0x0a, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x75, 0x73, 0x64, 0x18, 0x08, 0x20, 0x01, + 0x28, 0x09, 0x48, 0x02, 0x52, 0x09, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x55, 0x73, 0x64, 0x88, + 0x01, 0x01, 0x12, 0x1b, 0x0a, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x09, 0x20, 0x01, + 0x28, 0x09, 0x48, 0x03, 0x52, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x88, 0x01, 0x01, 0x42, + 0x0c, 0x0a, 0x0a, 0x5f, 0x6c, 0x6f, 0x67, 0x5f, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x42, 0x0e, 0x0a, + 0x0c, 0x5f, 0x6c, 0x6f, 0x67, 0x5f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x6c, 0x42, 0x0d, 0x0a, + 0x0b, 0x5f, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x75, 0x73, 0x64, 0x42, 0x09, 0x0a, 0x07, + 0x5f, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x22, 0x57, 0x0a, 0x0c, 0x54, 0x6f, 0x6b, 0x65, 0x6e, + 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x2d, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x72, 0x69, + 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, + 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, + 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, + 0x22, 0x5f, 0x0a, 0x07, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x61, + 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x64, + 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x3a, 0x0a, 0x08, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, + 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x72, + 0x69, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, + 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x08, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, + 0x73, 0x22, 0x3b, 0x0a, 0x08, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x12, 0x2f, 0x0a, + 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x6d, + 0x65, 0x73, 0x73, 0x61, 0x72, 0x69, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, + 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x4a, 0xe2, + 0x0b, 0x0a, 0x06, 0x12, 0x04, 0x00, 0x00, 0x2c, 0x01, 0x0a, 0x08, 0x0a, 0x01, 0x0c, 0x12, 0x03, + 0x00, 0x00, 0x12, 0x0a, 0x08, 0x0a, 0x01, 0x02, 0x12, 0x03, 0x02, 0x00, 0x19, 0x0a, 0x0a, 0x0a, + 0x02, 0x04, 0x00, 0x12, 0x04, 0x04, 0x00, 0x06, 0x01, 0x0a, 0x0a, 0x0a, 0x03, 0x04, 0x00, 0x01, + 0x12, 0x03, 0x04, 0x08, 0x0e, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x00, 0x02, 0x00, 0x12, 0x03, 0x05, + 0x02, 0x1b, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, 0x04, 0x12, 0x03, 0x05, 0x02, 0x0a, + 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, 0x06, 0x12, 0x03, 0x05, 0x0b, 0x10, 0x0a, 0x0c, + 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, 0x01, 0x12, 0x03, 0x05, 0x11, 0x16, 0x0a, 0x0c, 0x0a, 0x05, + 0x04, 0x00, 0x02, 0x00, 0x03, 0x12, 0x03, 0x05, 0x19, 0x1a, 0x0a, 0x0a, 0x0a, 0x02, 0x04, 0x01, + 0x12, 0x04, 0x08, 0x00, 0x0d, 0x01, 0x0a, 0x0a, 0x0a, 0x03, 0x04, 0x01, 0x01, 0x12, 0x03, 0x08, + 0x08, 0x0d, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x01, 0x02, 0x00, 0x12, 0x03, 0x09, 0x02, 0x15, 0x0a, + 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x00, 0x05, 0x12, 0x03, 0x09, 0x02, 0x08, 0x0a, 0x0c, 0x0a, + 0x05, 0x04, 0x01, 0x02, 0x00, 0x01, 0x12, 0x03, 0x09, 0x09, 0x10, 0x0a, 0x0c, 0x0a, 0x05, 0x04, + 0x01, 0x02, 0x00, 0x03, 0x12, 0x03, 0x09, 0x13, 0x14, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x01, 0x02, + 0x01, 0x12, 0x03, 0x0a, 0x02, 0x12, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x01, 0x05, 0x12, + 0x03, 0x0a, 0x02, 0x08, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x01, 0x01, 0x12, 0x03, 0x0a, + 0x09, 0x0d, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x01, 0x03, 0x12, 0x03, 0x0a, 0x10, 0x11, + 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x01, 0x02, 0x02, 0x12, 0x03, 0x0b, 0x02, 0x14, 0x0a, 0x0c, 0x0a, + 0x05, 0x04, 0x01, 0x02, 0x02, 0x05, 0x12, 0x03, 0x0b, 0x02, 0x08, 0x0a, 0x0c, 0x0a, 0x05, 0x04, + 0x01, 0x02, 0x02, 0x01, 0x12, 0x03, 0x0b, 0x09, 0x0f, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, + 0x02, 0x03, 0x12, 0x03, 0x0b, 0x12, 0x13, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x01, 0x02, 0x03, 0x12, + 0x03, 0x0c, 0x02, 0x16, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x03, 0x05, 0x12, 0x03, 0x0c, + 0x02, 0x08, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x03, 0x01, 0x12, 0x03, 0x0c, 0x09, 0x11, + 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x03, 0x03, 0x12, 0x03, 0x0c, 0x14, 0x15, 0x0a, 0x0a, + 0x0a, 0x02, 0x04, 0x02, 0x12, 0x04, 0x0f, 0x00, 0x11, 0x01, 0x0a, 0x0a, 0x0a, 0x03, 0x04, 0x02, + 0x01, 0x12, 0x03, 0x0f, 0x08, 0x11, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x02, 0x02, 0x00, 0x12, 0x03, + 0x10, 0x02, 0x1e, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x02, 0x02, 0x00, 0x04, 0x12, 0x03, 0x10, 0x02, + 0x0a, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x02, 0x02, 0x00, 0x06, 0x12, 0x03, 0x10, 0x0b, 0x13, 0x0a, + 0x0c, 0x0a, 0x05, 0x04, 0x02, 0x02, 0x00, 0x01, 0x12, 0x03, 0x10, 0x14, 0x19, 0x0a, 0x0c, 0x0a, + 0x05, 0x04, 0x02, 0x02, 0x00, 0x03, 0x12, 0x03, 0x10, 0x1c, 0x1d, 0x0a, 0x0a, 0x0a, 0x02, 0x04, + 0x03, 0x12, 0x04, 0x13, 0x00, 0x1d, 0x01, 0x0a, 0x0a, 0x0a, 0x03, 0x04, 0x03, 0x01, 0x12, 0x03, + 0x13, 0x08, 0x10, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x03, 0x02, 0x00, 0x12, 0x03, 0x14, 0x02, 0x15, + 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x00, 0x05, 0x12, 0x03, 0x14, 0x02, 0x08, 0x0a, 0x0c, + 0x0a, 0x05, 0x04, 0x03, 0x02, 0x00, 0x01, 0x12, 0x03, 0x14, 0x09, 0x10, 0x0a, 0x0c, 0x0a, 0x05, + 0x04, 0x03, 0x02, 0x00, 0x03, 0x12, 0x03, 0x14, 0x13, 0x14, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x03, + 0x02, 0x01, 0x12, 0x03, 0x15, 0x02, 0x20, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x01, 0x04, + 0x12, 0x03, 0x15, 0x02, 0x0a, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x01, 0x05, 0x12, 0x03, + 0x15, 0x0b, 0x11, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x01, 0x01, 0x12, 0x03, 0x15, 0x12, + 0x1b, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x01, 0x03, 0x12, 0x03, 0x15, 0x1e, 0x1f, 0x0a, + 0x0b, 0x0a, 0x04, 0x04, 0x03, 0x02, 0x02, 0x12, 0x03, 0x16, 0x02, 0x22, 0x0a, 0x0c, 0x0a, 0x05, + 0x04, 0x03, 0x02, 0x02, 0x04, 0x12, 0x03, 0x16, 0x02, 0x0a, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, + 0x02, 0x02, 0x05, 0x12, 0x03, 0x16, 0x0b, 0x11, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x02, + 0x01, 0x12, 0x03, 0x16, 0x12, 0x1d, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x02, 0x03, 0x12, + 0x03, 0x16, 0x20, 0x21, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x03, 0x02, 0x03, 0x12, 0x03, 0x17, 0x02, + 0x12, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x03, 0x06, 0x12, 0x03, 0x17, 0x02, 0x07, 0x0a, + 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x03, 0x01, 0x12, 0x03, 0x17, 0x08, 0x0d, 0x0a, 0x0c, 0x0a, + 0x05, 0x04, 0x03, 0x02, 0x03, 0x03, 0x12, 0x03, 0x17, 0x10, 0x11, 0x0a, 0x0b, 0x0a, 0x04, 0x04, + 0x03, 0x02, 0x04, 0x12, 0x03, 0x18, 0x02, 0x12, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x04, + 0x05, 0x12, 0x03, 0x18, 0x02, 0x08, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x04, 0x01, 0x12, + 0x03, 0x18, 0x09, 0x0d, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x04, 0x03, 0x12, 0x03, 0x18, + 0x10, 0x11, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x03, 0x02, 0x05, 0x12, 0x03, 0x19, 0x02, 0x10, 0x0a, + 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x05, 0x05, 0x12, 0x03, 0x19, 0x02, 0x08, 0x0a, 0x0c, 0x0a, + 0x05, 0x04, 0x03, 0x02, 0x05, 0x01, 0x12, 0x03, 0x19, 0x09, 0x0b, 0x0a, 0x0c, 0x0a, 0x05, 0x04, + 0x03, 0x02, 0x05, 0x03, 0x12, 0x03, 0x19, 0x0e, 0x0f, 0x0a, 0x2f, 0x0a, 0x04, 0x04, 0x03, 0x02, + 0x06, 0x12, 0x03, 0x1a, 0x02, 0x14, 0x22, 0x22, 0x20, 0x42, 0x69, 0x67, 0x49, 0x6e, 0x74, 0x2c, + 0x20, 0x69, 0x6e, 0x20, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x27, 0x73, 0x20, 0x6e, 0x61, 0x74, 0x69, + 0x76, 0x65, 0x20, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x0a, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, + 0x02, 0x06, 0x05, 0x12, 0x03, 0x1a, 0x02, 0x08, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x06, + 0x01, 0x12, 0x03, 0x1a, 0x09, 0x0f, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x06, 0x03, 0x12, + 0x03, 0x1a, 0x12, 0x13, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x03, 0x02, 0x07, 0x12, 0x03, 0x1b, 0x02, + 0x21, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x07, 0x04, 0x12, 0x03, 0x1b, 0x02, 0x0a, 0x0a, + 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x07, 0x05, 0x12, 0x03, 0x1b, 0x0b, 0x11, 0x0a, 0x0c, 0x0a, + 0x05, 0x04, 0x03, 0x02, 0x07, 0x01, 0x12, 0x03, 0x1b, 0x12, 0x1c, 0x0a, 0x0c, 0x0a, 0x05, 0x04, + 0x03, 0x02, 0x07, 0x03, 0x12, 0x03, 0x1b, 0x1f, 0x20, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x03, 0x02, + 0x08, 0x12, 0x03, 0x1c, 0x02, 0x1d, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x08, 0x04, 0x12, + 0x03, 0x1c, 0x02, 0x0a, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x08, 0x05, 0x12, 0x03, 0x1c, + 0x0b, 0x11, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x08, 0x01, 0x12, 0x03, 0x1c, 0x12, 0x18, + 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x08, 0x03, 0x12, 0x03, 0x1c, 0x1b, 0x1c, 0x0a, 0x0a, + 0x0a, 0x02, 0x04, 0x04, 0x12, 0x04, 0x1f, 0x00, 0x22, 0x01, 0x0a, 0x0a, 0x0a, 0x03, 0x04, 0x04, + 0x01, 0x12, 0x03, 0x1f, 0x08, 0x14, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x04, 0x02, 0x00, 0x12, 0x03, + 0x20, 0x02, 0x12, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x04, 0x02, 0x00, 0x06, 0x12, 0x03, 0x20, 0x02, + 0x07, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x04, 0x02, 0x00, 0x01, 0x12, 0x03, 0x20, 0x08, 0x0d, 0x0a, + 0x0c, 0x0a, 0x05, 0x04, 0x04, 0x02, 0x00, 0x03, 0x12, 0x03, 0x20, 0x10, 0x11, 0x0a, 0x2f, 0x0a, + 0x04, 0x04, 0x04, 0x02, 0x01, 0x12, 0x03, 0x21, 0x02, 0x15, 0x22, 0x22, 0x20, 0x42, 0x69, 0x67, + 0x49, 0x6e, 0x74, 0x2c, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x27, 0x73, 0x20, + 0x6e, 0x61, 0x74, 0x69, 0x76, 0x65, 0x20, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x0a, 0x0a, 0x0c, + 0x0a, 0x05, 0x04, 0x04, 0x02, 0x01, 0x05, 0x12, 0x03, 0x21, 0x02, 0x08, 0x0a, 0x0c, 0x0a, 0x05, + 0x04, 0x04, 0x02, 0x01, 0x01, 0x12, 0x03, 0x21, 0x09, 0x10, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x04, + 0x02, 0x01, 0x03, 0x12, 0x03, 0x21, 0x13, 0x14, 0x0a, 0x0a, 0x0a, 0x02, 0x04, 0x05, 0x12, 0x04, + 0x24, 0x00, 0x27, 0x01, 0x0a, 0x0a, 0x0a, 0x03, 0x04, 0x05, 0x01, 0x12, 0x03, 0x24, 0x08, 0x0f, + 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x05, 0x02, 0x00, 0x12, 0x03, 0x25, 0x02, 0x15, 0x0a, 0x0c, 0x0a, + 0x05, 0x04, 0x05, 0x02, 0x00, 0x05, 0x12, 0x03, 0x25, 0x02, 0x08, 0x0a, 0x0c, 0x0a, 0x05, 0x04, + 0x05, 0x02, 0x00, 0x01, 0x12, 0x03, 0x25, 0x09, 0x10, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x05, 0x02, + 0x00, 0x03, 0x12, 0x03, 0x25, 0x13, 0x14, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x05, 0x02, 0x01, 0x12, + 0x03, 0x26, 0x02, 0x25, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x05, 0x02, 0x01, 0x04, 0x12, 0x03, 0x26, + 0x02, 0x0a, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x05, 0x02, 0x01, 0x06, 0x12, 0x03, 0x26, 0x0b, 0x17, + 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x05, 0x02, 0x01, 0x01, 0x12, 0x03, 0x26, 0x18, 0x20, 0x0a, 0x0c, + 0x0a, 0x05, 0x04, 0x05, 0x02, 0x01, 0x03, 0x12, 0x03, 0x26, 0x23, 0x24, 0x0a, 0x24, 0x0a, 0x02, + 0x04, 0x06, 0x12, 0x04, 0x2a, 0x00, 0x2c, 0x01, 0x1a, 0x18, 0x20, 0x54, 0x4f, 0x44, 0x4f, 0x3a, + 0x20, 0x64, 0x6f, 0x20, 0x77, 0x65, 0x20, 0x6e, 0x65, 0x65, 0x64, 0x20, 0x74, 0x68, 0x69, 0x73, + 0x3f, 0x0a, 0x0a, 0x0a, 0x0a, 0x03, 0x04, 0x06, 0x01, 0x12, 0x03, 0x2a, 0x08, 0x10, 0x0a, 0x0b, + 0x0a, 0x04, 0x04, 0x06, 0x02, 0x00, 0x12, 0x03, 0x2b, 0x02, 0x1d, 0x0a, 0x0c, 0x0a, 0x05, 0x04, + 0x06, 0x02, 0x00, 0x04, 0x12, 0x03, 0x2b, 0x02, 0x0a, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x06, 0x02, + 0x00, 0x06, 0x12, 0x03, 0x2b, 0x0b, 0x12, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x06, 0x02, 0x00, 0x01, + 0x12, 0x03, 0x2b, 0x13, 0x18, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x06, 0x02, 0x00, 0x03, 0x12, 0x03, + 0x2b, 0x1b, 0x1c, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +]; +// @@protoc_insertion_point(module) \ No newline at end of file diff --git a/eth-balance/substreams.yaml b/eth-balance/substreams.yaml index d3cf94ca..e766789d 100644 --- a/eth-balance/substreams.yaml +++ b/eth-balance/substreams.yaml @@ -10,7 +10,7 @@ protobuf: files: - token.proto importPaths: - - ../common/proto/token.proto + - ../common/proto binaries: default: @@ -18,23 +18,10 @@ binaries: file: "../target/wasm32-unknown-unknown/release/eth_balance.wasm" modules: - - name: map_account_balances + - name: map_balances kind: map + initialBlock: 0 inputs: - source: sf.ethereum.type.v2.Block output: - type: proto:messari.token.v1.Account - - - name: map_transfers - kind: map - inputs: - - source: sf.ethereum.type.v2.Block - output: - type: proto:messari.token.v1.Transfers - - - name: store_transfers - kind: store - updatePolicy: add - valueType: int64 - inputs: - - map: map_transfers + type: proto:messari.token.Account From 8fe7b1438d80403c44ca9110578a33d88f397c2b Mon Sep 17 00:00:00 2001 From: dmelotik Date: Thu, 29 Dec 2022 22:48:40 -0600 Subject: [PATCH 03/25] format --- eth-balance/src/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/eth-balance/src/lib.rs b/eth-balance/src/lib.rs index 28f0c2fd..085afd34 100644 --- a/eth-balance/src/lib.rs +++ b/eth-balance/src/lib.rs @@ -1,12 +1,12 @@ #[rustfmt::skip] pub mod pb; -use pb::token::v1 as token; +use crate::pb::token::v1::Token; use num_bigint; +use pb::token::v1 as token; use substreams::scalar::BigInt; use substreams::Hex; use substreams_ethereum::pb::eth as pbeth; -use crate::pb::token::v1::Token; #[substreams::handlers::map] fn map_balances(block: pbeth::v2::Block) -> Result { @@ -26,18 +26,18 @@ fn map_balances(block: pbeth::v2::Block) -> Result token::Token { address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE".to_string(), // TODO: do we need to append "address: "? name: "Ethereum".to_string(), symbol: "ETH".to_string(), - decimals: 18 as u64 + decimals: 18 as u64, }; // let tokens = vec![eth_token.clone()]; // TODO: does this set the Tokens protbuf definition From ddcbf36959740b4dd185d1163bee33e9b4b35bc2 Mon Sep 17 00:00:00 2001 From: dmelotik Date: Fri, 6 Jan 2023 18:35:26 -0700 Subject: [PATCH 04/25] clean up --- Cargo.toml | 4 -- common/proto/dex_amm.proto | 2 +- common/proto/erc20.proto | 38 +++++++++++++++++++ common/proto/{token.proto => evm.token.proto} | 4 +- eth-balance/Makefile | 2 +- eth-balance/src/lib.rs | 4 +- eth-balance/substreams.yaml | 2 +- 7 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 common/proto/erc20.proto rename common/proto/{token.proto => evm.token.proto} (95%) diff --git a/Cargo.toml b/Cargo.toml index 72d7bb2d..5fbd25c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,10 +20,6 @@ substreams = "0.3.2" substreams-ethereum = "0.6.2" substreams-solana = "0.1.0" -# TODO: I get a warning when this is uncommented -#[build] -#target = "wasm32-unknown-unknown" - [profile.release] lto = true opt-level = 's' diff --git a/common/proto/dex_amm.proto b/common/proto/dex_amm.proto index 0f56dae9..69f84c0a 100644 --- a/common/proto/dex_amm.proto +++ b/common/proto/dex_amm.proto @@ -1,7 +1,7 @@ syntax = "proto3"; import "common.proto"; -import "token.proto"; +import "erc20.proto"; package messari.dex_amm.v1; diff --git a/common/proto/erc20.proto b/common/proto/erc20.proto new file mode 100644 index 00000000..2c0b99cf --- /dev/null +++ b/common/proto/erc20.proto @@ -0,0 +1,38 @@ +syntax = "proto3"; + +package messari.erc20.v1; + +message ERC20Tokens { + repeated ERC20Token items = 1; +} + +message ERC20Token { + string address = 1; + string name = 2; + string symbol = 3; + uint64 decimals = 4; +} + +message TransferEvents { + repeated TransferEvent items = 1; +} + +message TransferEvent { + string tx_hash = 1; + uint32 log_index = 2; + uint64 log_ordinal = 3; + string token_address = 4; + string from = 5; + string to = 6; + string amount = 7; // BigInt, in token's native amount +} + +message TokenBalance { + string token_address = 1; + string balance = 2; // BigInt, in token's native amount +} + +message Account { + string address = 1; + repeated TokenBalance balances = 2; +} diff --git a/common/proto/token.proto b/common/proto/evm.token.proto similarity index 95% rename from common/proto/token.proto rename to common/proto/evm.token.proto index dede3ac7..a6bd45fb 100644 --- a/common/proto/token.proto +++ b/common/proto/evm.token.proto @@ -11,6 +11,7 @@ message Token { string name = 2; string symbol = 3; uint64 decimals = 4; + optional string total_supply = 5; } message Transfers { @@ -39,7 +40,6 @@ message Account { repeated TokenBalance balances = 2; } -// TODO: do we need this? message Accounts { repeated Account items = 1; -} \ No newline at end of file +} diff --git a/eth-balance/Makefile b/eth-balance/Makefile index 3bd5d404..b780e887 100644 --- a/eth-balance/Makefile +++ b/eth-balance/Makefile @@ -8,4 +8,4 @@ build: .PHONY: run run: - substreams run -e mainnet.eth.streamingfast.io:443 substreams.yaml map_balances + substreams run -e mainnet.eth.streamingfast.io:443 substreams.yaml map_balances -s 46977 -t 46980 diff --git a/eth-balance/src/lib.rs b/eth-balance/src/lib.rs index 085afd34..72b05010 100644 --- a/eth-balance/src/lib.rs +++ b/eth-balance/src/lib.rs @@ -46,12 +46,12 @@ fn map_balances(block: pbeth::v2::Block) -> Result token::Token { let eth_token = Token { - address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE".to_string(), // TODO: do we need to append "address: "? + address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE".to_string(), name: "Ethereum".to_string(), symbol: "ETH".to_string(), decimals: 18 as u64, + total_supply: None, }; - // let tokens = vec![eth_token.clone()]; // TODO: does this set the Tokens protbuf definition eth_token } diff --git a/eth-balance/substreams.yaml b/eth-balance/substreams.yaml index e766789d..ed1ecd7c 100644 --- a/eth-balance/substreams.yaml +++ b/eth-balance/substreams.yaml @@ -8,7 +8,7 @@ imports: protobuf: files: - - token.proto + - evm.token.proto importPaths: - ../common/proto From 33b91add097c529e06f7304efdca0c2271d08c4b Mon Sep 17 00:00:00 2001 From: dmelotik Date: Fri, 6 Jan 2023 18:36:18 -0700 Subject: [PATCH 05/25] clean up README.md --- common/README.md | 58 ++---------------------------------------------- 1 file changed, 2 insertions(+), 56 deletions(-) diff --git a/common/README.md b/common/README.md index 7ddd178e..dc298361 100644 --- a/common/README.md +++ b/common/README.md @@ -10,60 +10,6 @@ TODO TODO -## Token Proto +## EVM Token Proto -The token proto is designed to store the token balances of all accounts throughout the blockchains history. It is designed to be network-agnostic and support all tokens. Token's can be blockchain native, erc20s, or any other derivative. - -### Definitions - -The first part are the token definitions. This is simple, and defines the tokens that are supported in the substream implementation. - -> Note: if the token is a native token (e.g. ethereum), then the address is the `0x0` address and the other values need to be hardcoded. -```protobuf -message Tokens { - repeated Token items = 1; -} - -message Token { - string address = 1; - string name = 2; - string symbol = 3; - uint64 decimals = 4; -} -``` - -The transfers track where the tokens move to/from. In most cases we can fill in every field. A `log_index` or `log_ordinal` may not always be possible. In addition a mint or burn will have either the `to` or `from` address as the `0x0` address. - -```protobuf -message Transfers { - repeated Transfer items = 1; -} - -message Transfer { - string tx_hash = 1; - optional uint32 log_index = 2; - optional uint64 log_ordinal = 3; - Token token = 4; - string from = 5; - string to = 6; - string amount = 7; // BigInt, in token's native amount - optional string reason = 8; -} -``` - -`TokenBalance` is simple, and defines the balance of a given token in an account. -```protobuf -message TokenBalance { - string token_address = 1; - string balance = 2; // BigInt, in token's native amount -} - -message Account { - string address = 1; - repeated TokenBalance balances = 2; -} -``` - -### How to Use - -TODO +This proto is designed to support fungible tokens on evm chains. In order to preserve the data from each chain we have separate definitions for tokens across chain implementations. From 83fdebf6cee939a5e0877b393e7c6723988c3d2b Mon Sep 17 00:00:00 2001 From: dmelotik Date: Fri, 6 Jan 2023 18:51:00 -0700 Subject: [PATCH 06/25] update docs --- common/README.md | 2 ++ docs/DECODING.md | 3 +++ docs/STANDARDS.md | 9 +++++++++ 3 files changed, 14 insertions(+) create mode 100644 docs/DECODING.md create mode 100644 docs/STANDARDS.md diff --git a/common/README.md b/common/README.md index dc298361..b8c18fb6 100644 --- a/common/README.md +++ b/common/README.md @@ -2,6 +2,8 @@ This folder contains common definitions for protobufs used more than once. We intentionally have this in order to standardize the way we define the data to make it easier for the end user to "plug-n-play". +We do NOT want to "over-standardize" on a substream level. Substreams works with raw, lower-level data. We do not want to lose any descriptiveness at this layer, therefore it is important to not generalize any data to try and fit a standard. + ## Common Proto TODO diff --git a/docs/DECODING.md b/docs/DECODING.md new file mode 100644 index 00000000..fd36e2f2 --- /dev/null +++ b/docs/DECODING.md @@ -0,0 +1,3 @@ +# Decoding Data + +Firehose delivers data in a very raw format and in order to make use of the data we need to be able to decode it. This file will go over examples of where/how you might need to do this. diff --git a/docs/STANDARDS.md b/docs/STANDARDS.md new file mode 100644 index 00000000..b0d9e2e7 --- /dev/null +++ b/docs/STANDARDS.md @@ -0,0 +1,9 @@ +# Standards + +Standardizing where it makes sense and early pays dividends in terms of developer time in the long run. This file will explore where we standardize and why those decisions were made. + +## Protobuf Definitions + +Where the same data structures are used multiple times, it makes sense to make a [common](../common) protobuf definition. It shows the user this definition can be found in multiple places. It also makes the code base cleaner. You can find these under [`../common/proto`](../common/proto). + +> You can learn more details about this [here](../common/README.md) From db2956e78c1b71bea017d28fe1616d1371aec09f Mon Sep 17 00:00:00 2001 From: dmelotik Date: Fri, 6 Jan 2023 20:48:27 -0700 Subject: [PATCH 07/25] update package name --- common/proto/evm.token.proto | 2 +- eth-balance/src/pb.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/common/proto/evm.token.proto b/common/proto/evm.token.proto index a6bd45fb..1025d10d 100644 --- a/common/proto/evm.token.proto +++ b/common/proto/evm.token.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -package messari.token.v1; +package messari.evm.token.v1; message Tokens { repeated Token items = 1; diff --git a/eth-balance/src/pb.rs b/eth-balance/src/pb.rs index c2b8777a..bbaf7662 100644 --- a/eth-balance/src/pb.rs +++ b/eth-balance/src/pb.rs @@ -1,9 +1,9 @@ #[rustfmt::skip] -#[path = "../target/pb/messari.token.v1.rs"] -pub(in crate::pb) mod token_v1; +#[path = "../target/pb/messari.evm.token.v1.rs"] +pub(in crate::pb) mod evm_token; -pub mod token { - pub mod v1 { - pub use super::super::token_v1::*; +pub mod evm { + pub mod token { + pub use super::super::evm_token::*; } } From a66961d6fe2c7b207c8390ae3a67dd6b5dc48d3f Mon Sep 17 00:00:00 2001 From: dmelotik Date: Fri, 6 Jan 2023 20:53:06 -0700 Subject: [PATCH 08/25] update --- eth-balance/substreams.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eth-balance/substreams.yaml b/eth-balance/substreams.yaml index ed1ecd7c..e755a2a3 100644 --- a/eth-balance/substreams.yaml +++ b/eth-balance/substreams.yaml @@ -24,4 +24,4 @@ modules: inputs: - source: sf.ethereum.type.v2.Block output: - type: proto:messari.token.Account + type: proto:messari.evm.token.Account From b4b7668001b5849378e766bb0c8d3233559e0e0e Mon Sep 17 00:00:00 2001 From: dmelotik Date: Tue, 10 Jan 2023 20:00:39 -0700 Subject: [PATCH 09/25] fix Vincents comments --- Cargo.toml | 3 +++ .../{evm.token.proto => evm_token.proto} | 10 ++++--- eth-balance/src/lib.rs | 26 +++++-------------- eth-balance/src/pb.rs | 10 +++---- eth-balance/substreams.yaml | 2 +- substreams-helper/src/lib.rs | 1 + substreams-helper/src/token.rs | 13 ++++++++++ 7 files changed, 36 insertions(+), 29 deletions(-) rename common/proto/{evm.token.proto => evm_token.proto} (80%) create mode 100644 substreams-helper/src/token.rs diff --git a/Cargo.toml b/Cargo.toml index 5fbd25c0..5a1bd6a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,9 @@ substreams = "0.3.2" substreams-ethereum = "0.6.2" substreams-solana = "0.1.0" +[build] +target = "wasm32-unknown-unknown" + [profile.release] lto = true opt-level = 's' diff --git a/common/proto/evm.token.proto b/common/proto/evm_token.proto similarity index 80% rename from common/proto/evm.token.proto rename to common/proto/evm_token.proto index 1025d10d..9ef3ccfa 100644 --- a/common/proto/evm.token.proto +++ b/common/proto/evm_token.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -package messari.evm.token.v1; +package messari.evm_token.v1; message Tokens { repeated Token items = 1; @@ -20,19 +20,21 @@ message Transfers { message Transfer { string tx_hash = 1; - optional uint32 log_index = 2; - optional uint64 log_ordinal = 3; + uint32 log_index = 2; + uint64 log_ordinal = 3; Token token = 4; string from = 5; string to = 6; string amount = 7; // BigInt, in token's native amount optional string amount_usd = 8; - optional string reason = 9; } +// spot balance of the given token message TokenBalance { Token token = 1; string balance = 2; // BigInt, in token's native amount + uint64 block_number = 3; + uint64 timestamp = 4; } message Account { diff --git a/eth-balance/src/lib.rs b/eth-balance/src/lib.rs index 72b05010..57540432 100644 --- a/eth-balance/src/lib.rs +++ b/eth-balance/src/lib.rs @@ -1,12 +1,14 @@ #[rustfmt::skip] pub mod pb; -use crate::pb::token::v1::Token; +use crate::pb::evm_token::v1::Token; use num_bigint; -use pb::token::v1 as token; +use pb::evm_token::v1 as token; use substreams::scalar::BigInt; use substreams::Hex; use substreams_ethereum::pb::eth as pbeth; +use substreams_helper::token::get_eth_token; + #[substreams::handlers::map] fn map_balances(block: pbeth::v2::Block) -> Result { @@ -25,8 +27,10 @@ fn map_balances(block: pbeth::v2::Block) -> Result Result token::Token { - let eth_token = Token { - address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE".to_string(), - name: "Ethereum".to_string(), - symbol: "ETH".to_string(), - decimals: 18 as u64, - total_supply: None, - }; - - eth_token -} diff --git a/eth-balance/src/pb.rs b/eth-balance/src/pb.rs index bbaf7662..2b6dbd63 100644 --- a/eth-balance/src/pb.rs +++ b/eth-balance/src/pb.rs @@ -1,9 +1,9 @@ #[rustfmt::skip] -#[path = "../target/pb/messari.evm.token.v1.rs"] -pub(in crate::pb) mod evm_token; +#[path = "../target/pb/messari.evm_token.v1.rs"] +pub(in crate::pb) mod evm_token_v1; -pub mod evm { - pub mod token { - pub use super::super::evm_token::*; +pub mod evm_token { + pub mod v1 { + pub use super::super::evm_token_v1::*; } } diff --git a/eth-balance/substreams.yaml b/eth-balance/substreams.yaml index e755a2a3..7310d434 100644 --- a/eth-balance/substreams.yaml +++ b/eth-balance/substreams.yaml @@ -8,7 +8,7 @@ imports: protobuf: files: - - evm.token.proto + - evm_token.proto importPaths: - ../common/proto diff --git a/substreams-helper/src/lib.rs b/substreams-helper/src/lib.rs index b6cf1767..46e38e87 100644 --- a/substreams-helper/src/lib.rs +++ b/substreams-helper/src/lib.rs @@ -3,5 +3,6 @@ pub mod erc20; pub mod keyer; pub mod math; pub mod price; +pub mod token; pub mod types; pub mod utils; diff --git a/substreams-helper/src/token.rs b/substreams-helper/src/token.rs new file mode 100644 index 00000000..eeb5172c --- /dev/null +++ b/substreams-helper/src/token.rs @@ -0,0 +1,13 @@ +use crate::pb::evm_token::v1::Token; + +pub fn get_eth_token() -> Option { + let eth_token = Token { + address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE".to_string(), + name: "Ethereum".to_string(), + symbol: "ETH".to_string(), + decimals: 18 as u64, + total_supply: None, + }; + + Some(eth_token) +} From e49ee6d0d6d87f52ede426d730cdc13b6cd7b0d7 Mon Sep 17 00:00:00 2001 From: dmelotik Date: Wed, 11 Jan 2023 14:56:14 -0700 Subject: [PATCH 10/25] add evm token to helper manifest --- substreams-helper/Makefile | 4 + substreams-helper/src/pb.rs | 9 + .../src/pb/messari.evm_token.v1.rs | 232 ++++++++++++++++++ substreams-helper/src/token.rs | 2 +- substreams-helper/substreams.yaml | 19 ++ 5 files changed, 265 insertions(+), 1 deletion(-) create mode 100644 substreams-helper/src/pb.rs create mode 100644 substreams-helper/src/pb/messari.evm_token.v1.rs create mode 100644 substreams-helper/substreams.yaml diff --git a/substreams-helper/Makefile b/substreams-helper/Makefile index f991fe2f..354cce6d 100644 --- a/substreams-helper/Makefile +++ b/substreams-helper/Makefile @@ -1,3 +1,7 @@ +.PHONY: codegen +codegen: + substreams protogen ./substreams.yaml --exclude-paths="sf/ethereum,sf/substreams,google" + .PHONY: build build: cargo build --target wasm32-unknown-unknown --release diff --git a/substreams-helper/src/pb.rs b/substreams-helper/src/pb.rs new file mode 100644 index 00000000..2b6dbd63 --- /dev/null +++ b/substreams-helper/src/pb.rs @@ -0,0 +1,9 @@ +#[rustfmt::skip] +#[path = "../target/pb/messari.evm_token.v1.rs"] +pub(in crate::pb) mod evm_token_v1; + +pub mod evm_token { + pub mod v1 { + pub use super::super::evm_token_v1::*; + } +} diff --git a/substreams-helper/src/pb/messari.evm_token.v1.rs b/substreams-helper/src/pb/messari.evm_token.v1.rs new file mode 100644 index 00000000..6f0a137c --- /dev/null +++ b/substreams-helper/src/pb/messari.evm_token.v1.rs @@ -0,0 +1,232 @@ +// @generated +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Tokens { + #[prost(message, repeated, tag="1")] + pub items: ::prost::alloc::vec::Vec, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Token { + #[prost(string, tag="1")] + pub address: ::prost::alloc::string::String, + #[prost(string, tag="2")] + pub name: ::prost::alloc::string::String, + #[prost(string, tag="3")] + pub symbol: ::prost::alloc::string::String, + #[prost(uint64, tag="4")] + pub decimals: u64, + #[prost(string, optional, tag="5")] + pub total_supply: ::core::option::Option<::prost::alloc::string::String>, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Transfers { + #[prost(message, repeated, tag="1")] + pub items: ::prost::alloc::vec::Vec, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Transfer { + #[prost(string, tag="1")] + pub tx_hash: ::prost::alloc::string::String, + #[prost(uint32, tag="2")] + pub log_index: u32, + #[prost(uint64, tag="3")] + pub log_ordinal: u64, + #[prost(message, optional, tag="4")] + pub token: ::core::option::Option, + #[prost(string, tag="5")] + pub from: ::prost::alloc::string::String, + #[prost(string, tag="6")] + pub to: ::prost::alloc::string::String, + /// BigInt, in token's native amount + #[prost(string, tag="7")] + pub amount: ::prost::alloc::string::String, + #[prost(string, optional, tag="8")] + pub amount_usd: ::core::option::Option<::prost::alloc::string::String>, +} +/// spot balance of the given token +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct TokenBalance { + #[prost(message, optional, tag="1")] + pub token: ::core::option::Option, + /// BigInt, in token's native amount + #[prost(string, tag="2")] + pub balance: ::prost::alloc::string::String, + #[prost(uint64, tag="3")] + pub block_number: u64, + #[prost(uint64, tag="4")] + pub timestamp: u64, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Account { + #[prost(string, tag="1")] + pub address: ::prost::alloc::string::String, + #[prost(message, repeated, tag="2")] + pub balances: ::prost::alloc::vec::Vec, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Accounts { + #[prost(message, repeated, tag="1")] + pub items: ::prost::alloc::vec::Vec, +} +/// Encoded file descriptor set for the `messari.evm_token.v1` package +pub const FILE_DESCRIPTOR_SET: &[u8] = &[ + 0x0a, 0xdf, 0x13, 0x0a, 0x0f, 0x65, 0x76, 0x6d, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x14, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x72, 0x69, 0x2e, 0x65, 0x76, + 0x6d, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x22, 0x3b, 0x0a, 0x06, 0x54, 0x6f, + 0x6b, 0x65, 0x6e, 0x73, 0x12, 0x31, 0x0a, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x18, 0x01, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x72, 0x69, 0x2e, 0x65, 0x76, + 0x6d, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, + 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x22, 0xa2, 0x01, 0x0a, 0x05, 0x54, 0x6f, 0x6b, 0x65, + 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x6e, + 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, + 0x16, 0x0a, 0x06, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x06, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x63, 0x69, 0x6d, + 0x61, 0x6c, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x64, 0x65, 0x63, 0x69, 0x6d, + 0x61, 0x6c, 0x73, 0x12, 0x26, 0x0a, 0x0c, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x5f, 0x73, 0x75, 0x70, + 0x70, 0x6c, 0x79, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x0b, 0x74, 0x6f, 0x74, + 0x61, 0x6c, 0x53, 0x75, 0x70, 0x70, 0x6c, 0x79, 0x88, 0x01, 0x01, 0x42, 0x0f, 0x0a, 0x0d, 0x5f, + 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x5f, 0x73, 0x75, 0x70, 0x70, 0x6c, 0x79, 0x22, 0x41, 0x0a, 0x09, + 0x54, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 0x73, 0x12, 0x34, 0x0a, 0x05, 0x69, 0x74, 0x65, + 0x6d, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, + 0x72, 0x69, 0x2e, 0x65, 0x76, 0x6d, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, + 0x54, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x22, + 0x83, 0x02, 0x0a, 0x08, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 0x12, 0x17, 0x0a, 0x07, + 0x74, 0x78, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x74, + 0x78, 0x48, 0x61, 0x73, 0x68, 0x12, 0x1b, 0x0a, 0x09, 0x6c, 0x6f, 0x67, 0x5f, 0x69, 0x6e, 0x64, + 0x65, 0x78, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x6c, 0x6f, 0x67, 0x49, 0x6e, 0x64, + 0x65, 0x78, 0x12, 0x1f, 0x0a, 0x0b, 0x6c, 0x6f, 0x67, 0x5f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, + 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0a, 0x6c, 0x6f, 0x67, 0x4f, 0x72, 0x64, 0x69, + 0x6e, 0x61, 0x6c, 0x12, 0x31, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x04, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x72, 0x69, 0x2e, 0x65, 0x76, 0x6d, + 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, + 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x72, 0x6f, 0x6d, 0x18, 0x05, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x66, 0x72, 0x6f, 0x6d, 0x12, 0x0e, 0x0a, 0x02, 0x74, 0x6f, + 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x74, 0x6f, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x6d, + 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x61, 0x6d, 0x6f, 0x75, + 0x6e, 0x74, 0x12, 0x22, 0x0a, 0x0a, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x75, 0x73, 0x64, + 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x09, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, + 0x55, 0x73, 0x64, 0x88, 0x01, 0x01, 0x42, 0x0d, 0x0a, 0x0b, 0x5f, 0x61, 0x6d, 0x6f, 0x75, 0x6e, + 0x74, 0x5f, 0x75, 0x73, 0x64, 0x22, 0x9c, 0x01, 0x0a, 0x0c, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x42, + 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x31, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x72, 0x69, 0x2e, + 0x65, 0x76, 0x6d, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x6f, 0x6b, + 0x65, 0x6e, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x62, 0x61, 0x6c, + 0x61, 0x6e, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x62, 0x61, 0x6c, 0x61, + 0x6e, 0x63, 0x65, 0x12, 0x21, 0x0a, 0x0c, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x6e, 0x75, 0x6d, + 0x62, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0b, 0x62, 0x6c, 0x6f, 0x63, 0x6b, + 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, + 0x61, 0x6d, 0x70, 0x18, 0x04, 0x20, 0x01, 0x28, 0x04, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, + 0x74, 0x61, 0x6d, 0x70, 0x22, 0x63, 0x0a, 0x07, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, + 0x18, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x3e, 0x0a, 0x08, 0x62, 0x61, 0x6c, + 0x61, 0x6e, 0x63, 0x65, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x22, 0x2e, 0x6d, 0x65, + 0x73, 0x73, 0x61, 0x72, 0x69, 0x2e, 0x65, 0x76, 0x6d, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, + 0x76, 0x31, 0x2e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, + 0x08, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x73, 0x22, 0x3f, 0x0a, 0x08, 0x41, 0x63, 0x63, + 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x12, 0x33, 0x0a, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x18, 0x01, + 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x72, 0x69, 0x2e, 0x65, + 0x76, 0x6d, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x63, 0x63, 0x6f, + 0x75, 0x6e, 0x74, 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x4a, 0xbd, 0x0c, 0x0a, 0x06, 0x12, + 0x04, 0x00, 0x00, 0x2e, 0x01, 0x0a, 0x08, 0x0a, 0x01, 0x0c, 0x12, 0x03, 0x00, 0x00, 0x12, 0x0a, + 0x08, 0x0a, 0x01, 0x02, 0x12, 0x03, 0x02, 0x00, 0x1d, 0x0a, 0x0a, 0x0a, 0x02, 0x04, 0x00, 0x12, + 0x04, 0x04, 0x00, 0x06, 0x01, 0x0a, 0x0a, 0x0a, 0x03, 0x04, 0x00, 0x01, 0x12, 0x03, 0x04, 0x08, + 0x0e, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x00, 0x02, 0x00, 0x12, 0x03, 0x05, 0x02, 0x1b, 0x0a, 0x0c, + 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, 0x04, 0x12, 0x03, 0x05, 0x02, 0x0a, 0x0a, 0x0c, 0x0a, 0x05, + 0x04, 0x00, 0x02, 0x00, 0x06, 0x12, 0x03, 0x05, 0x0b, 0x10, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, + 0x02, 0x00, 0x01, 0x12, 0x03, 0x05, 0x11, 0x16, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, + 0x03, 0x12, 0x03, 0x05, 0x19, 0x1a, 0x0a, 0x0a, 0x0a, 0x02, 0x04, 0x01, 0x12, 0x04, 0x08, 0x00, + 0x0e, 0x01, 0x0a, 0x0a, 0x0a, 0x03, 0x04, 0x01, 0x01, 0x12, 0x03, 0x08, 0x08, 0x0d, 0x0a, 0x0b, + 0x0a, 0x04, 0x04, 0x01, 0x02, 0x00, 0x12, 0x03, 0x09, 0x02, 0x15, 0x0a, 0x0c, 0x0a, 0x05, 0x04, + 0x01, 0x02, 0x00, 0x05, 0x12, 0x03, 0x09, 0x02, 0x08, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, + 0x00, 0x01, 0x12, 0x03, 0x09, 0x09, 0x10, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x00, 0x03, + 0x12, 0x03, 0x09, 0x13, 0x14, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x01, 0x02, 0x01, 0x12, 0x03, 0x0a, + 0x02, 0x12, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x01, 0x05, 0x12, 0x03, 0x0a, 0x02, 0x08, + 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x01, 0x01, 0x12, 0x03, 0x0a, 0x09, 0x0d, 0x0a, 0x0c, + 0x0a, 0x05, 0x04, 0x01, 0x02, 0x01, 0x03, 0x12, 0x03, 0x0a, 0x10, 0x11, 0x0a, 0x0b, 0x0a, 0x04, + 0x04, 0x01, 0x02, 0x02, 0x12, 0x03, 0x0b, 0x02, 0x14, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, + 0x02, 0x05, 0x12, 0x03, 0x0b, 0x02, 0x08, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x02, 0x01, + 0x12, 0x03, 0x0b, 0x09, 0x0f, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x02, 0x03, 0x12, 0x03, + 0x0b, 0x12, 0x13, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x01, 0x02, 0x03, 0x12, 0x03, 0x0c, 0x02, 0x16, + 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x03, 0x05, 0x12, 0x03, 0x0c, 0x02, 0x08, 0x0a, 0x0c, + 0x0a, 0x05, 0x04, 0x01, 0x02, 0x03, 0x01, 0x12, 0x03, 0x0c, 0x09, 0x11, 0x0a, 0x0c, 0x0a, 0x05, + 0x04, 0x01, 0x02, 0x03, 0x03, 0x12, 0x03, 0x0c, 0x14, 0x15, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x01, + 0x02, 0x04, 0x12, 0x03, 0x0d, 0x02, 0x23, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x04, 0x04, + 0x12, 0x03, 0x0d, 0x02, 0x0a, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x04, 0x05, 0x12, 0x03, + 0x0d, 0x0b, 0x11, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x04, 0x01, 0x12, 0x03, 0x0d, 0x12, + 0x1e, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x04, 0x03, 0x12, 0x03, 0x0d, 0x21, 0x22, 0x0a, + 0x0a, 0x0a, 0x02, 0x04, 0x02, 0x12, 0x04, 0x10, 0x00, 0x12, 0x01, 0x0a, 0x0a, 0x0a, 0x03, 0x04, + 0x02, 0x01, 0x12, 0x03, 0x10, 0x08, 0x11, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x02, 0x02, 0x00, 0x12, + 0x03, 0x11, 0x02, 0x1e, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x02, 0x02, 0x00, 0x04, 0x12, 0x03, 0x11, + 0x02, 0x0a, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x02, 0x02, 0x00, 0x06, 0x12, 0x03, 0x11, 0x0b, 0x13, + 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x02, 0x02, 0x00, 0x01, 0x12, 0x03, 0x11, 0x14, 0x19, 0x0a, 0x0c, + 0x0a, 0x05, 0x04, 0x02, 0x02, 0x00, 0x03, 0x12, 0x03, 0x11, 0x1c, 0x1d, 0x0a, 0x0a, 0x0a, 0x02, + 0x04, 0x03, 0x12, 0x04, 0x14, 0x00, 0x1d, 0x01, 0x0a, 0x0a, 0x0a, 0x03, 0x04, 0x03, 0x01, 0x12, + 0x03, 0x14, 0x08, 0x10, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x03, 0x02, 0x00, 0x12, 0x03, 0x15, 0x02, + 0x15, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x00, 0x05, 0x12, 0x03, 0x15, 0x02, 0x08, 0x0a, + 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x00, 0x01, 0x12, 0x03, 0x15, 0x09, 0x10, 0x0a, 0x0c, 0x0a, + 0x05, 0x04, 0x03, 0x02, 0x00, 0x03, 0x12, 0x03, 0x15, 0x13, 0x14, 0x0a, 0x0b, 0x0a, 0x04, 0x04, + 0x03, 0x02, 0x01, 0x12, 0x03, 0x16, 0x02, 0x17, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x01, + 0x05, 0x12, 0x03, 0x16, 0x02, 0x08, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x01, 0x01, 0x12, + 0x03, 0x16, 0x09, 0x12, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x01, 0x03, 0x12, 0x03, 0x16, + 0x15, 0x16, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x03, 0x02, 0x02, 0x12, 0x03, 0x17, 0x02, 0x19, 0x0a, + 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x02, 0x05, 0x12, 0x03, 0x17, 0x02, 0x08, 0x0a, 0x0c, 0x0a, + 0x05, 0x04, 0x03, 0x02, 0x02, 0x01, 0x12, 0x03, 0x17, 0x09, 0x14, 0x0a, 0x0c, 0x0a, 0x05, 0x04, + 0x03, 0x02, 0x02, 0x03, 0x12, 0x03, 0x17, 0x17, 0x18, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x03, 0x02, + 0x03, 0x12, 0x03, 0x18, 0x02, 0x12, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x03, 0x06, 0x12, + 0x03, 0x18, 0x02, 0x07, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x03, 0x01, 0x12, 0x03, 0x18, + 0x08, 0x0d, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x03, 0x03, 0x12, 0x03, 0x18, 0x10, 0x11, + 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x03, 0x02, 0x04, 0x12, 0x03, 0x19, 0x02, 0x12, 0x0a, 0x0c, 0x0a, + 0x05, 0x04, 0x03, 0x02, 0x04, 0x05, 0x12, 0x03, 0x19, 0x02, 0x08, 0x0a, 0x0c, 0x0a, 0x05, 0x04, + 0x03, 0x02, 0x04, 0x01, 0x12, 0x03, 0x19, 0x09, 0x0d, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, + 0x04, 0x03, 0x12, 0x03, 0x19, 0x10, 0x11, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x03, 0x02, 0x05, 0x12, + 0x03, 0x1a, 0x02, 0x10, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x05, 0x05, 0x12, 0x03, 0x1a, + 0x02, 0x08, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x05, 0x01, 0x12, 0x03, 0x1a, 0x09, 0x0b, + 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x05, 0x03, 0x12, 0x03, 0x1a, 0x0e, 0x0f, 0x0a, 0x2f, + 0x0a, 0x04, 0x04, 0x03, 0x02, 0x06, 0x12, 0x03, 0x1b, 0x02, 0x14, 0x22, 0x22, 0x20, 0x42, 0x69, + 0x67, 0x49, 0x6e, 0x74, 0x2c, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x27, 0x73, + 0x20, 0x6e, 0x61, 0x74, 0x69, 0x76, 0x65, 0x20, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x0a, 0x0a, + 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x06, 0x05, 0x12, 0x03, 0x1b, 0x02, 0x08, 0x0a, 0x0c, 0x0a, + 0x05, 0x04, 0x03, 0x02, 0x06, 0x01, 0x12, 0x03, 0x1b, 0x09, 0x0f, 0x0a, 0x0c, 0x0a, 0x05, 0x04, + 0x03, 0x02, 0x06, 0x03, 0x12, 0x03, 0x1b, 0x12, 0x13, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x03, 0x02, + 0x07, 0x12, 0x03, 0x1c, 0x02, 0x21, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x07, 0x04, 0x12, + 0x03, 0x1c, 0x02, 0x0a, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x07, 0x05, 0x12, 0x03, 0x1c, + 0x0b, 0x11, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x07, 0x01, 0x12, 0x03, 0x1c, 0x12, 0x1c, + 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x07, 0x03, 0x12, 0x03, 0x1c, 0x1f, 0x20, 0x0a, 0x2d, + 0x0a, 0x02, 0x04, 0x04, 0x12, 0x04, 0x20, 0x00, 0x25, 0x01, 0x1a, 0x21, 0x20, 0x73, 0x70, 0x6f, + 0x74, 0x20, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, + 0x20, 0x67, 0x69, 0x76, 0x65, 0x6e, 0x20, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x0a, 0x0a, 0x0a, 0x0a, + 0x03, 0x04, 0x04, 0x01, 0x12, 0x03, 0x20, 0x08, 0x14, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x04, 0x02, + 0x00, 0x12, 0x03, 0x21, 0x02, 0x12, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x04, 0x02, 0x00, 0x06, 0x12, + 0x03, 0x21, 0x02, 0x07, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x04, 0x02, 0x00, 0x01, 0x12, 0x03, 0x21, + 0x08, 0x0d, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x04, 0x02, 0x00, 0x03, 0x12, 0x03, 0x21, 0x10, 0x11, + 0x0a, 0x2f, 0x0a, 0x04, 0x04, 0x04, 0x02, 0x01, 0x12, 0x03, 0x22, 0x02, 0x15, 0x22, 0x22, 0x20, + 0x42, 0x69, 0x67, 0x49, 0x6e, 0x74, 0x2c, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x6f, 0x6b, 0x65, 0x6e, + 0x27, 0x73, 0x20, 0x6e, 0x61, 0x74, 0x69, 0x76, 0x65, 0x20, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, + 0x0a, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x04, 0x02, 0x01, 0x05, 0x12, 0x03, 0x22, 0x02, 0x08, 0x0a, + 0x0c, 0x0a, 0x05, 0x04, 0x04, 0x02, 0x01, 0x01, 0x12, 0x03, 0x22, 0x09, 0x10, 0x0a, 0x0c, 0x0a, + 0x05, 0x04, 0x04, 0x02, 0x01, 0x03, 0x12, 0x03, 0x22, 0x13, 0x14, 0x0a, 0x0b, 0x0a, 0x04, 0x04, + 0x04, 0x02, 0x02, 0x12, 0x03, 0x23, 0x02, 0x1a, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x04, 0x02, 0x02, + 0x05, 0x12, 0x03, 0x23, 0x02, 0x08, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x04, 0x02, 0x02, 0x01, 0x12, + 0x03, 0x23, 0x09, 0x15, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x04, 0x02, 0x02, 0x03, 0x12, 0x03, 0x23, + 0x18, 0x19, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x04, 0x02, 0x03, 0x12, 0x03, 0x24, 0x02, 0x17, 0x0a, + 0x0c, 0x0a, 0x05, 0x04, 0x04, 0x02, 0x03, 0x05, 0x12, 0x03, 0x24, 0x02, 0x08, 0x0a, 0x0c, 0x0a, + 0x05, 0x04, 0x04, 0x02, 0x03, 0x01, 0x12, 0x03, 0x24, 0x09, 0x12, 0x0a, 0x0c, 0x0a, 0x05, 0x04, + 0x04, 0x02, 0x03, 0x03, 0x12, 0x03, 0x24, 0x15, 0x16, 0x0a, 0x0a, 0x0a, 0x02, 0x04, 0x05, 0x12, + 0x04, 0x27, 0x00, 0x2a, 0x01, 0x0a, 0x0a, 0x0a, 0x03, 0x04, 0x05, 0x01, 0x12, 0x03, 0x27, 0x08, + 0x0f, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x05, 0x02, 0x00, 0x12, 0x03, 0x28, 0x02, 0x15, 0x0a, 0x0c, + 0x0a, 0x05, 0x04, 0x05, 0x02, 0x00, 0x05, 0x12, 0x03, 0x28, 0x02, 0x08, 0x0a, 0x0c, 0x0a, 0x05, + 0x04, 0x05, 0x02, 0x00, 0x01, 0x12, 0x03, 0x28, 0x09, 0x10, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x05, + 0x02, 0x00, 0x03, 0x12, 0x03, 0x28, 0x13, 0x14, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x05, 0x02, 0x01, + 0x12, 0x03, 0x29, 0x02, 0x25, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x05, 0x02, 0x01, 0x04, 0x12, 0x03, + 0x29, 0x02, 0x0a, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x05, 0x02, 0x01, 0x06, 0x12, 0x03, 0x29, 0x0b, + 0x17, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x05, 0x02, 0x01, 0x01, 0x12, 0x03, 0x29, 0x18, 0x20, 0x0a, + 0x0c, 0x0a, 0x05, 0x04, 0x05, 0x02, 0x01, 0x03, 0x12, 0x03, 0x29, 0x23, 0x24, 0x0a, 0x0a, 0x0a, + 0x02, 0x04, 0x06, 0x12, 0x04, 0x2c, 0x00, 0x2e, 0x01, 0x0a, 0x0a, 0x0a, 0x03, 0x04, 0x06, 0x01, + 0x12, 0x03, 0x2c, 0x08, 0x10, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x06, 0x02, 0x00, 0x12, 0x03, 0x2d, + 0x02, 0x1d, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x06, 0x02, 0x00, 0x04, 0x12, 0x03, 0x2d, 0x02, 0x0a, + 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x06, 0x02, 0x00, 0x06, 0x12, 0x03, 0x2d, 0x0b, 0x12, 0x0a, 0x0c, + 0x0a, 0x05, 0x04, 0x06, 0x02, 0x00, 0x01, 0x12, 0x03, 0x2d, 0x13, 0x18, 0x0a, 0x0c, 0x0a, 0x05, + 0x04, 0x06, 0x02, 0x00, 0x03, 0x12, 0x03, 0x2d, 0x1b, 0x1c, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, +]; +// @@protoc_insertion_point(module) \ No newline at end of file diff --git a/substreams-helper/src/token.rs b/substreams-helper/src/token.rs index eeb5172c..0a06a38a 100644 --- a/substreams-helper/src/token.rs +++ b/substreams-helper/src/token.rs @@ -1,4 +1,4 @@ -use crate::pb::evm_token::v1::Token; +use substream pub fn get_eth_token() -> Option { let eth_token = Token { diff --git a/substreams-helper/substreams.yaml b/substreams-helper/substreams.yaml new file mode 100644 index 00000000..882ad016 --- /dev/null +++ b/substreams-helper/substreams.yaml @@ -0,0 +1,19 @@ +specVersion: v0.1.0 +package: + name: substreams_helper + version: v0.1.0 + +imports: + eth: https://github.com/streamingfast/sf-ethereum/releases/download/v0.10.2/ethereum-v0.10.4.spkg + +protobuf: + files: + - evm_token.proto + importPaths: + - ../common/proto + +binaries: + default: + type: wasm/rust-v1 + file: "../target/wasm32-unknown-unknown/release/substreams_helper.wasm" + From d27155e9de0c42febfd4fd705bc5c03be2f0bb10 Mon Sep 17 00:00:00 2001 From: dmelotik Date: Wed, 11 Jan 2023 17:26:43 -0700 Subject: [PATCH 11/25] backup changes made to get pb to generate :( --- substreams-helper/Makefile | 4 - substreams-helper/src/pb.rs | 9 - .../src/pb/messari.evm_token.v1.rs | 232 ------------------ substreams-helper/src/token.rs | 2 +- 4 files changed, 1 insertion(+), 246 deletions(-) delete mode 100644 substreams-helper/src/pb.rs delete mode 100644 substreams-helper/src/pb/messari.evm_token.v1.rs diff --git a/substreams-helper/Makefile b/substreams-helper/Makefile index 354cce6d..f991fe2f 100644 --- a/substreams-helper/Makefile +++ b/substreams-helper/Makefile @@ -1,7 +1,3 @@ -.PHONY: codegen -codegen: - substreams protogen ./substreams.yaml --exclude-paths="sf/ethereum,sf/substreams,google" - .PHONY: build build: cargo build --target wasm32-unknown-unknown --release diff --git a/substreams-helper/src/pb.rs b/substreams-helper/src/pb.rs deleted file mode 100644 index 2b6dbd63..00000000 --- a/substreams-helper/src/pb.rs +++ /dev/null @@ -1,9 +0,0 @@ -#[rustfmt::skip] -#[path = "../target/pb/messari.evm_token.v1.rs"] -pub(in crate::pb) mod evm_token_v1; - -pub mod evm_token { - pub mod v1 { - pub use super::super::evm_token_v1::*; - } -} diff --git a/substreams-helper/src/pb/messari.evm_token.v1.rs b/substreams-helper/src/pb/messari.evm_token.v1.rs deleted file mode 100644 index 6f0a137c..00000000 --- a/substreams-helper/src/pb/messari.evm_token.v1.rs +++ /dev/null @@ -1,232 +0,0 @@ -// @generated -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct Tokens { - #[prost(message, repeated, tag="1")] - pub items: ::prost::alloc::vec::Vec, -} -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct Token { - #[prost(string, tag="1")] - pub address: ::prost::alloc::string::String, - #[prost(string, tag="2")] - pub name: ::prost::alloc::string::String, - #[prost(string, tag="3")] - pub symbol: ::prost::alloc::string::String, - #[prost(uint64, tag="4")] - pub decimals: u64, - #[prost(string, optional, tag="5")] - pub total_supply: ::core::option::Option<::prost::alloc::string::String>, -} -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct Transfers { - #[prost(message, repeated, tag="1")] - pub items: ::prost::alloc::vec::Vec, -} -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct Transfer { - #[prost(string, tag="1")] - pub tx_hash: ::prost::alloc::string::String, - #[prost(uint32, tag="2")] - pub log_index: u32, - #[prost(uint64, tag="3")] - pub log_ordinal: u64, - #[prost(message, optional, tag="4")] - pub token: ::core::option::Option, - #[prost(string, tag="5")] - pub from: ::prost::alloc::string::String, - #[prost(string, tag="6")] - pub to: ::prost::alloc::string::String, - /// BigInt, in token's native amount - #[prost(string, tag="7")] - pub amount: ::prost::alloc::string::String, - #[prost(string, optional, tag="8")] - pub amount_usd: ::core::option::Option<::prost::alloc::string::String>, -} -/// spot balance of the given token -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct TokenBalance { - #[prost(message, optional, tag="1")] - pub token: ::core::option::Option, - /// BigInt, in token's native amount - #[prost(string, tag="2")] - pub balance: ::prost::alloc::string::String, - #[prost(uint64, tag="3")] - pub block_number: u64, - #[prost(uint64, tag="4")] - pub timestamp: u64, -} -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct Account { - #[prost(string, tag="1")] - pub address: ::prost::alloc::string::String, - #[prost(message, repeated, tag="2")] - pub balances: ::prost::alloc::vec::Vec, -} -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct Accounts { - #[prost(message, repeated, tag="1")] - pub items: ::prost::alloc::vec::Vec, -} -/// Encoded file descriptor set for the `messari.evm_token.v1` package -pub const FILE_DESCRIPTOR_SET: &[u8] = &[ - 0x0a, 0xdf, 0x13, 0x0a, 0x0f, 0x65, 0x76, 0x6d, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x14, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x72, 0x69, 0x2e, 0x65, 0x76, - 0x6d, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x22, 0x3b, 0x0a, 0x06, 0x54, 0x6f, - 0x6b, 0x65, 0x6e, 0x73, 0x12, 0x31, 0x0a, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x18, 0x01, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x72, 0x69, 0x2e, 0x65, 0x76, - 0x6d, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, - 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x22, 0xa2, 0x01, 0x0a, 0x05, 0x54, 0x6f, 0x6b, 0x65, - 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x6e, - 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, - 0x16, 0x0a, 0x06, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x06, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x63, 0x69, 0x6d, - 0x61, 0x6c, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x64, 0x65, 0x63, 0x69, 0x6d, - 0x61, 0x6c, 0x73, 0x12, 0x26, 0x0a, 0x0c, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x5f, 0x73, 0x75, 0x70, - 0x70, 0x6c, 0x79, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x0b, 0x74, 0x6f, 0x74, - 0x61, 0x6c, 0x53, 0x75, 0x70, 0x70, 0x6c, 0x79, 0x88, 0x01, 0x01, 0x42, 0x0f, 0x0a, 0x0d, 0x5f, - 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x5f, 0x73, 0x75, 0x70, 0x70, 0x6c, 0x79, 0x22, 0x41, 0x0a, 0x09, - 0x54, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 0x73, 0x12, 0x34, 0x0a, 0x05, 0x69, 0x74, 0x65, - 0x6d, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, - 0x72, 0x69, 0x2e, 0x65, 0x76, 0x6d, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, - 0x54, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x22, - 0x83, 0x02, 0x0a, 0x08, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 0x12, 0x17, 0x0a, 0x07, - 0x74, 0x78, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x74, - 0x78, 0x48, 0x61, 0x73, 0x68, 0x12, 0x1b, 0x0a, 0x09, 0x6c, 0x6f, 0x67, 0x5f, 0x69, 0x6e, 0x64, - 0x65, 0x78, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x6c, 0x6f, 0x67, 0x49, 0x6e, 0x64, - 0x65, 0x78, 0x12, 0x1f, 0x0a, 0x0b, 0x6c, 0x6f, 0x67, 0x5f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, - 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0a, 0x6c, 0x6f, 0x67, 0x4f, 0x72, 0x64, 0x69, - 0x6e, 0x61, 0x6c, 0x12, 0x31, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x04, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x72, 0x69, 0x2e, 0x65, 0x76, 0x6d, - 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, - 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x72, 0x6f, 0x6d, 0x18, 0x05, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x66, 0x72, 0x6f, 0x6d, 0x12, 0x0e, 0x0a, 0x02, 0x74, 0x6f, - 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x74, 0x6f, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x6d, - 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x61, 0x6d, 0x6f, 0x75, - 0x6e, 0x74, 0x12, 0x22, 0x0a, 0x0a, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x75, 0x73, 0x64, - 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x09, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, - 0x55, 0x73, 0x64, 0x88, 0x01, 0x01, 0x42, 0x0d, 0x0a, 0x0b, 0x5f, 0x61, 0x6d, 0x6f, 0x75, 0x6e, - 0x74, 0x5f, 0x75, 0x73, 0x64, 0x22, 0x9c, 0x01, 0x0a, 0x0c, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x42, - 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x31, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x72, 0x69, 0x2e, - 0x65, 0x76, 0x6d, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x6f, 0x6b, - 0x65, 0x6e, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x62, 0x61, 0x6c, - 0x61, 0x6e, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x62, 0x61, 0x6c, 0x61, - 0x6e, 0x63, 0x65, 0x12, 0x21, 0x0a, 0x0c, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x6e, 0x75, 0x6d, - 0x62, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0b, 0x62, 0x6c, 0x6f, 0x63, 0x6b, - 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, - 0x61, 0x6d, 0x70, 0x18, 0x04, 0x20, 0x01, 0x28, 0x04, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, - 0x74, 0x61, 0x6d, 0x70, 0x22, 0x63, 0x0a, 0x07, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, - 0x18, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x3e, 0x0a, 0x08, 0x62, 0x61, 0x6c, - 0x61, 0x6e, 0x63, 0x65, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x22, 0x2e, 0x6d, 0x65, - 0x73, 0x73, 0x61, 0x72, 0x69, 0x2e, 0x65, 0x76, 0x6d, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, - 0x76, 0x31, 0x2e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, - 0x08, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x73, 0x22, 0x3f, 0x0a, 0x08, 0x41, 0x63, 0x63, - 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x12, 0x33, 0x0a, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x18, 0x01, - 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x72, 0x69, 0x2e, 0x65, - 0x76, 0x6d, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x63, 0x63, 0x6f, - 0x75, 0x6e, 0x74, 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x4a, 0xbd, 0x0c, 0x0a, 0x06, 0x12, - 0x04, 0x00, 0x00, 0x2e, 0x01, 0x0a, 0x08, 0x0a, 0x01, 0x0c, 0x12, 0x03, 0x00, 0x00, 0x12, 0x0a, - 0x08, 0x0a, 0x01, 0x02, 0x12, 0x03, 0x02, 0x00, 0x1d, 0x0a, 0x0a, 0x0a, 0x02, 0x04, 0x00, 0x12, - 0x04, 0x04, 0x00, 0x06, 0x01, 0x0a, 0x0a, 0x0a, 0x03, 0x04, 0x00, 0x01, 0x12, 0x03, 0x04, 0x08, - 0x0e, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x00, 0x02, 0x00, 0x12, 0x03, 0x05, 0x02, 0x1b, 0x0a, 0x0c, - 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, 0x04, 0x12, 0x03, 0x05, 0x02, 0x0a, 0x0a, 0x0c, 0x0a, 0x05, - 0x04, 0x00, 0x02, 0x00, 0x06, 0x12, 0x03, 0x05, 0x0b, 0x10, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, - 0x02, 0x00, 0x01, 0x12, 0x03, 0x05, 0x11, 0x16, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, - 0x03, 0x12, 0x03, 0x05, 0x19, 0x1a, 0x0a, 0x0a, 0x0a, 0x02, 0x04, 0x01, 0x12, 0x04, 0x08, 0x00, - 0x0e, 0x01, 0x0a, 0x0a, 0x0a, 0x03, 0x04, 0x01, 0x01, 0x12, 0x03, 0x08, 0x08, 0x0d, 0x0a, 0x0b, - 0x0a, 0x04, 0x04, 0x01, 0x02, 0x00, 0x12, 0x03, 0x09, 0x02, 0x15, 0x0a, 0x0c, 0x0a, 0x05, 0x04, - 0x01, 0x02, 0x00, 0x05, 0x12, 0x03, 0x09, 0x02, 0x08, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, - 0x00, 0x01, 0x12, 0x03, 0x09, 0x09, 0x10, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x00, 0x03, - 0x12, 0x03, 0x09, 0x13, 0x14, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x01, 0x02, 0x01, 0x12, 0x03, 0x0a, - 0x02, 0x12, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x01, 0x05, 0x12, 0x03, 0x0a, 0x02, 0x08, - 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x01, 0x01, 0x12, 0x03, 0x0a, 0x09, 0x0d, 0x0a, 0x0c, - 0x0a, 0x05, 0x04, 0x01, 0x02, 0x01, 0x03, 0x12, 0x03, 0x0a, 0x10, 0x11, 0x0a, 0x0b, 0x0a, 0x04, - 0x04, 0x01, 0x02, 0x02, 0x12, 0x03, 0x0b, 0x02, 0x14, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, - 0x02, 0x05, 0x12, 0x03, 0x0b, 0x02, 0x08, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x02, 0x01, - 0x12, 0x03, 0x0b, 0x09, 0x0f, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x02, 0x03, 0x12, 0x03, - 0x0b, 0x12, 0x13, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x01, 0x02, 0x03, 0x12, 0x03, 0x0c, 0x02, 0x16, - 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x03, 0x05, 0x12, 0x03, 0x0c, 0x02, 0x08, 0x0a, 0x0c, - 0x0a, 0x05, 0x04, 0x01, 0x02, 0x03, 0x01, 0x12, 0x03, 0x0c, 0x09, 0x11, 0x0a, 0x0c, 0x0a, 0x05, - 0x04, 0x01, 0x02, 0x03, 0x03, 0x12, 0x03, 0x0c, 0x14, 0x15, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x01, - 0x02, 0x04, 0x12, 0x03, 0x0d, 0x02, 0x23, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x04, 0x04, - 0x12, 0x03, 0x0d, 0x02, 0x0a, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x04, 0x05, 0x12, 0x03, - 0x0d, 0x0b, 0x11, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x04, 0x01, 0x12, 0x03, 0x0d, 0x12, - 0x1e, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x04, 0x03, 0x12, 0x03, 0x0d, 0x21, 0x22, 0x0a, - 0x0a, 0x0a, 0x02, 0x04, 0x02, 0x12, 0x04, 0x10, 0x00, 0x12, 0x01, 0x0a, 0x0a, 0x0a, 0x03, 0x04, - 0x02, 0x01, 0x12, 0x03, 0x10, 0x08, 0x11, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x02, 0x02, 0x00, 0x12, - 0x03, 0x11, 0x02, 0x1e, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x02, 0x02, 0x00, 0x04, 0x12, 0x03, 0x11, - 0x02, 0x0a, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x02, 0x02, 0x00, 0x06, 0x12, 0x03, 0x11, 0x0b, 0x13, - 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x02, 0x02, 0x00, 0x01, 0x12, 0x03, 0x11, 0x14, 0x19, 0x0a, 0x0c, - 0x0a, 0x05, 0x04, 0x02, 0x02, 0x00, 0x03, 0x12, 0x03, 0x11, 0x1c, 0x1d, 0x0a, 0x0a, 0x0a, 0x02, - 0x04, 0x03, 0x12, 0x04, 0x14, 0x00, 0x1d, 0x01, 0x0a, 0x0a, 0x0a, 0x03, 0x04, 0x03, 0x01, 0x12, - 0x03, 0x14, 0x08, 0x10, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x03, 0x02, 0x00, 0x12, 0x03, 0x15, 0x02, - 0x15, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x00, 0x05, 0x12, 0x03, 0x15, 0x02, 0x08, 0x0a, - 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x00, 0x01, 0x12, 0x03, 0x15, 0x09, 0x10, 0x0a, 0x0c, 0x0a, - 0x05, 0x04, 0x03, 0x02, 0x00, 0x03, 0x12, 0x03, 0x15, 0x13, 0x14, 0x0a, 0x0b, 0x0a, 0x04, 0x04, - 0x03, 0x02, 0x01, 0x12, 0x03, 0x16, 0x02, 0x17, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x01, - 0x05, 0x12, 0x03, 0x16, 0x02, 0x08, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x01, 0x01, 0x12, - 0x03, 0x16, 0x09, 0x12, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x01, 0x03, 0x12, 0x03, 0x16, - 0x15, 0x16, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x03, 0x02, 0x02, 0x12, 0x03, 0x17, 0x02, 0x19, 0x0a, - 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x02, 0x05, 0x12, 0x03, 0x17, 0x02, 0x08, 0x0a, 0x0c, 0x0a, - 0x05, 0x04, 0x03, 0x02, 0x02, 0x01, 0x12, 0x03, 0x17, 0x09, 0x14, 0x0a, 0x0c, 0x0a, 0x05, 0x04, - 0x03, 0x02, 0x02, 0x03, 0x12, 0x03, 0x17, 0x17, 0x18, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x03, 0x02, - 0x03, 0x12, 0x03, 0x18, 0x02, 0x12, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x03, 0x06, 0x12, - 0x03, 0x18, 0x02, 0x07, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x03, 0x01, 0x12, 0x03, 0x18, - 0x08, 0x0d, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x03, 0x03, 0x12, 0x03, 0x18, 0x10, 0x11, - 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x03, 0x02, 0x04, 0x12, 0x03, 0x19, 0x02, 0x12, 0x0a, 0x0c, 0x0a, - 0x05, 0x04, 0x03, 0x02, 0x04, 0x05, 0x12, 0x03, 0x19, 0x02, 0x08, 0x0a, 0x0c, 0x0a, 0x05, 0x04, - 0x03, 0x02, 0x04, 0x01, 0x12, 0x03, 0x19, 0x09, 0x0d, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, - 0x04, 0x03, 0x12, 0x03, 0x19, 0x10, 0x11, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x03, 0x02, 0x05, 0x12, - 0x03, 0x1a, 0x02, 0x10, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x05, 0x05, 0x12, 0x03, 0x1a, - 0x02, 0x08, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x05, 0x01, 0x12, 0x03, 0x1a, 0x09, 0x0b, - 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x05, 0x03, 0x12, 0x03, 0x1a, 0x0e, 0x0f, 0x0a, 0x2f, - 0x0a, 0x04, 0x04, 0x03, 0x02, 0x06, 0x12, 0x03, 0x1b, 0x02, 0x14, 0x22, 0x22, 0x20, 0x42, 0x69, - 0x67, 0x49, 0x6e, 0x74, 0x2c, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x27, 0x73, - 0x20, 0x6e, 0x61, 0x74, 0x69, 0x76, 0x65, 0x20, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x0a, 0x0a, - 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x06, 0x05, 0x12, 0x03, 0x1b, 0x02, 0x08, 0x0a, 0x0c, 0x0a, - 0x05, 0x04, 0x03, 0x02, 0x06, 0x01, 0x12, 0x03, 0x1b, 0x09, 0x0f, 0x0a, 0x0c, 0x0a, 0x05, 0x04, - 0x03, 0x02, 0x06, 0x03, 0x12, 0x03, 0x1b, 0x12, 0x13, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x03, 0x02, - 0x07, 0x12, 0x03, 0x1c, 0x02, 0x21, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x07, 0x04, 0x12, - 0x03, 0x1c, 0x02, 0x0a, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x07, 0x05, 0x12, 0x03, 0x1c, - 0x0b, 0x11, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x07, 0x01, 0x12, 0x03, 0x1c, 0x12, 0x1c, - 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x07, 0x03, 0x12, 0x03, 0x1c, 0x1f, 0x20, 0x0a, 0x2d, - 0x0a, 0x02, 0x04, 0x04, 0x12, 0x04, 0x20, 0x00, 0x25, 0x01, 0x1a, 0x21, 0x20, 0x73, 0x70, 0x6f, - 0x74, 0x20, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, - 0x20, 0x67, 0x69, 0x76, 0x65, 0x6e, 0x20, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x0a, 0x0a, 0x0a, 0x0a, - 0x03, 0x04, 0x04, 0x01, 0x12, 0x03, 0x20, 0x08, 0x14, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x04, 0x02, - 0x00, 0x12, 0x03, 0x21, 0x02, 0x12, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x04, 0x02, 0x00, 0x06, 0x12, - 0x03, 0x21, 0x02, 0x07, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x04, 0x02, 0x00, 0x01, 0x12, 0x03, 0x21, - 0x08, 0x0d, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x04, 0x02, 0x00, 0x03, 0x12, 0x03, 0x21, 0x10, 0x11, - 0x0a, 0x2f, 0x0a, 0x04, 0x04, 0x04, 0x02, 0x01, 0x12, 0x03, 0x22, 0x02, 0x15, 0x22, 0x22, 0x20, - 0x42, 0x69, 0x67, 0x49, 0x6e, 0x74, 0x2c, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x6f, 0x6b, 0x65, 0x6e, - 0x27, 0x73, 0x20, 0x6e, 0x61, 0x74, 0x69, 0x76, 0x65, 0x20, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, - 0x0a, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x04, 0x02, 0x01, 0x05, 0x12, 0x03, 0x22, 0x02, 0x08, 0x0a, - 0x0c, 0x0a, 0x05, 0x04, 0x04, 0x02, 0x01, 0x01, 0x12, 0x03, 0x22, 0x09, 0x10, 0x0a, 0x0c, 0x0a, - 0x05, 0x04, 0x04, 0x02, 0x01, 0x03, 0x12, 0x03, 0x22, 0x13, 0x14, 0x0a, 0x0b, 0x0a, 0x04, 0x04, - 0x04, 0x02, 0x02, 0x12, 0x03, 0x23, 0x02, 0x1a, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x04, 0x02, 0x02, - 0x05, 0x12, 0x03, 0x23, 0x02, 0x08, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x04, 0x02, 0x02, 0x01, 0x12, - 0x03, 0x23, 0x09, 0x15, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x04, 0x02, 0x02, 0x03, 0x12, 0x03, 0x23, - 0x18, 0x19, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x04, 0x02, 0x03, 0x12, 0x03, 0x24, 0x02, 0x17, 0x0a, - 0x0c, 0x0a, 0x05, 0x04, 0x04, 0x02, 0x03, 0x05, 0x12, 0x03, 0x24, 0x02, 0x08, 0x0a, 0x0c, 0x0a, - 0x05, 0x04, 0x04, 0x02, 0x03, 0x01, 0x12, 0x03, 0x24, 0x09, 0x12, 0x0a, 0x0c, 0x0a, 0x05, 0x04, - 0x04, 0x02, 0x03, 0x03, 0x12, 0x03, 0x24, 0x15, 0x16, 0x0a, 0x0a, 0x0a, 0x02, 0x04, 0x05, 0x12, - 0x04, 0x27, 0x00, 0x2a, 0x01, 0x0a, 0x0a, 0x0a, 0x03, 0x04, 0x05, 0x01, 0x12, 0x03, 0x27, 0x08, - 0x0f, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x05, 0x02, 0x00, 0x12, 0x03, 0x28, 0x02, 0x15, 0x0a, 0x0c, - 0x0a, 0x05, 0x04, 0x05, 0x02, 0x00, 0x05, 0x12, 0x03, 0x28, 0x02, 0x08, 0x0a, 0x0c, 0x0a, 0x05, - 0x04, 0x05, 0x02, 0x00, 0x01, 0x12, 0x03, 0x28, 0x09, 0x10, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x05, - 0x02, 0x00, 0x03, 0x12, 0x03, 0x28, 0x13, 0x14, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x05, 0x02, 0x01, - 0x12, 0x03, 0x29, 0x02, 0x25, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x05, 0x02, 0x01, 0x04, 0x12, 0x03, - 0x29, 0x02, 0x0a, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x05, 0x02, 0x01, 0x06, 0x12, 0x03, 0x29, 0x0b, - 0x17, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x05, 0x02, 0x01, 0x01, 0x12, 0x03, 0x29, 0x18, 0x20, 0x0a, - 0x0c, 0x0a, 0x05, 0x04, 0x05, 0x02, 0x01, 0x03, 0x12, 0x03, 0x29, 0x23, 0x24, 0x0a, 0x0a, 0x0a, - 0x02, 0x04, 0x06, 0x12, 0x04, 0x2c, 0x00, 0x2e, 0x01, 0x0a, 0x0a, 0x0a, 0x03, 0x04, 0x06, 0x01, - 0x12, 0x03, 0x2c, 0x08, 0x10, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x06, 0x02, 0x00, 0x12, 0x03, 0x2d, - 0x02, 0x1d, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x06, 0x02, 0x00, 0x04, 0x12, 0x03, 0x2d, 0x02, 0x0a, - 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x06, 0x02, 0x00, 0x06, 0x12, 0x03, 0x2d, 0x0b, 0x12, 0x0a, 0x0c, - 0x0a, 0x05, 0x04, 0x06, 0x02, 0x00, 0x01, 0x12, 0x03, 0x2d, 0x13, 0x18, 0x0a, 0x0c, 0x0a, 0x05, - 0x04, 0x06, 0x02, 0x00, 0x03, 0x12, 0x03, 0x2d, 0x1b, 0x1c, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x33, -]; -// @@protoc_insertion_point(module) \ No newline at end of file diff --git a/substreams-helper/src/token.rs b/substreams-helper/src/token.rs index 0a06a38a..8c7d1565 100644 --- a/substreams-helper/src/token.rs +++ b/substreams-helper/src/token.rs @@ -1,4 +1,4 @@ -use substream + pub fn get_eth_token() -> Option { let eth_token = Token { From 9f344cf972312863aa271822a4be2a32e8ba618b Mon Sep 17 00:00:00 2001 From: dmelotik Date: Wed, 11 Jan 2023 18:38:53 -0700 Subject: [PATCH 12/25] get autogen to work! --- eth-balance/src/lib.rs | 11 ++++++++--- substreams-helper/build.rs | 2 ++ substreams-helper/src/lib.rs | 1 + substreams-helper/src/pb.rs | 9 +++++++++ substreams-helper/src/token.rs | 2 +- substreams-helper/substreams.yaml | 1 - 6 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 substreams-helper/src/pb.rs diff --git a/eth-balance/src/lib.rs b/eth-balance/src/lib.rs index 57540432..02e00deb 100644 --- a/eth-balance/src/lib.rs +++ b/eth-balance/src/lib.rs @@ -1,7 +1,6 @@ #[rustfmt::skip] pub mod pb; -use crate::pb::evm_token::v1::Token; use num_bigint; use pb::evm_token::v1 as token; use substreams::scalar::BigInt; @@ -9,7 +8,6 @@ use substreams::Hex; use substreams_ethereum::pb::eth as pbeth; use substreams_helper::token::get_eth_token; - #[substreams::handlers::map] fn map_balances(block: pbeth::v2::Block) -> Result { let mut accounts = vec![]; @@ -30,7 +28,14 @@ fn map_balances(block: pbeth::v2::Block) -> Result Result<(), anyhow::Error> { + codegen::generate(None)?; codegen::generate_abi(None)?; + Ok(()) } diff --git a/substreams-helper/src/lib.rs b/substreams-helper/src/lib.rs index 46e38e87..ad0b4954 100644 --- a/substreams-helper/src/lib.rs +++ b/substreams-helper/src/lib.rs @@ -2,6 +2,7 @@ pub mod abi; pub mod erc20; pub mod keyer; pub mod math; +pub mod pb; pub mod price; pub mod token; pub mod types; diff --git a/substreams-helper/src/pb.rs b/substreams-helper/src/pb.rs new file mode 100644 index 00000000..2b6dbd63 --- /dev/null +++ b/substreams-helper/src/pb.rs @@ -0,0 +1,9 @@ +#[rustfmt::skip] +#[path = "../target/pb/messari.evm_token.v1.rs"] +pub(in crate::pb) mod evm_token_v1; + +pub mod evm_token { + pub mod v1 { + pub use super::super::evm_token_v1::*; + } +} diff --git a/substreams-helper/src/token.rs b/substreams-helper/src/token.rs index 8c7d1565..eeb5172c 100644 --- a/substreams-helper/src/token.rs +++ b/substreams-helper/src/token.rs @@ -1,4 +1,4 @@ - +use crate::pb::evm_token::v1::Token; pub fn get_eth_token() -> Option { let eth_token = Token { diff --git a/substreams-helper/substreams.yaml b/substreams-helper/substreams.yaml index 882ad016..9dd7db03 100644 --- a/substreams-helper/substreams.yaml +++ b/substreams-helper/substreams.yaml @@ -16,4 +16,3 @@ binaries: default: type: wasm/rust-v1 file: "../target/wasm32-unknown-unknown/release/substreams_helper.wasm" - From 906326255ca903cdc776ea78f8c4796b80e038be Mon Sep 17 00:00:00 2001 From: dmelotik Date: Thu, 12 Jan 2023 12:39:17 -0700 Subject: [PATCH 13/25] remove codegen command --- eth-balance/Makefile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/eth-balance/Makefile b/eth-balance/Makefile index b780e887..a6a1849d 100644 --- a/eth-balance/Makefile +++ b/eth-balance/Makefile @@ -1,7 +1,3 @@ -.PHONY: codegen -codegen: - substreams protogen ./substreams.yaml --exclude-paths="sf/ethereum,sf/substreams,google" - .PHONY: build build: cargo build --target wasm32-unknown-unknown --release From 1a735705944c0df5d5db7f37bd16b0349d23609e Mon Sep 17 00:00:00 2001 From: dmelotik Date: Tue, 17 Jan 2023 23:31:17 -0700 Subject: [PATCH 14/25] update to new proto definition to be more accomodating of eth block data structure --- common/proto/evm_token.proto | 35 ++++++++---------- eth-balance/src/lib.rs | 61 ++++++++++++++++--------------- eth-balance/substreams.yaml | 2 +- substreams-helper/src/token.rs | 11 ++++++ substreams-helper/substreams.yaml | 1 + 5 files changed, 59 insertions(+), 51 deletions(-) diff --git a/common/proto/evm_token.proto b/common/proto/evm_token.proto index 9ef3ccfa..a27a6f8b 100644 --- a/common/proto/evm_token.proto +++ b/common/proto/evm_token.proto @@ -20,28 +20,23 @@ message Transfers { message Transfer { string tx_hash = 1; - uint32 log_index = 2; - uint64 log_ordinal = 3; - Token token = 4; - string from = 5; + uint64 block_number = 2; + uint64 timestamp = 3; + uint32 log_index = 4; + Token token = 5; string to = 6; - string amount = 7; // BigInt, in token's native amount - optional string amount_usd = 8; + string from = 7; + string amount = 8; // BigInt, in token's native amount + optional string amount_usd = 9; + repeated TokenBalance balance_changes = 10; } -// spot balance of the given token +// balance changes message TokenBalance { - Token token = 1; - string balance = 2; // BigInt, in token's native amount - uint64 block_number = 3; - uint64 timestamp = 4; -} - -message Account { - string address = 1; - repeated TokenBalance balances = 2; -} - -message Accounts { - repeated Account items = 1; + uint64 log_ordinal = 1; + Token token = 2; + string address = 3; // account address of the balance change + string old_balance = 4; // BigInt, in token's native amount + string new_balance = 5; // BigInt, in token's native amount + optional int32 reason = 6; } diff --git a/eth-balance/src/lib.rs b/eth-balance/src/lib.rs index 02e00deb..b79f28b2 100644 --- a/eth-balance/src/lib.rs +++ b/eth-balance/src/lib.rs @@ -6,45 +6,46 @@ use pb::evm_token::v1 as token; use substreams::scalar::BigInt; use substreams::Hex; use substreams_ethereum::pb::eth as pbeth; -use substreams_helper::token::get_eth_token; +use substreams_helper::token as token_helper; #[substreams::handlers::map] -fn map_balances(block: pbeth::v2::Block) -> Result { - let mut accounts = vec![]; +fn map_balances(block: pbeth::v2::Block) -> Result { + let mut transfers = vec![]; for transaction in &block.transaction_traces { + let mut balance_changes = vec![]; for call in &transaction.calls { for balance_change in &call.balance_changes { - // TODO: replace this with substreams::scalar::BigInt once the wrapper is integrated - let new_value = balance_change - .new_value - .as_ref() - .map(|value| { - num_bigint::BigInt::from_bytes_be(num_bigint::Sign::Plus, &value.bytes) - .into() - }) - .unwrap_or(BigInt::zero()); - let new_token_balance = vec![token::TokenBalance { - token: get_eth_token(), - balance: new_value.to_string(), - block_number: block.number, - timestamp: block - .header - .as_ref() - .unwrap() - .timestamp - .as_ref() - .unwrap() - .seconds as u64, - }]; - let account = token::Account { + balance_changes.push(token::TokenBalance { + log_ordinal: balance_change.ordinal, + token: token_helper::get_eth_token(), address: Hex(&balance_change.address).to_string(), - balances: new_token_balance, - }; - accounts.push(account); + old_balance: token_helper::bigint_to_string(balance_change.old_value.clone()), + new_balance: token_helper::bigint_to_string(balance_change.new_value.clone()), + reason: Some(balance_change.reason), + }); } } + transfers.push(token::Transfer { + tx_hash: Hex(&transaction.hash).to_string(), + block_number: block.number, + timestamp: block + .header + .as_ref() + .unwrap() + .timestamp + .as_ref() + .unwrap() + .seconds as u64, + log_index: transaction.index, + token: token_helper::get_eth_token(), + to: Hex(&transaction.to).to_string(), + from: Hex(&transaction.from).to_string(), + amount: token_helper::bigint_to_string(transaction.value.clone()), + amount_usd: None, + balance_changes: balance_changes, + }); } - Ok(token::Accounts { items: accounts }) + Ok(token::Transfers { items: transfers }) } diff --git a/eth-balance/substreams.yaml b/eth-balance/substreams.yaml index 7310d434..aba540d1 100644 --- a/eth-balance/substreams.yaml +++ b/eth-balance/substreams.yaml @@ -24,4 +24,4 @@ modules: inputs: - source: sf.ethereum.type.v2.Block output: - type: proto:messari.evm.token.Account + type: proto:messari.evm.token.Transfers diff --git a/substreams-helper/src/token.rs b/substreams-helper/src/token.rs index eeb5172c..09113a39 100644 --- a/substreams-helper/src/token.rs +++ b/substreams-helper/src/token.rs @@ -1,4 +1,6 @@ use crate::pb::evm_token::v1::Token; +use substreams::scalar::BigInt; +use substreams_ethereum::pb::eth as pbeth; pub fn get_eth_token() -> Option { let eth_token = Token { @@ -11,3 +13,12 @@ pub fn get_eth_token() -> Option { Some(eth_token) } + +// TODO: replace this with substreams::scalar::BigInt once the wrapper is integrated +pub fn bigint_to_string(number: Option) -> String { + "".to_string() + // number + // .as_ref() + // .map(|value| num_bigint::BigInt::from_bytes_be(num_bigint::Sign::Plus, &value.bytes).into()) + // .unwrap_or(BigInt::zero()) +} diff --git a/substreams-helper/substreams.yaml b/substreams-helper/substreams.yaml index 9dd7db03..19746bbd 100644 --- a/substreams-helper/substreams.yaml +++ b/substreams-helper/substreams.yaml @@ -9,6 +9,7 @@ imports: protobuf: files: - evm_token.proto + - importPaths: - ../common/proto From 4a225f716a5a6d82c525675674b43eebef45ee33 Mon Sep 17 00:00:00 2001 From: dmelotik Date: Wed, 18 Jan 2023 09:58:26 -0700 Subject: [PATCH 15/25] Make it run! sweet --- eth-balance/Makefile | 2 +- eth-balance/README.md | 0 eth-balance/src/lib.rs | 5 ++--- substreams-helper/src/token.rs | 12 ++++++------ 4 files changed, 9 insertions(+), 10 deletions(-) create mode 100644 eth-balance/README.md diff --git a/eth-balance/Makefile b/eth-balance/Makefile index a6a1849d..62b10842 100644 --- a/eth-balance/Makefile +++ b/eth-balance/Makefile @@ -4,4 +4,4 @@ build: .PHONY: run run: - substreams run -e mainnet.eth.streamingfast.io:443 substreams.yaml map_balances -s 46977 -t 46980 + substreams run -e mainnet.eth.streamingfast.io:443 substreams.yaml map_balances -s 5350000 -t 5350001 diff --git a/eth-balance/README.md b/eth-balance/README.md new file mode 100644 index 00000000..e69de29b diff --git a/eth-balance/src/lib.rs b/eth-balance/src/lib.rs index b79f28b2..93d64694 100644 --- a/eth-balance/src/lib.rs +++ b/eth-balance/src/lib.rs @@ -1,9 +1,8 @@ #[rustfmt::skip] pub mod pb; -use num_bigint; -use pb::evm_token::v1 as token; -use substreams::scalar::BigInt; +use substreams_helper::pb::evm_token::v1 as token; +// use pb::evm_token::v1 as token; use substreams::Hex; use substreams_ethereum::pb::eth as pbeth; use substreams_helper::token as token_helper; diff --git a/substreams-helper/src/token.rs b/substreams-helper/src/token.rs index 09113a39..106f8a0b 100644 --- a/substreams-helper/src/token.rs +++ b/substreams-helper/src/token.rs @@ -1,4 +1,5 @@ use crate::pb::evm_token::v1::Token; +use num_bigint; use substreams::scalar::BigInt; use substreams_ethereum::pb::eth as pbeth; @@ -15,10 +16,9 @@ pub fn get_eth_token() -> Option { } // TODO: replace this with substreams::scalar::BigInt once the wrapper is integrated -pub fn bigint_to_string(number: Option) -> String { - "".to_string() - // number - // .as_ref() - // .map(|value| num_bigint::BigInt::from_bytes_be(num_bigint::Sign::Plus, &value.bytes).into()) - // .unwrap_or(BigInt::zero()) +pub fn bigint_to_string(number: Option) -> String { + number + .as_ref() + .map(|value| num_bigint::BigInt::from_bytes_be(num_bigint::Sign::Plus, &value.bytes)) + .unwrap_or(BigInt::zero().into()).to_string() } From ccf8fc5d6b45d27c338bf304a5d820560545d57c Mon Sep 17 00:00:00 2001 From: dmelotik Date: Wed, 18 Jan 2023 18:59:55 -0700 Subject: [PATCH 16/25] format token.rs --- substreams-helper/src/token.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/substreams-helper/src/token.rs b/substreams-helper/src/token.rs index 106f8a0b..193c421b 100644 --- a/substreams-helper/src/token.rs +++ b/substreams-helper/src/token.rs @@ -20,5 +20,6 @@ pub fn bigint_to_string(number: Option) -> String { number .as_ref() .map(|value| num_bigint::BigInt::from_bytes_be(num_bigint::Sign::Plus, &value.bytes)) - .unwrap_or(BigInt::zero().into()).to_string() + .unwrap_or(BigInt::zero().into()) + .to_string() } From 9a48a90162d51e63945280ab30bbdd34f82c8d1c Mon Sep 17 00:00:00 2001 From: dmelotik Date: Wed, 18 Jan 2023 21:16:57 -0700 Subject: [PATCH 17/25] add README.md --- eth-balance/README.md | 54 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/eth-balance/README.md b/eth-balance/README.md index e69de29b..f3576746 100644 --- a/eth-balance/README.md +++ b/eth-balance/README.md @@ -0,0 +1,54 @@ +# ETH Balance Substream + +The purpose of this substream is to get a all ETH transferred in every transaction and the following balance changes for various reasons. + +## Data Structure + +Every transaction on ethereum is made a `Transfer` in the `evm_token` proto. A transfer without any "value" will still be available. There should still be eth balance changes from gas at least which we will want to see in the data. + +A snippet of the important proto definitions looks like this: + +```protobuf +message Transfer { + string tx_hash = 1; + uint64 block_number = 2; + uint64 timestamp = 3; + uint32 log_index = 4; + Token token = 5; + string to = 6; + string from = 7; + string amount = 8; // BigInt, in token's native amount + optional string amount_usd = 9; + repeated TokenBalance balance_changes = 10; +} + +// balance changes +message TokenBalance { + uint64 log_ordinal = 1; + Token token = 2; + string address = 3; // account address of the balance change + string old_balance = 4; // BigInt, in token's native amount + string new_balance = 5; // BigInt, in token's native amount + optional int32 reason = 6; +} +``` + +## Notes + +- The only module in this substream is `map_balances` and it takes in eth blocks and maps the balance changes. +- The balance changes have a reason associated with them which provides more context to the data. +- Since we use a map module there is no "back-processing", you can run from any block. See the next section on how to run this on a section of code. + +## Running + +To specify the start and end block that you want to see balances for change the run command in the `Makefile` like this: + +```makefile +substreams run -e mainnet.eth.streamingfast.io:443 substreams.yaml map_balances -s start-block -t end-block +``` + +Then run the command: + +```bash +make run +``` From af3bd1aaffbfac8d815fbe82a44acc6d2cb62418 Mon Sep 17 00:00:00 2001 From: dmelotik Date: Tue, 24 Jan 2023 16:09:32 -0700 Subject: [PATCH 18/25] fix some comments --- .../proto/eth_balance.proto | 1 - eth-balance/src/lib.rs | 10 +- eth-balance/src/pb/messari.token.v1.rs | 217 ------------------ eth-balance/substreams.yaml | 5 +- substreams-helper/src/token.rs | 4 +- substreams-helper/substreams.yaml | 4 +- 6 files changed, 10 insertions(+), 231 deletions(-) rename common/proto/evm_token.proto => eth-balance/proto/eth_balance.proto (96%) delete mode 100644 eth-balance/src/pb/messari.token.v1.rs diff --git a/common/proto/evm_token.proto b/eth-balance/proto/eth_balance.proto similarity index 96% rename from common/proto/evm_token.proto rename to eth-balance/proto/eth_balance.proto index a27a6f8b..36b72779 100644 --- a/common/proto/evm_token.proto +++ b/eth-balance/proto/eth_balance.proto @@ -11,7 +11,6 @@ message Token { string name = 2; string symbol = 3; uint64 decimals = 4; - optional string total_supply = 5; } message Transfers { diff --git a/eth-balance/src/lib.rs b/eth-balance/src/lib.rs index 93d64694..1cd5a715 100644 --- a/eth-balance/src/lib.rs +++ b/eth-balance/src/lib.rs @@ -1,10 +1,8 @@ -#[rustfmt::skip] pub mod pb; -use substreams_helper::pb::evm_token::v1 as token; -// use pb::evm_token::v1 as token; use substreams::Hex; use substreams_ethereum::pb::eth as pbeth; +use substreams_helper::pb::evm_token::v1 as token; use substreams_helper::token as token_helper; #[substreams::handlers::map] @@ -26,7 +24,7 @@ fn map_balances(block: pbeth::v2::Block) -> Result Result, -} -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct Token { - #[prost(string, tag="1")] - pub address: ::prost::alloc::string::String, - #[prost(string, tag="2")] - pub name: ::prost::alloc::string::String, - #[prost(string, tag="3")] - pub symbol: ::prost::alloc::string::String, - #[prost(uint64, tag="4")] - pub decimals: u64, -} -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct Transfers { - #[prost(message, repeated, tag="1")] - pub items: ::prost::alloc::vec::Vec, -} -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct Transfer { - #[prost(string, tag="1")] - pub tx_hash: ::prost::alloc::string::String, - #[prost(uint32, optional, tag="2")] - pub log_index: ::core::option::Option, - #[prost(uint64, optional, tag="3")] - pub log_ordinal: ::core::option::Option, - #[prost(message, optional, tag="4")] - pub token: ::core::option::Option, - #[prost(string, tag="5")] - pub from: ::prost::alloc::string::String, - #[prost(string, tag="6")] - pub to: ::prost::alloc::string::String, - /// BigInt, in token's native amount - #[prost(string, tag="7")] - pub amount: ::prost::alloc::string::String, - #[prost(string, optional, tag="8")] - pub amount_usd: ::core::option::Option<::prost::alloc::string::String>, - #[prost(string, optional, tag="9")] - pub reason: ::core::option::Option<::prost::alloc::string::String>, -} -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct TokenBalance { - #[prost(message, optional, tag="1")] - pub token: ::core::option::Option, - /// BigInt, in token's native amount - #[prost(string, tag="2")] - pub balance: ::prost::alloc::string::String, -} -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct Account { - #[prost(string, tag="1")] - pub address: ::prost::alloc::string::String, - #[prost(message, repeated, tag="2")] - pub balances: ::prost::alloc::vec::Vec, -} -/// TODO: do we need this? -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct Accounts { - #[prost(message, repeated, tag="1")] - pub items: ::prost::alloc::vec::Vec, -} -/// Encoded file descriptor set for the `messari.token.v1` package -pub const FILE_DESCRIPTOR_SET: &[u8] = &[ - 0x0a, 0xb8, 0x12, 0x0a, 0x0b, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x12, 0x10, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x72, 0x69, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, - 0x76, 0x31, 0x22, 0x37, 0x0a, 0x06, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x12, 0x2d, 0x0a, 0x05, - 0x69, 0x74, 0x65, 0x6d, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x6d, 0x65, - 0x73, 0x73, 0x61, 0x72, 0x69, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x54, - 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x22, 0x69, 0x0a, 0x05, 0x54, - 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x12, - 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, - 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x18, 0x03, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x06, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, - 0x63, 0x69, 0x6d, 0x61, 0x6c, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x64, 0x65, - 0x63, 0x69, 0x6d, 0x61, 0x6c, 0x73, 0x22, 0x3d, 0x0a, 0x09, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x66, - 0x65, 0x72, 0x73, 0x12, 0x30, 0x0a, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x18, 0x01, 0x20, 0x03, - 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x72, 0x69, 0x2e, 0x74, 0x6f, 0x6b, - 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 0x52, 0x05, - 0x69, 0x74, 0x65, 0x6d, 0x73, 0x22, 0xcf, 0x02, 0x0a, 0x08, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x66, - 0x65, 0x72, 0x12, 0x17, 0x0a, 0x07, 0x74, 0x78, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x06, 0x74, 0x78, 0x48, 0x61, 0x73, 0x68, 0x12, 0x20, 0x0a, 0x09, 0x6c, - 0x6f, 0x67, 0x5f, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x48, 0x00, - 0x52, 0x08, 0x6c, 0x6f, 0x67, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x88, 0x01, 0x01, 0x12, 0x24, 0x0a, - 0x0b, 0x6c, 0x6f, 0x67, 0x5f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x6c, 0x18, 0x03, 0x20, 0x01, - 0x28, 0x04, 0x48, 0x01, 0x52, 0x0a, 0x6c, 0x6f, 0x67, 0x4f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x6c, - 0x88, 0x01, 0x01, 0x12, 0x2d, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x04, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x72, 0x69, 0x2e, 0x74, 0x6f, 0x6b, - 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x05, 0x74, 0x6f, 0x6b, - 0x65, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x72, 0x6f, 0x6d, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x04, 0x66, 0x72, 0x6f, 0x6d, 0x12, 0x0e, 0x0a, 0x02, 0x74, 0x6f, 0x18, 0x06, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x02, 0x74, 0x6f, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, - 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x22, - 0x0a, 0x0a, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x75, 0x73, 0x64, 0x18, 0x08, 0x20, 0x01, - 0x28, 0x09, 0x48, 0x02, 0x52, 0x09, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x55, 0x73, 0x64, 0x88, - 0x01, 0x01, 0x12, 0x1b, 0x0a, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x09, 0x20, 0x01, - 0x28, 0x09, 0x48, 0x03, 0x52, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x88, 0x01, 0x01, 0x42, - 0x0c, 0x0a, 0x0a, 0x5f, 0x6c, 0x6f, 0x67, 0x5f, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x42, 0x0e, 0x0a, - 0x0c, 0x5f, 0x6c, 0x6f, 0x67, 0x5f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x6c, 0x42, 0x0d, 0x0a, - 0x0b, 0x5f, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x75, 0x73, 0x64, 0x42, 0x09, 0x0a, 0x07, - 0x5f, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x22, 0x57, 0x0a, 0x0c, 0x54, 0x6f, 0x6b, 0x65, 0x6e, - 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x2d, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x72, 0x69, - 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, - 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, - 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, - 0x22, 0x5f, 0x0a, 0x07, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x61, - 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x64, - 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x3a, 0x0a, 0x08, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, - 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x72, - 0x69, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, - 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x08, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, - 0x73, 0x22, 0x3b, 0x0a, 0x08, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x12, 0x2f, 0x0a, - 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x6d, - 0x65, 0x73, 0x73, 0x61, 0x72, 0x69, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x76, 0x31, 0x2e, - 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x4a, 0xe2, - 0x0b, 0x0a, 0x06, 0x12, 0x04, 0x00, 0x00, 0x2c, 0x01, 0x0a, 0x08, 0x0a, 0x01, 0x0c, 0x12, 0x03, - 0x00, 0x00, 0x12, 0x0a, 0x08, 0x0a, 0x01, 0x02, 0x12, 0x03, 0x02, 0x00, 0x19, 0x0a, 0x0a, 0x0a, - 0x02, 0x04, 0x00, 0x12, 0x04, 0x04, 0x00, 0x06, 0x01, 0x0a, 0x0a, 0x0a, 0x03, 0x04, 0x00, 0x01, - 0x12, 0x03, 0x04, 0x08, 0x0e, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x00, 0x02, 0x00, 0x12, 0x03, 0x05, - 0x02, 0x1b, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, 0x04, 0x12, 0x03, 0x05, 0x02, 0x0a, - 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, 0x06, 0x12, 0x03, 0x05, 0x0b, 0x10, 0x0a, 0x0c, - 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, 0x01, 0x12, 0x03, 0x05, 0x11, 0x16, 0x0a, 0x0c, 0x0a, 0x05, - 0x04, 0x00, 0x02, 0x00, 0x03, 0x12, 0x03, 0x05, 0x19, 0x1a, 0x0a, 0x0a, 0x0a, 0x02, 0x04, 0x01, - 0x12, 0x04, 0x08, 0x00, 0x0d, 0x01, 0x0a, 0x0a, 0x0a, 0x03, 0x04, 0x01, 0x01, 0x12, 0x03, 0x08, - 0x08, 0x0d, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x01, 0x02, 0x00, 0x12, 0x03, 0x09, 0x02, 0x15, 0x0a, - 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x00, 0x05, 0x12, 0x03, 0x09, 0x02, 0x08, 0x0a, 0x0c, 0x0a, - 0x05, 0x04, 0x01, 0x02, 0x00, 0x01, 0x12, 0x03, 0x09, 0x09, 0x10, 0x0a, 0x0c, 0x0a, 0x05, 0x04, - 0x01, 0x02, 0x00, 0x03, 0x12, 0x03, 0x09, 0x13, 0x14, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x01, 0x02, - 0x01, 0x12, 0x03, 0x0a, 0x02, 0x12, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x01, 0x05, 0x12, - 0x03, 0x0a, 0x02, 0x08, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x01, 0x01, 0x12, 0x03, 0x0a, - 0x09, 0x0d, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x01, 0x03, 0x12, 0x03, 0x0a, 0x10, 0x11, - 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x01, 0x02, 0x02, 0x12, 0x03, 0x0b, 0x02, 0x14, 0x0a, 0x0c, 0x0a, - 0x05, 0x04, 0x01, 0x02, 0x02, 0x05, 0x12, 0x03, 0x0b, 0x02, 0x08, 0x0a, 0x0c, 0x0a, 0x05, 0x04, - 0x01, 0x02, 0x02, 0x01, 0x12, 0x03, 0x0b, 0x09, 0x0f, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, - 0x02, 0x03, 0x12, 0x03, 0x0b, 0x12, 0x13, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x01, 0x02, 0x03, 0x12, - 0x03, 0x0c, 0x02, 0x16, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x03, 0x05, 0x12, 0x03, 0x0c, - 0x02, 0x08, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x03, 0x01, 0x12, 0x03, 0x0c, 0x09, 0x11, - 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x03, 0x03, 0x12, 0x03, 0x0c, 0x14, 0x15, 0x0a, 0x0a, - 0x0a, 0x02, 0x04, 0x02, 0x12, 0x04, 0x0f, 0x00, 0x11, 0x01, 0x0a, 0x0a, 0x0a, 0x03, 0x04, 0x02, - 0x01, 0x12, 0x03, 0x0f, 0x08, 0x11, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x02, 0x02, 0x00, 0x12, 0x03, - 0x10, 0x02, 0x1e, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x02, 0x02, 0x00, 0x04, 0x12, 0x03, 0x10, 0x02, - 0x0a, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x02, 0x02, 0x00, 0x06, 0x12, 0x03, 0x10, 0x0b, 0x13, 0x0a, - 0x0c, 0x0a, 0x05, 0x04, 0x02, 0x02, 0x00, 0x01, 0x12, 0x03, 0x10, 0x14, 0x19, 0x0a, 0x0c, 0x0a, - 0x05, 0x04, 0x02, 0x02, 0x00, 0x03, 0x12, 0x03, 0x10, 0x1c, 0x1d, 0x0a, 0x0a, 0x0a, 0x02, 0x04, - 0x03, 0x12, 0x04, 0x13, 0x00, 0x1d, 0x01, 0x0a, 0x0a, 0x0a, 0x03, 0x04, 0x03, 0x01, 0x12, 0x03, - 0x13, 0x08, 0x10, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x03, 0x02, 0x00, 0x12, 0x03, 0x14, 0x02, 0x15, - 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x00, 0x05, 0x12, 0x03, 0x14, 0x02, 0x08, 0x0a, 0x0c, - 0x0a, 0x05, 0x04, 0x03, 0x02, 0x00, 0x01, 0x12, 0x03, 0x14, 0x09, 0x10, 0x0a, 0x0c, 0x0a, 0x05, - 0x04, 0x03, 0x02, 0x00, 0x03, 0x12, 0x03, 0x14, 0x13, 0x14, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x03, - 0x02, 0x01, 0x12, 0x03, 0x15, 0x02, 0x20, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x01, 0x04, - 0x12, 0x03, 0x15, 0x02, 0x0a, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x01, 0x05, 0x12, 0x03, - 0x15, 0x0b, 0x11, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x01, 0x01, 0x12, 0x03, 0x15, 0x12, - 0x1b, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x01, 0x03, 0x12, 0x03, 0x15, 0x1e, 0x1f, 0x0a, - 0x0b, 0x0a, 0x04, 0x04, 0x03, 0x02, 0x02, 0x12, 0x03, 0x16, 0x02, 0x22, 0x0a, 0x0c, 0x0a, 0x05, - 0x04, 0x03, 0x02, 0x02, 0x04, 0x12, 0x03, 0x16, 0x02, 0x0a, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, - 0x02, 0x02, 0x05, 0x12, 0x03, 0x16, 0x0b, 0x11, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x02, - 0x01, 0x12, 0x03, 0x16, 0x12, 0x1d, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x02, 0x03, 0x12, - 0x03, 0x16, 0x20, 0x21, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x03, 0x02, 0x03, 0x12, 0x03, 0x17, 0x02, - 0x12, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x03, 0x06, 0x12, 0x03, 0x17, 0x02, 0x07, 0x0a, - 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x03, 0x01, 0x12, 0x03, 0x17, 0x08, 0x0d, 0x0a, 0x0c, 0x0a, - 0x05, 0x04, 0x03, 0x02, 0x03, 0x03, 0x12, 0x03, 0x17, 0x10, 0x11, 0x0a, 0x0b, 0x0a, 0x04, 0x04, - 0x03, 0x02, 0x04, 0x12, 0x03, 0x18, 0x02, 0x12, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x04, - 0x05, 0x12, 0x03, 0x18, 0x02, 0x08, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x04, 0x01, 0x12, - 0x03, 0x18, 0x09, 0x0d, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x04, 0x03, 0x12, 0x03, 0x18, - 0x10, 0x11, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x03, 0x02, 0x05, 0x12, 0x03, 0x19, 0x02, 0x10, 0x0a, - 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x05, 0x05, 0x12, 0x03, 0x19, 0x02, 0x08, 0x0a, 0x0c, 0x0a, - 0x05, 0x04, 0x03, 0x02, 0x05, 0x01, 0x12, 0x03, 0x19, 0x09, 0x0b, 0x0a, 0x0c, 0x0a, 0x05, 0x04, - 0x03, 0x02, 0x05, 0x03, 0x12, 0x03, 0x19, 0x0e, 0x0f, 0x0a, 0x2f, 0x0a, 0x04, 0x04, 0x03, 0x02, - 0x06, 0x12, 0x03, 0x1a, 0x02, 0x14, 0x22, 0x22, 0x20, 0x42, 0x69, 0x67, 0x49, 0x6e, 0x74, 0x2c, - 0x20, 0x69, 0x6e, 0x20, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x27, 0x73, 0x20, 0x6e, 0x61, 0x74, 0x69, - 0x76, 0x65, 0x20, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x0a, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, - 0x02, 0x06, 0x05, 0x12, 0x03, 0x1a, 0x02, 0x08, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x06, - 0x01, 0x12, 0x03, 0x1a, 0x09, 0x0f, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x06, 0x03, 0x12, - 0x03, 0x1a, 0x12, 0x13, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x03, 0x02, 0x07, 0x12, 0x03, 0x1b, 0x02, - 0x21, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x07, 0x04, 0x12, 0x03, 0x1b, 0x02, 0x0a, 0x0a, - 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x07, 0x05, 0x12, 0x03, 0x1b, 0x0b, 0x11, 0x0a, 0x0c, 0x0a, - 0x05, 0x04, 0x03, 0x02, 0x07, 0x01, 0x12, 0x03, 0x1b, 0x12, 0x1c, 0x0a, 0x0c, 0x0a, 0x05, 0x04, - 0x03, 0x02, 0x07, 0x03, 0x12, 0x03, 0x1b, 0x1f, 0x20, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x03, 0x02, - 0x08, 0x12, 0x03, 0x1c, 0x02, 0x1d, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x08, 0x04, 0x12, - 0x03, 0x1c, 0x02, 0x0a, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x08, 0x05, 0x12, 0x03, 0x1c, - 0x0b, 0x11, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x08, 0x01, 0x12, 0x03, 0x1c, 0x12, 0x18, - 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x03, 0x02, 0x08, 0x03, 0x12, 0x03, 0x1c, 0x1b, 0x1c, 0x0a, 0x0a, - 0x0a, 0x02, 0x04, 0x04, 0x12, 0x04, 0x1f, 0x00, 0x22, 0x01, 0x0a, 0x0a, 0x0a, 0x03, 0x04, 0x04, - 0x01, 0x12, 0x03, 0x1f, 0x08, 0x14, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x04, 0x02, 0x00, 0x12, 0x03, - 0x20, 0x02, 0x12, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x04, 0x02, 0x00, 0x06, 0x12, 0x03, 0x20, 0x02, - 0x07, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x04, 0x02, 0x00, 0x01, 0x12, 0x03, 0x20, 0x08, 0x0d, 0x0a, - 0x0c, 0x0a, 0x05, 0x04, 0x04, 0x02, 0x00, 0x03, 0x12, 0x03, 0x20, 0x10, 0x11, 0x0a, 0x2f, 0x0a, - 0x04, 0x04, 0x04, 0x02, 0x01, 0x12, 0x03, 0x21, 0x02, 0x15, 0x22, 0x22, 0x20, 0x42, 0x69, 0x67, - 0x49, 0x6e, 0x74, 0x2c, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x27, 0x73, 0x20, - 0x6e, 0x61, 0x74, 0x69, 0x76, 0x65, 0x20, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x0a, 0x0a, 0x0c, - 0x0a, 0x05, 0x04, 0x04, 0x02, 0x01, 0x05, 0x12, 0x03, 0x21, 0x02, 0x08, 0x0a, 0x0c, 0x0a, 0x05, - 0x04, 0x04, 0x02, 0x01, 0x01, 0x12, 0x03, 0x21, 0x09, 0x10, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x04, - 0x02, 0x01, 0x03, 0x12, 0x03, 0x21, 0x13, 0x14, 0x0a, 0x0a, 0x0a, 0x02, 0x04, 0x05, 0x12, 0x04, - 0x24, 0x00, 0x27, 0x01, 0x0a, 0x0a, 0x0a, 0x03, 0x04, 0x05, 0x01, 0x12, 0x03, 0x24, 0x08, 0x0f, - 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x05, 0x02, 0x00, 0x12, 0x03, 0x25, 0x02, 0x15, 0x0a, 0x0c, 0x0a, - 0x05, 0x04, 0x05, 0x02, 0x00, 0x05, 0x12, 0x03, 0x25, 0x02, 0x08, 0x0a, 0x0c, 0x0a, 0x05, 0x04, - 0x05, 0x02, 0x00, 0x01, 0x12, 0x03, 0x25, 0x09, 0x10, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x05, 0x02, - 0x00, 0x03, 0x12, 0x03, 0x25, 0x13, 0x14, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x05, 0x02, 0x01, 0x12, - 0x03, 0x26, 0x02, 0x25, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x05, 0x02, 0x01, 0x04, 0x12, 0x03, 0x26, - 0x02, 0x0a, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x05, 0x02, 0x01, 0x06, 0x12, 0x03, 0x26, 0x0b, 0x17, - 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x05, 0x02, 0x01, 0x01, 0x12, 0x03, 0x26, 0x18, 0x20, 0x0a, 0x0c, - 0x0a, 0x05, 0x04, 0x05, 0x02, 0x01, 0x03, 0x12, 0x03, 0x26, 0x23, 0x24, 0x0a, 0x24, 0x0a, 0x02, - 0x04, 0x06, 0x12, 0x04, 0x2a, 0x00, 0x2c, 0x01, 0x1a, 0x18, 0x20, 0x54, 0x4f, 0x44, 0x4f, 0x3a, - 0x20, 0x64, 0x6f, 0x20, 0x77, 0x65, 0x20, 0x6e, 0x65, 0x65, 0x64, 0x20, 0x74, 0x68, 0x69, 0x73, - 0x3f, 0x0a, 0x0a, 0x0a, 0x0a, 0x03, 0x04, 0x06, 0x01, 0x12, 0x03, 0x2a, 0x08, 0x10, 0x0a, 0x0b, - 0x0a, 0x04, 0x04, 0x06, 0x02, 0x00, 0x12, 0x03, 0x2b, 0x02, 0x1d, 0x0a, 0x0c, 0x0a, 0x05, 0x04, - 0x06, 0x02, 0x00, 0x04, 0x12, 0x03, 0x2b, 0x02, 0x0a, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x06, 0x02, - 0x00, 0x06, 0x12, 0x03, 0x2b, 0x0b, 0x12, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x06, 0x02, 0x00, 0x01, - 0x12, 0x03, 0x2b, 0x13, 0x18, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x06, 0x02, 0x00, 0x03, 0x12, 0x03, - 0x2b, 0x1b, 0x1c, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -]; -// @@protoc_insertion_point(module) \ No newline at end of file diff --git a/eth-balance/substreams.yaml b/eth-balance/substreams.yaml index aba540d1..b7aea193 100644 --- a/eth-balance/substreams.yaml +++ b/eth-balance/substreams.yaml @@ -8,9 +8,9 @@ imports: protobuf: files: - - evm_token.proto + - eth_balance.proto importPaths: - - ../common/proto + - ./proto binaries: default: @@ -20,7 +20,6 @@ binaries: modules: - name: map_balances kind: map - initialBlock: 0 inputs: - source: sf.ethereum.type.v2.Block output: diff --git a/substreams-helper/src/token.rs b/substreams-helper/src/token.rs index 193c421b..d661a6d8 100644 --- a/substreams-helper/src/token.rs +++ b/substreams-helper/src/token.rs @@ -8,14 +8,14 @@ pub fn get_eth_token() -> Option { address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE".to_string(), name: "Ethereum".to_string(), symbol: "ETH".to_string(), - decimals: 18 as u64, - total_supply: None, + decimals: 18_u64, }; Some(eth_token) } // TODO: replace this with substreams::scalar::BigInt once the wrapper is integrated +// TODO: make this an impl of fmt::Display pub fn bigint_to_string(number: Option) -> String { number .as_ref() diff --git a/substreams-helper/substreams.yaml b/substreams-helper/substreams.yaml index 19746bbd..a79c6089 100644 --- a/substreams-helper/substreams.yaml +++ b/substreams-helper/substreams.yaml @@ -8,10 +8,10 @@ imports: protobuf: files: - - evm_token.proto + - eth_balance.proto - importPaths: - - ../common/proto + - ../eth-balance/proto binaries: default: From 5684f3c98a193ae2da99ec808a28c8ecf9387739 Mon Sep 17 00:00:00 2001 From: dmelotik Date: Wed, 25 Jan 2023 21:01:16 -0700 Subject: [PATCH 19/25] update proto package name --- eth-balance/proto/eth_balance.proto | 2 +- eth-balance/src/lib.rs | 2 +- eth-balance/src/pb.rs | 8 ++++---- substreams-helper/src/pb.rs | 8 ++++---- substreams-helper/src/token.rs | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/eth-balance/proto/eth_balance.proto b/eth-balance/proto/eth_balance.proto index 36b72779..ea4eab3c 100644 --- a/eth-balance/proto/eth_balance.proto +++ b/eth-balance/proto/eth_balance.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -package messari.evm_token.v1; +package messari.eth_balance.v1; message Tokens { repeated Token items = 1; diff --git a/eth-balance/src/lib.rs b/eth-balance/src/lib.rs index 1cd5a715..4cad2b5e 100644 --- a/eth-balance/src/lib.rs +++ b/eth-balance/src/lib.rs @@ -2,7 +2,7 @@ pub mod pb; use substreams::Hex; use substreams_ethereum::pb::eth as pbeth; -use substreams_helper::pb::evm_token::v1 as token; +use substreams_helper::pb::eth_balance::v1 as token; use substreams_helper::token as token_helper; #[substreams::handlers::map] diff --git a/eth-balance/src/pb.rs b/eth-balance/src/pb.rs index 2b6dbd63..21c620eb 100644 --- a/eth-balance/src/pb.rs +++ b/eth-balance/src/pb.rs @@ -1,9 +1,9 @@ #[rustfmt::skip] -#[path = "../target/pb/messari.evm_token.v1.rs"] -pub(in crate::pb) mod evm_token_v1; +#[path = "../target/pb/messari.eth_balance.v1.rs"] +pub(in crate::pb) mod eth_balance_v1; -pub mod evm_token { +pub mod eth_balance { pub mod v1 { - pub use super::super::evm_token_v1::*; + pub use super::super::eth_balance_v1::*; } } diff --git a/substreams-helper/src/pb.rs b/substreams-helper/src/pb.rs index 2b6dbd63..21c620eb 100644 --- a/substreams-helper/src/pb.rs +++ b/substreams-helper/src/pb.rs @@ -1,9 +1,9 @@ #[rustfmt::skip] -#[path = "../target/pb/messari.evm_token.v1.rs"] -pub(in crate::pb) mod evm_token_v1; +#[path = "../target/pb/messari.eth_balance.v1.rs"] +pub(in crate::pb) mod eth_balance_v1; -pub mod evm_token { +pub mod eth_balance { pub mod v1 { - pub use super::super::evm_token_v1::*; + pub use super::super::eth_balance_v1::*; } } diff --git a/substreams-helper/src/token.rs b/substreams-helper/src/token.rs index d661a6d8..9517ff58 100644 --- a/substreams-helper/src/token.rs +++ b/substreams-helper/src/token.rs @@ -1,4 +1,4 @@ -use crate::pb::evm_token::v1::Token; +use crate::pb::eth_balance::v1::Token; use num_bigint; use substreams::scalar::BigInt; use substreams_ethereum::pb::eth as pbeth; From 5babb04ebe54a4896f9149af42eecf59dd393384 Mon Sep 17 00:00:00 2001 From: dmelotik Date: Wed, 1 Feb 2023 11:49:45 -0700 Subject: [PATCH 20/25] Amend erc20 proto to support all fields we want --- common/proto/erc20.proto | 30 ++-- erc20-holdings/Makefile | 2 +- erc20-holdings/src/lib.rs | 146 ++++++++++++++---- erc20-holdings/src/rpc.rs | 75 +++++++++ erc20-holdings/substreams.yaml | 3 +- erc20-market-cap/src/pb.rs | 10 ++ .../modules/1_store_chainlink_aggregator.rs | 4 + .../modules/3_store_pair_created_events.rs | 4 + erc20-price/src/modules/5_map_eth_price.rs | 2 + eth-balance/proto/eth_balance.proto | 2 + eth-balance/src/lib.rs | 2 +- eth-balance/substreams.yaml | 6 +- substreams-helper/build.rs | 1 - substreams-helper/src/pb.rs | 8 +- substreams-helper/src/token.rs | 10 +- substreams-helper/substreams.yaml | 5 +- 16 files changed, 253 insertions(+), 57 deletions(-) create mode 100644 erc20-holdings/src/rpc.rs diff --git a/common/proto/erc20.proto b/common/proto/erc20.proto index 2c0b99cf..da0e6d9f 100644 --- a/common/proto/erc20.proto +++ b/common/proto/erc20.proto @@ -11,6 +11,8 @@ message ERC20Token { string name = 2; string symbol = 3; uint64 decimals = 4; + string tx_created = 5; + uint64 block_created = 6; } message TransferEvents { @@ -19,20 +21,26 @@ message TransferEvents { message TransferEvent { string tx_hash = 1; - uint32 log_index = 2; - uint64 log_ordinal = 3; - string token_address = 4; - string from = 5; - string to = 6; - string amount = 7; // BigInt, in token's native amount + uint64 block_number = 2; + uint64 timestamp = 3; + uint32 log_index = 4; + optional uint64 log_ordinal = 5; + string token_address = 6; + string from = 7; + string to = 8; + string amount = 9; // BigInt, in token's native amount + repeated TokenBalance balance_changes = 10; } message TokenBalance { - string token_address = 1; - string balance = 2; // BigInt, in token's native amount + optional uint64 log_ordinal = 1; + ERC20Token token = 2; + string address = 3; // account address of the balance change + optional string old_balance = 4; // BigInt, in token's native amount + string new_balance = 5; // BigInt, in token's native amount + optional int32 reason = 6; } -message Account { - string address = 1; - repeated TokenBalance balances = 2; +message TokenBalances { + TokenBalance items = 1; } diff --git a/erc20-holdings/Makefile b/erc20-holdings/Makefile index a5bf0781..52b9b93e 100644 --- a/erc20-holdings/Makefile +++ b/erc20-holdings/Makefile @@ -6,4 +6,4 @@ build: .PHONY: run run: - substreams run -e mainnet.eth.streamingfast.io:443 substreams.yaml map_block_to_erc20_contracts -s 1 + substreams run -e mainnet.eth.streamingfast.io:443 substreams.yaml map_block_to_erc20_contracts -s 10606500 -t +100 diff --git a/erc20-holdings/src/lib.rs b/erc20-holdings/src/lib.rs index 6419a124..322e7706 100644 --- a/erc20-holdings/src/lib.rs +++ b/erc20-holdings/src/lib.rs @@ -4,6 +4,7 @@ pub mod abi; pub mod pb; mod keyer; +mod rpc; use pb::common::v1 as common; use pb::erc20::v1 as erc20; @@ -22,10 +23,13 @@ use substreams::store::StoreSetBigDecimal; use substreams::store::StoreSetRaw; use substreams::{hex, log, proto, store, Hex}; use substreams_ethereum::{pb::eth as pbeth, Event, NULL_ADDRESS}; +use substreams_helper::erc20::Erc20Token; use substreams_helper::keyer::chainlink_asset_key; use substreams_helper::types::Address; -fn contract_bytecode_len(call: &pbeth::v2::Call) -> usize { +const INITIALIZE_METHOD_HASH: [u8; 4] = hex!("1459457a"); + +fn code_len(call: &pbeth::v2::Call) -> usize { let mut len = 0; for code_change in &call.code_changes { len += code_change.new_code.len() @@ -38,30 +42,108 @@ fn contract_bytecode_len(call: &pbeth::v2::Call) -> usize { #[substreams::handlers::map] fn map_block_to_erc20_contracts( block: pbeth::v2::Block, -) -> Result { - let mut erc20_contracts = common::Addresses { items: vec![] }; - - for call_view in block.calls() { - let call = call_view.call; - if call.call_type == pbeth::v2::CallType::Create as i32 { - // skipping contracts that are too short to be an erc20 token - if contract_bytecode_len(call) < 150 { +) -> Result { + let mut erc20_tokens = erc20::Erc20Tokens { items: vec![] }; + + for tx in block.transaction_traces { + for call in tx.calls { + if call.state_reverted { continue; } - let address = Hex(call.address.clone()).to_string(); + if call.call_type == pbeth::v2::CallType::Create as i32 + || call.call_type == pbeth::v2::CallType::Call as i32 + // proxy contract creation + { + let call_input_len = call.input.len(); + if call.call_type == pbeth::v2::CallType::Call as i32 + && (call_input_len < 4 || call.input[0..4] != INITIALIZE_METHOD_HASH) + { + // this will check if a proxy contract has been called to create a ERC20 contract. + // if that is the case the Proxy contract will call the initialize function on the ERC20 contract + // this is part of the OpenZeppelin Proxy contract standard + continue; + } - // check if contract is an erc20 token - if substreams_helper::erc20::get_erc20_token(address.clone()).is_none() { - continue; - } + // Contract creation not from proxy contract + if call.call_type == pbeth::v2::CallType::Create as i32 { + let mut code_change_len = 0; + for code_change in &call.code_changes { + code_change_len += code_change.new_code.len() + } + + if code_change_len <= 150 { + // skipping contracts with less than 150 bytes of code + log::info!( + "Skipping contract {}. Contract code is less than 150 bytes.", + Hex::encode(&call.address) + ); + continue; + } + } - log::info!("Create {}, len {}", address, contract_bytecode_len(call)); - erc20_contracts.items.push(common::Address { address }); + let mut decimals = 18_u64; + let decimal_result = rpc::get_erc20_decimals(&call.address); + match decimal_result { + Ok(_decimals) => decimals = _decimals, + Err(e) => continue, + }; + + let mut symbol = "".to_string(); + let symbaol_result = rpc::get_erc20_symbol(&call.address); + match symbaol_result { + Ok(_symbol) => symbol = _symbol, + Err(e) => continue, + }; + + let mut name = "".to_string(); + let name_result = rpc::get_erc20_name(&call.address); + match name_result { + Ok(_name) => name = _name, + Err(e) => continue, + }; + + erc20_tokens.items.push(erc20::Erc20Token { + address: Hex::encode(call.address.clone()), + name: name, + symbol: symbol, + decimals: decimals, + tx_created: Hex::encode(&tx.hash), + block_created: block.number, + }); + } } } - Ok(erc20_contracts) + // for call_view in block.calls() { + // let call = call_view.call; + // if call.call_type == pbeth::v2::CallType::Create as i32 { + // // skipping contracts that are too short to be an erc20 token + // if code_len(call) < 150 { + // continue; + // } + // + // let address = Hex::encode(call.address.clone()); + // + // // check if contract is an erc20 token + // let erc20_struct = substreams_helper::erc20::get_erc20_token(address.clone()); + // if erc20_struct.is_none() { + // continue; + // } + // + // log::info!("Create {}, len {}", address, code_len(call)); + // erc20_tokens.items.push(erc20::Erc20Token { + // address: address, + // name: erc20_struct.as_ref().unwrap().name.clone(), + // symbol: erc20_struct.as_ref().unwrap().symbol.clone(), + // decimals: erc20_struct.as_ref().unwrap().decimals, + // tx_created: "TODO".to_string(), + // block_created: block.number, + // }); + // } + // } + + Ok(erc20_tokens) } /// Extracts transfer events from the blocks @@ -81,13 +163,23 @@ fn map_block_to_transfers( } transfer_events.items.push(erc20::TransferEvent { - tx_hash: Hex(log.receipt.transaction.clone().hash).to_string(), + tx_hash: Hex::encode(log.receipt.transaction.clone().hash), + block_number: block.number, + timestamp: block + .header + .as_ref() + .unwrap() + .timestamp + .as_ref() + .unwrap() + .seconds as u64, log_index: log.index(), - log_ordinal: log.ordinal(), - token_address: Hex(log.address()).to_string(), - from: Hex(event.from).to_string(), - to: Hex(event.to).to_string(), + log_ordinal: Some(log.ordinal()), + token_address: Hex::encode(log.address()), + from: Hex::encode(event.from), + to: Hex::encode(event.to), amount: event.value.to_string(), + balance_changes: vec![], }) } } @@ -100,7 +192,7 @@ fn store_transfers(transfers: erc20::TransferEvents, output: store::StoreSetRaw) log::info!("Stored events {}", transfers.items.len()); for transfer in transfers.items { output.set( - transfer.log_ordinal, + transfer.log_ordinal.unwrap(), Hex::encode(&transfer.token_address), &proto::encode(&transfer).unwrap(), ); @@ -112,14 +204,14 @@ fn store_balance(transfers: erc20::TransferEvents, output: store::StoreAddBigInt log::info!("Stored events {}", transfers.items.len()); for transfer in transfers.items { output.add( - transfer.log_ordinal, + transfer.log_ordinal.unwrap(), keyer::account_balance_key(&transfer.to), &BigInt::from_str(transfer.amount.as_str()).unwrap(), ); if Hex::decode(transfer.from.clone()).unwrap() != NULL_ADDRESS { output.add( - transfer.log_ordinal, + transfer.log_ordinal.unwrap(), keyer::account_balance_key(&transfer.from), &BigInt::from_str((transfer.amount).as_str()).unwrap().neg(), ); @@ -148,7 +240,7 @@ fn store_balance_usd( match balances.get_last(keyer::account_balance_key(&transfer.to)) { Some(balance) => output.set( - transfer.log_ordinal, + transfer.log_ordinal.unwrap(), keyer::account_balance_usd_key(&transfer.to), &(token_price.clone() * balance.to_decimal(token_decimals.into())), ), @@ -158,7 +250,7 @@ fn store_balance_usd( if Hex::decode(transfer.from.clone()).unwrap() != NULL_ADDRESS { match balances.get_last(keyer::account_balance_key(&transfer.from)) { Some(balance) => output.set( - transfer.log_ordinal, + transfer.log_ordinal.unwrap(), keyer::account_balance_usd_key(&transfer.from), &(token_price.clone() * balance.to_decimal(token_decimals.into())), ), diff --git a/erc20-holdings/src/rpc.rs b/erc20-holdings/src/rpc.rs new file mode 100644 index 00000000..6b4c5516 --- /dev/null +++ b/erc20-holdings/src/rpc.rs @@ -0,0 +1,75 @@ +use std::fmt::Error; +use substreams::{log, Hex}; +use substreams_ethereum::pb::eth; +use substreams_ethereum::rpc::eth_call; +use substreams_helper::utils::{read_string, read_uint32}; + +// Functions to attempt to get erc20 contract calls + +pub const DECIMALS: &str = "313ce567"; +pub const NAME: &str = "06fdde03"; +pub const SYMBOL: &str = "95d89b41"; + +pub fn get_erc20_decimals(call_addr: &Vec) -> Result { + let rpc_call_decimal = create_rpc_calls(call_addr, vec![DECIMALS]); + let rpc_responses_unmarshalled_decimal = eth_call(&rpc_call_decimal); + let response_decimal = rpc_responses_unmarshalled_decimal.responses; + if response_decimal.len() < 1 || response_decimal[0].failed { + return Err(Error); + } + + let decoded_decimals = read_uint32(response_decimal[0].raw.as_ref()); + if decoded_decimals.is_err() { + log::info!("Failed to decode decimals"); + return Err(Error); + } + + return Ok(decoded_decimals.unwrap() as u64); +} + +pub fn get_erc20_symbol(call_addr: &Vec) -> Result { + let rpc_call_symbol = create_rpc_calls(call_addr, vec![SYMBOL]); + let rpc_responses_unmarshalled = eth_call(&rpc_call_symbol); + let responses = rpc_responses_unmarshalled.responses; + if responses.len() < 2 || responses[1].failed { + log::info!("Failed to get symbol"); + return Err(Error); + }; + + let decoded_symbol = read_string(responses[2].raw.as_ref()); + if decoded_symbol.is_err() { + log::info!("Failed to decode symbol"); + return Err(Error); + } + + return Ok(decoded_symbol.unwrap()); +} + +pub fn get_erc20_name(call_addr: &Vec) -> Result { + let rpc_call_name = create_rpc_calls(call_addr, vec![NAME]); + let rpc_responses_unmarshalled = eth_call(&rpc_call_name); + let responses = rpc_responses_unmarshalled.responses; + if responses.len() < 1 || responses[0].failed { + return Err(Error); + }; + + let decoded_name = read_string(responses[1].raw.as_ref()); + if decoded_name.is_err() { + return Err(Error); + } + + return Ok(decoded_name.unwrap()); +} + +fn create_rpc_calls(addr: &Vec, method_signatures: Vec<&str>) -> eth::rpc::RpcCalls { + let mut rpc_calls = eth::rpc::RpcCalls { calls: vec![] }; + + for method_signature in method_signatures { + rpc_calls.calls.push(eth::rpc::RpcCall { + to_addr: Vec::from(addr.clone()), + data: Hex::decode(method_signature).unwrap(), + }) + } + + return rpc_calls; +} diff --git a/erc20-holdings/substreams.yaml b/erc20-holdings/substreams.yaml index 7353d0de..c72d7109 100644 --- a/erc20-holdings/substreams.yaml +++ b/erc20-holdings/substreams.yaml @@ -20,13 +20,14 @@ binaries: file: ../target/wasm32-unknown-unknown/release/substreams_erc20_holdings.wasm modules: + # This should be a store module since it is needed by multiple modules - name: map_block_to_erc20_contracts kind: map initialBlock: 1 inputs: - source: sf.ethereum.type.v2.Block output: - type: proto:messari.common.v1.Addresses + type: proto:messari.erc20.v1.ERC20Tokens - name: map_block_to_transfers kind: map diff --git a/erc20-market-cap/src/pb.rs b/erc20-market-cap/src/pb.rs index 9a8fb3eb..eb61bfbe 100644 --- a/erc20-market-cap/src/pb.rs +++ b/erc20-market-cap/src/pb.rs @@ -37,3 +37,13 @@ pub mod erc20_price { pub use super::super::erc20_price_v1::*; } } + +#[rustfmt::skip] +#[path = "../target/pb/messari.uniswap.v1.rs"] +pub(in crate::pb) mod uniswap_v1; + +pub mod uniswap { + pub mod v1 { + pub use super::super::uniswap_v1::*; + } +} diff --git a/erc20-price/src/modules/1_store_chainlink_aggregator.rs b/erc20-price/src/modules/1_store_chainlink_aggregator.rs index f8d8f0ab..8515aa3e 100644 --- a/erc20-price/src/modules/1_store_chainlink_aggregator.rs +++ b/erc20-price/src/modules/1_store_chainlink_aggregator.rs @@ -78,12 +78,16 @@ fn store_chainlink_aggregator(block: eth::Block, output: StoreSetProto Result Result<(), anyhow::Error> { codegen::generate(None)?; - codegen::generate_abi(None)?; Ok(()) } diff --git a/substreams-helper/src/pb.rs b/substreams-helper/src/pb.rs index 21c620eb..cd2c33a1 100644 --- a/substreams-helper/src/pb.rs +++ b/substreams-helper/src/pb.rs @@ -1,9 +1,9 @@ #[rustfmt::skip] -#[path = "../target/pb/messari.eth_balance.v1.rs"] -pub(in crate::pb) mod eth_balance_v1; +#[path = "../target/pb/messari.erc20.v1.rs"] +pub(in crate::pb) mod erc20_v1; -pub mod eth_balance { +pub mod erc20 { pub mod v1 { - pub use super::super::eth_balance_v1::*; + pub use super::super::erc20_v1::*; } } diff --git a/substreams-helper/src/token.rs b/substreams-helper/src/token.rs index 9517ff58..b79a5cad 100644 --- a/substreams-helper/src/token.rs +++ b/substreams-helper/src/token.rs @@ -1,21 +1,21 @@ -use crate::pb::eth_balance::v1::Token; +use crate::pb::erc20::v1::Erc20Token; use num_bigint; use substreams::scalar::BigInt; use substreams_ethereum::pb::eth as pbeth; -pub fn get_eth_token() -> Option { - let eth_token = Token { +pub fn get_eth_token() -> Option { + let eth_token = Erc20Token { address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE".to_string(), name: "Ethereum".to_string(), symbol: "ETH".to_string(), decimals: 18_u64, + tx_created: "".to_string(), + block_created: 0_u64, }; Some(eth_token) } -// TODO: replace this with substreams::scalar::BigInt once the wrapper is integrated -// TODO: make this an impl of fmt::Display pub fn bigint_to_string(number: Option) -> String { number .as_ref() diff --git a/substreams-helper/substreams.yaml b/substreams-helper/substreams.yaml index a79c6089..fd59c8ab 100644 --- a/substreams-helper/substreams.yaml +++ b/substreams-helper/substreams.yaml @@ -8,10 +8,9 @@ imports: protobuf: files: - - eth_balance.proto - - + - erc20.proto importPaths: - - ../eth-balance/proto + - ../common/proto binaries: default: From d2ecbc23d1ef1089313d96cac8d93869c5c953bf Mon Sep 17 00:00:00 2001 From: dmelotik Date: Wed, 1 Feb 2023 13:43:35 -0700 Subject: [PATCH 21/25] Add README.md and remove build warnings --- common/src/codegen.rs | 3 --- erc20-holdings/Makefile | 2 +- erc20-holdings/README.md | 8 ++++++ erc20-holdings/src/lib.rs | 55 ++++++++++----------------------------- erc20-holdings/src/rpc.rs | 13 +++++---- 5 files changed, 31 insertions(+), 50 deletions(-) create mode 100644 erc20-holdings/README.md diff --git a/common/src/codegen.rs b/common/src/codegen.rs index fdf2549f..94918952 100644 --- a/common/src/codegen.rs +++ b/common/src/codegen.rs @@ -139,9 +139,6 @@ pub fn generate_pb(out_dir: Option<&str>) -> Result<(), Error> { } } - // Cleanup - fs::remove_dir_all(&tmp_dir).unwrap(); - if !pb_files.is_empty() { let pb_file_content = pb_files .into_iter() diff --git a/erc20-holdings/Makefile b/erc20-holdings/Makefile index 52b9b93e..150a87ed 100644 --- a/erc20-holdings/Makefile +++ b/erc20-holdings/Makefile @@ -6,4 +6,4 @@ build: .PHONY: run run: - substreams run -e mainnet.eth.streamingfast.io:443 substreams.yaml map_block_to_erc20_contracts -s 10606500 -t +100 + substreams run -e mainnet.eth.streamingfast.io:443 substreams.yaml map_block_to_erc20_contracts -s 6082465 -t +1 diff --git a/erc20-holdings/README.md b/erc20-holdings/README.md new file mode 100644 index 00000000..7fd342ac --- /dev/null +++ b/erc20-holdings/README.md @@ -0,0 +1,8 @@ +# ERC20 Holdings + +This substream will find all of the ERC20 tokens on ethereum with metadata. In addition it will map transfers. Balance can be derived from this. Then the `store_balance_usd` module combines chainlink data to store the prices as well. + +## Notes + +- The `map_block_to_erc20_contracts` module should be a `store` module since multiple other modules will want to use it as input to get ERC20 token metadata. +- `map_block_to_erc20_contracts` gets ERC20 metadata some of the time. It should grab all ERC20 contracts, however the metadata is not always populated. I am not quite sure why this is. diff --git a/erc20-holdings/src/lib.rs b/erc20-holdings/src/lib.rs index 322e7706..32644c46 100644 --- a/erc20-holdings/src/lib.rs +++ b/erc20-holdings/src/lib.rs @@ -6,7 +6,6 @@ pub mod pb; mod keyer; mod rpc; -use pb::common::v1 as common; use pb::erc20::v1 as erc20; use pb::erc20_price::v1::Erc20Price; use std::str::FromStr; @@ -23,7 +22,6 @@ use substreams::store::StoreSetBigDecimal; use substreams::store::StoreSetRaw; use substreams::{hex, log, proto, store, Hex}; use substreams_ethereum::{pb::eth as pbeth, Event, NULL_ADDRESS}; -use substreams_helper::erc20::Erc20Token; use substreams_helper::keyer::chainlink_asset_key; use substreams_helper::types::Address; @@ -38,6 +36,7 @@ fn code_len(call: &pbeth::v2::Call) -> usize { len } +// TODO: this should be a store module /// Extracts erc20 contract deployments from the blocks #[substreams::handlers::map] fn map_block_to_erc20_contracts( @@ -67,40 +66,42 @@ fn map_block_to_erc20_contracts( // Contract creation not from proxy contract if call.call_type == pbeth::v2::CallType::Create as i32 { - let mut code_change_len = 0; - for code_change in &call.code_changes { - code_change_len += code_change.new_code.len() - } + let code_change_len = code_len(&call); if code_change_len <= 150 { // skipping contracts with less than 150 bytes of code log::info!( - "Skipping contract {}. Contract code is less than 150 bytes.", + "Skipping contract: {}. Contract code is less than 150 bytes.", Hex::encode(&call.address) ); continue; } } - let mut decimals = 18_u64; + log::info!( + "Attempting to get metadata for erc20: {}", + Hex::encode(&call.address) + ); + + let decimals: u64; let decimal_result = rpc::get_erc20_decimals(&call.address); match decimal_result { Ok(_decimals) => decimals = _decimals, - Err(e) => continue, + Err(_e) => continue, }; - let mut symbol = "".to_string(); + let symbol: String; let symbaol_result = rpc::get_erc20_symbol(&call.address); match symbaol_result { Ok(_symbol) => symbol = _symbol, - Err(e) => continue, + Err(_e) => continue, }; - let mut name = "".to_string(); + let name: String; let name_result = rpc::get_erc20_name(&call.address); match name_result { Ok(_name) => name = _name, - Err(e) => continue, + Err(_e) => continue, }; erc20_tokens.items.push(erc20::Erc20Token { @@ -115,34 +116,6 @@ fn map_block_to_erc20_contracts( } } - // for call_view in block.calls() { - // let call = call_view.call; - // if call.call_type == pbeth::v2::CallType::Create as i32 { - // // skipping contracts that are too short to be an erc20 token - // if code_len(call) < 150 { - // continue; - // } - // - // let address = Hex::encode(call.address.clone()); - // - // // check if contract is an erc20 token - // let erc20_struct = substreams_helper::erc20::get_erc20_token(address.clone()); - // if erc20_struct.is_none() { - // continue; - // } - // - // log::info!("Create {}, len {}", address, code_len(call)); - // erc20_tokens.items.push(erc20::Erc20Token { - // address: address, - // name: erc20_struct.as_ref().unwrap().name.clone(), - // symbol: erc20_struct.as_ref().unwrap().symbol.clone(), - // decimals: erc20_struct.as_ref().unwrap().decimals, - // tx_created: "TODO".to_string(), - // block_created: block.number, - // }); - // } - // } - Ok(erc20_tokens) } diff --git a/erc20-holdings/src/rpc.rs b/erc20-holdings/src/rpc.rs index 6b4c5516..43168d04 100644 --- a/erc20-holdings/src/rpc.rs +++ b/erc20-holdings/src/rpc.rs @@ -14,7 +14,8 @@ pub fn get_erc20_decimals(call_addr: &Vec) -> Result { let rpc_call_decimal = create_rpc_calls(call_addr, vec![DECIMALS]); let rpc_responses_unmarshalled_decimal = eth_call(&rpc_call_decimal); let response_decimal = rpc_responses_unmarshalled_decimal.responses; - if response_decimal.len() < 1 || response_decimal[0].failed { + if response_decimal[0].failed { + log::info!("Failed to get decimals"); return Err(Error); } @@ -31,12 +32,12 @@ pub fn get_erc20_symbol(call_addr: &Vec) -> Result { let rpc_call_symbol = create_rpc_calls(call_addr, vec![SYMBOL]); let rpc_responses_unmarshalled = eth_call(&rpc_call_symbol); let responses = rpc_responses_unmarshalled.responses; - if responses.len() < 2 || responses[1].failed { + if responses[0].failed { log::info!("Failed to get symbol"); return Err(Error); }; - let decoded_symbol = read_string(responses[2].raw.as_ref()); + let decoded_symbol = read_string(responses[0].raw.as_ref()); if decoded_symbol.is_err() { log::info!("Failed to decode symbol"); return Err(Error); @@ -49,12 +50,14 @@ pub fn get_erc20_name(call_addr: &Vec) -> Result { let rpc_call_name = create_rpc_calls(call_addr, vec![NAME]); let rpc_responses_unmarshalled = eth_call(&rpc_call_name); let responses = rpc_responses_unmarshalled.responses; - if responses.len() < 1 || responses[0].failed { + if responses[0].failed { + log::info!("Failed to get name"); return Err(Error); }; - let decoded_name = read_string(responses[1].raw.as_ref()); + let decoded_name = read_string(responses[0].raw.as_ref()); if decoded_name.is_err() { + log::info!("Failed to decode name"); return Err(Error); } From faeede82d4b9da4bab3176ef46ae17d0a0113d41 Mon Sep 17 00:00:00 2001 From: dmelotik Date: Wed, 1 Feb 2023 13:55:38 -0700 Subject: [PATCH 22/25] update eth-balance with updated proto --- eth-balance/proto/eth_balance.proto | 43 ----------------------------- eth-balance/src/lib.rs | 25 ++++++++++------- eth-balance/src/pb.rs | 8 +++--- substreams-helper/src/token.rs | 4 ++- 4 files changed, 22 insertions(+), 58 deletions(-) delete mode 100644 eth-balance/proto/eth_balance.proto diff --git a/eth-balance/proto/eth_balance.proto b/eth-balance/proto/eth_balance.proto deleted file mode 100644 index c2a57fa5..00000000 --- a/eth-balance/proto/eth_balance.proto +++ /dev/null @@ -1,43 +0,0 @@ -syntax = "proto3"; - -package messari.eth_balance.v1; - -message Tokens { - repeated Token items = 1; -} - -message Token { - string address = 1; - string name = 2; - string symbol = 3; - uint64 decimals = 4; - string tx_created = 5; - uint64 block_created = 6; -} - -message Transfers { - repeated Transfer items = 1; -} - -message Transfer { - string tx_hash = 1; - uint64 block_number = 2; - uint64 timestamp = 3; - uint32 log_index = 4; - Token token = 5; - string to = 6; - string from = 7; - string amount = 8; // BigInt, in token's native amount - optional string amount_usd = 9; - repeated TokenBalance balance_changes = 10; -} - -// balance changes -message TokenBalance { - uint64 log_ordinal = 1; - Token token = 2; - string address = 3; // account address of the balance change - string old_balance = 4; // BigInt, in token's native amount - string new_balance = 5; // BigInt, in token's native amount - optional int32 reason = 6; -} diff --git a/eth-balance/src/lib.rs b/eth-balance/src/lib.rs index 2ead5a11..9049a9dd 100644 --- a/eth-balance/src/lib.rs +++ b/eth-balance/src/lib.rs @@ -2,28 +2,33 @@ pub mod pb; use substreams::Hex; use substreams_ethereum::pb::eth as pbeth; -use substreams_helper::pb::eth_balance::v1 as token; +use substreams_helper::pb::erc20::v1 as proto; use substreams_helper::token as token_helper; +use substreams_helper::token::ETH_ADDRESS; #[substreams::handlers::map] -fn map_balances(block: pbeth::v2::Block) -> Result { +fn map_balances( + block: pbeth::v2::Block, +) -> Result { let mut transfers = vec![]; for transaction in &block.transaction_traces { let mut balance_changes = vec![]; for call in &transaction.calls { for balance_change in &call.balance_changes { - balance_changes.push(token::TokenBalance { - log_ordinal: balance_change.ordinal, + balance_changes.push(proto::TokenBalance { + log_ordinal: Some(balance_change.ordinal), token: token_helper::get_eth_token(), address: Hex::encode(&balance_change.address), - old_balance: token_helper::bigint_to_string(balance_change.old_value.clone()), + old_balance: Some(token_helper::bigint_to_string( + balance_change.old_value.clone(), + )), new_balance: token_helper::bigint_to_string(balance_change.new_value.clone()), reason: Some(balance_change.reason), }); } } - transfers.push(token::Transfer { + transfers.push(proto::TransferEvent { tx_hash: Hex::encode(&transaction.hash), block_number: block.number, timestamp: block @@ -35,14 +40,14 @@ fn map_balances(block: pbeth::v2::Block) -> Result Option { let eth_token = Erc20Token { - address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE".to_string(), + address: ETH_ADDRESS.to_string(), name: "Ethereum".to_string(), symbol: "ETH".to_string(), decimals: 18_u64, From f33704e1629843538978b1f2d2a4389f67b35038 Mon Sep 17 00:00:00 2001 From: dmelotik Date: Fri, 31 Mar 2023 14:22:07 -0700 Subject: [PATCH 23/25] add subgraph sink source code (bitcode error) --- Cargo.lock | 52 ++++++++++++++++++++ common/src/codegen.rs | 7 ++- erc20-price/src/pb.rs | 38 ++------------- eth-balance/Cargo.toml | 1 + eth-balance/Makefile | 8 +-- eth-balance/src/lib.rs | 75 +++++++++++++++++++++++++++++ eth-balance/src/pb.rs | 10 ++++ eth-balance/subgraph/schema.graphql | 40 +++++++++++++++ eth-balance/subgraph/subgraph.yaml | 15 ++++++ eth-balance/substreams.yaml | 9 ++++ network/src/pb.rs | 18 +++++-- substreams-helper/src/token.rs | 2 +- 12 files changed, 229 insertions(+), 46 deletions(-) create mode 100644 eth-balance/subgraph/schema.graphql create mode 100644 eth-balance/subgraph/subgraph.yaml diff --git a/Cargo.lock b/Cargo.lock index c0db0194..5c1b477f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -38,6 +38,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + [[package]] name = "bigdecimal" version = "0.3.0" @@ -249,6 +255,7 @@ dependencies = [ "prost 0.11.3", "substreams 0.3.2", "substreams-common", + "substreams-entity-change", "substreams-ethereum", "substreams-helper", ] @@ -988,6 +995,27 @@ dependencies = [ "wee_alloc", ] +[[package]] +name = "substreams" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0af4a883f8ce09c8b5c2560c2373d230b6fce37972833f96151c0a0469b2c3b4" +dependencies = [ + "anyhow", + "bigdecimal", + "hex", + "hex-literal", + "num-bigint", + "num-traits", + "pad", + "prost 0.11.3", + "prost-build 0.11.1", + "prost-types 0.11.1", + "substreams-macro 0.5.6", + "thiserror", + "wee_alloc", +] + [[package]] name = "substreams-common" version = "0.1.0" @@ -999,6 +1027,18 @@ dependencies = [ "thiserror", ] +[[package]] +name = "substreams-entity-change" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c81fb0794efb438c5743c821ec76528c38878010c30d4a79d70799eac68837f6" +dependencies = [ + "base64", + "prost 0.11.3", + "prost-types 0.11.1", + "substreams 0.5.6", +] + [[package]] name = "substreams-erc20-holdings" version = "0.1.0" @@ -1143,6 +1183,18 @@ dependencies = [ "thiserror", ] +[[package]] +name = "substreams-macro" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f70ab0d9112fa637daad274d1163277d292600e19ac5edb9219cb063110970a" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "thiserror", +] + [[package]] name = "substreams-solana" version = "0.1.0" diff --git a/common/src/codegen.rs b/common/src/codegen.rs index 94918952..2bcdbf87 100644 --- a/common/src/codegen.rs +++ b/common/src/codegen.rs @@ -149,9 +149,9 @@ pub fn generate_pb(out_dir: Option<&str>) -> Result<(), Error> { ( format!( "#[rustfmt::skip]\n\ - #[path = \"../{}/pb/messari.{}.{}.rs\"]\n\ - pub(in crate::pb) mod {1}_{2};\n", - out_dir, filename, version + #[path = \"../{}/pb/{}.{}.{}.rs\"]\n\ + pub(in crate::pb) mod {2}_{3};\n", + out_dir, (if filename.contains("entity") {"substreams"} else {"messari"}), filename, version ), format!( " pub mod {} {{\n \ @@ -162,7 +162,6 @@ pub fn generate_pb(out_dir: Option<&str>) -> Result<(), Error> { ) }) .unzip(); - format!( "{}\n\ pub mod {} {{\n\ diff --git a/erc20-price/src/pb.rs b/erc20-price/src/pb.rs index fdb3e696..b6d84e80 100644 --- a/erc20-price/src/pb.rs +++ b/erc20-price/src/pb.rs @@ -1,39 +1,9 @@ #[rustfmt::skip] -#[path = "../target/pb/messari.chainlink.v1.rs"] -pub(in crate::pb) mod chainlink_v1; +#[path = "../target/pb/messari.erc721.v1.rs"] +pub(in crate::pb) mod erc721_v1; -pub mod chainlink { +pub mod erc721 { pub mod v1 { - pub use super::super::chainlink_v1::*; - } -} - -#[rustfmt::skip] -#[path = "../target/pb/messari.erc20.v1.rs"] -pub(in crate::pb) mod erc20_v1; - -pub mod erc20 { - pub mod v1 { - pub use super::super::erc20_v1::*; - } -} - -#[rustfmt::skip] -#[path = "../target/pb/messari.erc20_price.v1.rs"] -pub(in crate::pb) mod erc20_price_v1; - -pub mod erc20_price { - pub mod v1 { - pub use super::super::erc20_price_v1::*; - } -} - -#[rustfmt::skip] -#[path = "../target/pb/messari.uniswap.v1.rs"] -pub(in crate::pb) mod uniswap_v1; - -pub mod uniswap { - pub mod v1 { - pub use super::super::uniswap_v1::*; + pub use super::super::erc721_v1::*; } } diff --git a/eth-balance/Cargo.toml b/eth-balance/Cargo.toml index 3f2ff416..bc94ef95 100644 --- a/eth-balance/Cargo.toml +++ b/eth-balance/Cargo.toml @@ -16,6 +16,7 @@ hex-literal = "0.3.4" substreams = { workspace = true } substreams-ethereum = { workspace = true } substreams-helper = { path = "../substreams-helper" } +substreams-entity-change = "0.3.0" [build-dependencies] anyhow = "1" diff --git a/eth-balance/Makefile b/eth-balance/Makefile index 62b10842..ec118ac2 100644 --- a/eth-balance/Makefile +++ b/eth-balance/Makefile @@ -1,7 +1,9 @@ -.PHONY: build +.PHONY: build run all + build: cargo build --target wasm32-unknown-unknown --release -.PHONY: run run: - substreams run -e mainnet.eth.streamingfast.io:443 substreams.yaml map_balances -s 5350000 -t 5350001 + substreams run -e mainnet.eth.streamingfast.io:443 substreams.yaml map_entity_changes -s 5350000 -t 5350001 + +all: build run diff --git a/eth-balance/src/lib.rs b/eth-balance/src/lib.rs index 9049a9dd..d1ce6fce 100644 --- a/eth-balance/src/lib.rs +++ b/eth-balance/src/lib.rs @@ -1,11 +1,17 @@ pub mod pb; +use substreams::pb::substreams::store_delta::Operation; use substreams::Hex; +// use substreams::scalar::BigInt; +use substreams_entity_change::change::ToField; use substreams_ethereum::pb::eth as pbeth; use substreams_helper::pb::erc20::v1 as proto; use substreams_helper::token as token_helper; use substreams_helper::token::ETH_ADDRESS; +use substreams_entity_change::pb::entity::entity_change::Operation as EntityChangeOperation; +use substreams_entity_change::pb::entity::{EntityChange, EntityChanges}; + #[substreams::handlers::map] fn map_balances( block: pbeth::v2::Block, @@ -51,3 +57,72 @@ fn map_balances( Ok(proto::TransferEvents { items: transfers }) } + +#[substreams::handlers::map] +fn map_entity_changes( + transfer_events: proto::TransferEvents, +) -> Result { + let mut transfer_enitites = vec![]; + let mut balance_change_entities = vec![]; + + for transfer in transfer_events.items { + // extract balance changes + for balance_change in transfer.balance_changes { + balance_change_entities.push(EntityChange { + entity: "TokenBalance".to_string(), + id: transfer.tx_hash.clone() + + transfer + .log_ordinal + .unwrap_or_default() + .to_string() + .as_str(), + ordinal: transfer.log_ordinal.unwrap_or_default(), + operation: EntityChangeOperation::Create.into(), + fields: vec![ + transfer.tx_hash.clone().to_field("transfer".to_string()), + transfer + .log_ordinal + .unwrap_or_default() + .to_field("logOrdinal".to_string()), + balance_change.address.to_field("account".to_string()), + balance_change + .old_balance + .unwrap() + .to_field("oldBalance".to_string()), + balance_change + .new_balance + .to_field("newBalance".to_string()), + balance_change + .reason + .unwrap() + .to_field("reason".to_string()), + ], + }); + } + + // map transfer entity changes + transfer_enitites.push(EntityChange { + entity: "Transfer".to_string(), + id: transfer.tx_hash.clone(), + ordinal: transfer.block_number, + operation: Operation::Create.into(), + fields: vec![ + transfer.block_number.to_field("blockNumber".to_string()), + transfer.timestamp.to_field("timestamp".to_string()), + transfer.log_index.to_string().to_field("logIndex".to_string()), + transfer + .log_ordinal + .unwrap_or_default() + .to_field("logOrdinal".to_string()), + transfer.token_address.to_field("tokenAddress".to_string()), + transfer.from.to_field("from".to_string()), + transfer.to.to_field("to".to_string()), + transfer.amount.to_field("amount".to_string()), + ], + }); + } + + Ok(EntityChanges { + entity_changes: [transfer_enitites, balance_change_entities].concat(), + }) +} diff --git a/eth-balance/src/pb.rs b/eth-balance/src/pb.rs index cd2c33a1..bf50187b 100644 --- a/eth-balance/src/pb.rs +++ b/eth-balance/src/pb.rs @@ -1,3 +1,13 @@ +#[rustfmt::skip] +#[path = "../target/pb/substreams.entity.v1.rs"] +pub(in crate::pb) mod entity_v1; + +pub mod entity { + pub mod v1 { + pub use super::super::entity_v1::*; + } +} + #[rustfmt::skip] #[path = "../target/pb/messari.erc20.v1.rs"] pub(in crate::pb) mod erc20_v1; diff --git a/eth-balance/subgraph/schema.graphql b/eth-balance/subgraph/schema.graphql new file mode 100644 index 00000000..7e0457ba --- /dev/null +++ b/eth-balance/subgraph/schema.graphql @@ -0,0 +1,40 @@ +type Transfer @entity { + " {transaction hash} " + id: Bytes! + + blockNumber: BigInt! + timestamp: BigInt! + logIndex: BigInt! + logOrdinal: BigInt + + " The address of the token being transferred " + tokenAddress: Bytes! + + " Address sending the tokens " + from: Bytes! + + " Address receiving the tokens " + to: Bytes! + + " Amount of tokens being transferred " + amount: BigInt! + + balanceChanges: [BalanceChange!]! @derivedFrom(field: "transfer") +} + +type BalanceChange @entity { + " {transaction hash}-{log ordinal} " + id: Bytes! + + " Related Transfer event ID (ie, transaction hash) " + transfer: Bytes! + + logOrdinal: BigInt + + account: Bytes! + + oldBalance: BigInt + newBalance: BigInt! + + reason: Int! +} \ No newline at end of file diff --git a/eth-balance/subgraph/subgraph.yaml b/eth-balance/subgraph/subgraph.yaml new file mode 100644 index 00000000..c016abdb --- /dev/null +++ b/eth-balance/subgraph/subgraph.yaml @@ -0,0 +1,15 @@ +specVersion: 0.0.4 +description: ETH Balance Change subgraph powered by substreams +schema: + file: schema.graphql +dataSources: + - kind: substreams + name: graph_network_substreams + network: mainnet + source: + package: + moduleName: map_entity_changes + file: ../eth-balance-v0.1.0.spkg + mapping: + kind: substreams/graph-entities + apiVersion: 0.0.5 diff --git a/eth-balance/substreams.yaml b/eth-balance/substreams.yaml index 88783b75..52778cd9 100644 --- a/eth-balance/substreams.yaml +++ b/eth-balance/substreams.yaml @@ -5,10 +5,12 @@ package: imports: eth: https://github.com/streamingfast/sf-ethereum/releases/download/v0.10.2/ethereum-v0.10.4.spkg + entity: https://github.com/streamingfast/substreams-entity-change/releases/download/v0.2.1/substreams-entity-change-v0.2.1.spkg protobuf: files: - erc20.proto + - importPaths: - ../common/proto @@ -24,3 +26,10 @@ modules: - source: sf.ethereum.type.v2.Block output: type: proto:messari.erc20.v1.TransferEvents + + - name: map_entity_changes + kind: map + inputs: + - map: map_balances + output: + type: proto:substreams.entity.v1.EntityChanges \ No newline at end of file diff --git a/network/src/pb.rs b/network/src/pb.rs index d2daff74..8f12a5af 100644 --- a/network/src/pb.rs +++ b/network/src/pb.rs @@ -1,9 +1,19 @@ #[rustfmt::skip] -#[path = "../target/pb/messari.network.v1.rs"] -pub(in crate::pb) mod network_v1; +#[path = "../target/pb/messari.entity.v1.rs"] +pub(in crate::pb) mod entity_v1; -pub mod network { +pub mod entity { pub mod v1 { - pub use super::super::network_v1::*; + pub use super::super::entity_v1::*; + } +} + +#[rustfmt::skip] +#[path = "../target/pb/messari.erc20.v1.rs"] +pub(in crate::pb) mod erc20_v1; + +pub mod erc20 { + pub mod v1 { + pub use super::super::erc20_v1::*; } } diff --git a/substreams-helper/src/token.rs b/substreams-helper/src/token.rs index 8d9b2214..b0d5e1a4 100644 --- a/substreams-helper/src/token.rs +++ b/substreams-helper/src/token.rs @@ -3,7 +3,7 @@ use num_bigint; use substreams::scalar::BigInt; use substreams_ethereum::pb::eth as pbeth; -pub const ETH_ADDRESS: &str = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; +pub const ETH_ADDRESS: &str = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"; pub fn get_eth_token() -> Option { let eth_token = Erc20Token { From eb72edf388349e24bf27c87f49af150a55fd6961 Mon Sep 17 00:00:00 2001 From: dmelotik Date: Thu, 6 Apr 2023 14:57:39 -0700 Subject: [PATCH 24/25] add latest code --- common/src/codegen.rs | 13 ++++++++++--- eth-balance/rust-toolchain.toml | 4 ++-- eth-balance/src/pb.rs | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/common/src/codegen.rs b/common/src/codegen.rs index 2bcdbf87..f55d393d 100644 --- a/common/src/codegen.rs +++ b/common/src/codegen.rs @@ -101,6 +101,9 @@ pub fn generate_pb(out_dir: Option<&str>) -> Result<(), Error> { // parse version from file name let filename = file.split('.').collect::>(); // let package_name = filename[0]; + if filename.len() < 2 { + continue; + } let name = filename[1].to_string(); let version = filename[2]; pb_files_hash @@ -139,6 +142,9 @@ pub fn generate_pb(out_dir: Option<&str>) -> Result<(), Error> { } } + // Cleanup + fs::remove_dir_all(&tmp_dir).unwrap(); + if !pb_files.is_empty() { let pb_file_content = pb_files .into_iter() @@ -149,9 +155,9 @@ pub fn generate_pb(out_dir: Option<&str>) -> Result<(), Error> { ( format!( "#[rustfmt::skip]\n\ - #[path = \"../{}/pb/{}.{}.{}.rs\"]\n\ - pub(in crate::pb) mod {2}_{3};\n", - out_dir, (if filename.contains("entity") {"substreams"} else {"messari"}), filename, version + #[path = \"../{}/pb/messari.{}.{}.rs\"]\n\ + pub(in crate::pb) mod {1}_{2};\n", + out_dir, filename, version ), format!( " pub mod {} {{\n \ @@ -162,6 +168,7 @@ pub fn generate_pb(out_dir: Option<&str>) -> Result<(), Error> { ) }) .unzip(); + format!( "{}\n\ pub mod {} {{\n\ diff --git a/eth-balance/rust-toolchain.toml b/eth-balance/rust-toolchain.toml index 0a0b90ae..374fe12b 100644 --- a/eth-balance/rust-toolchain.toml +++ b/eth-balance/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = "1.64.0" +channel = "1.67.0" components = [ "rustfmt" ] -targets = [ "wasm32-unknown-unknown" ] +targets = [ "wasm32-unknown-unknown" ] \ No newline at end of file diff --git a/eth-balance/src/pb.rs b/eth-balance/src/pb.rs index bf50187b..8f12a5af 100644 --- a/eth-balance/src/pb.rs +++ b/eth-balance/src/pb.rs @@ -1,5 +1,5 @@ #[rustfmt::skip] -#[path = "../target/pb/substreams.entity.v1.rs"] +#[path = "../target/pb/messari.entity.v1.rs"] pub(in crate::pb) mod entity_v1; pub mod entity { From 880344dade5adbe845a13fa813ea975cd4b89492 Mon Sep 17 00:00:00 2001 From: dmelotik Date: Tue, 11 Apr 2023 09:26:26 -0700 Subject: [PATCH 25/25] fix codegen.rs --- common/src/codegen.rs | 11 ++++++++--- compound-v2/src/pb.rs | 8 ++++---- erc20-price/src/pb.rs | 38 ++++++++++++++++++++++++++++++++++---- eth-balance/src/pb.rs | 2 +- network/src/pb.rs | 18 ++++-------------- 5 files changed, 51 insertions(+), 26 deletions(-) diff --git a/common/src/codegen.rs b/common/src/codegen.rs index f55d393d..249b0865 100644 --- a/common/src/codegen.rs +++ b/common/src/codegen.rs @@ -149,15 +149,20 @@ pub fn generate_pb(out_dir: Option<&str>) -> Result<(), Error> { let pb_file_content = pb_files .into_iter() .map(|(filename, versions)| { + let mut name = "messari".to_string(); + if filename == "entity".to_string() { + name = "substreams".to_string(); + } let (mod_content, registration_content): (Vec, Vec) = versions .into_iter() .map(|version| { ( + format!( "#[rustfmt::skip]\n\ - #[path = \"../{}/pb/messari.{}.{}.rs\"]\n\ - pub(in crate::pb) mod {1}_{2};\n", - out_dir, filename, version + #[path = \"../{}/pb/{}.{}.{}.rs\"]\n\ + pub(in crate::pb) mod {2}_{3};\n", + out_dir, name, filename, version ), format!( " pub mod {} {{\n \ diff --git a/compound-v2/src/pb.rs b/compound-v2/src/pb.rs index 963d1415..b6d84e80 100644 --- a/compound-v2/src/pb.rs +++ b/compound-v2/src/pb.rs @@ -1,9 +1,9 @@ #[rustfmt::skip] -#[path = "../target/pb/messari.compound.v1.rs"] -pub(in crate::pb) mod compound_v1; +#[path = "../target/pb/messari.erc721.v1.rs"] +pub(in crate::pb) mod erc721_v1; -pub mod compound { +pub mod erc721 { pub mod v1 { - pub use super::super::compound_v1::*; + pub use super::super::erc721_v1::*; } } diff --git a/erc20-price/src/pb.rs b/erc20-price/src/pb.rs index b6d84e80..fdb3e696 100644 --- a/erc20-price/src/pb.rs +++ b/erc20-price/src/pb.rs @@ -1,9 +1,39 @@ #[rustfmt::skip] -#[path = "../target/pb/messari.erc721.v1.rs"] -pub(in crate::pb) mod erc721_v1; +#[path = "../target/pb/messari.chainlink.v1.rs"] +pub(in crate::pb) mod chainlink_v1; -pub mod erc721 { +pub mod chainlink { pub mod v1 { - pub use super::super::erc721_v1::*; + pub use super::super::chainlink_v1::*; + } +} + +#[rustfmt::skip] +#[path = "../target/pb/messari.erc20.v1.rs"] +pub(in crate::pb) mod erc20_v1; + +pub mod erc20 { + pub mod v1 { + pub use super::super::erc20_v1::*; + } +} + +#[rustfmt::skip] +#[path = "../target/pb/messari.erc20_price.v1.rs"] +pub(in crate::pb) mod erc20_price_v1; + +pub mod erc20_price { + pub mod v1 { + pub use super::super::erc20_price_v1::*; + } +} + +#[rustfmt::skip] +#[path = "../target/pb/messari.uniswap.v1.rs"] +pub(in crate::pb) mod uniswap_v1; + +pub mod uniswap { + pub mod v1 { + pub use super::super::uniswap_v1::*; } } diff --git a/eth-balance/src/pb.rs b/eth-balance/src/pb.rs index 8f12a5af..bf50187b 100644 --- a/eth-balance/src/pb.rs +++ b/eth-balance/src/pb.rs @@ -1,5 +1,5 @@ #[rustfmt::skip] -#[path = "../target/pb/messari.entity.v1.rs"] +#[path = "../target/pb/substreams.entity.v1.rs"] pub(in crate::pb) mod entity_v1; pub mod entity { diff --git a/network/src/pb.rs b/network/src/pb.rs index 8f12a5af..d2daff74 100644 --- a/network/src/pb.rs +++ b/network/src/pb.rs @@ -1,19 +1,9 @@ #[rustfmt::skip] -#[path = "../target/pb/messari.entity.v1.rs"] -pub(in crate::pb) mod entity_v1; +#[path = "../target/pb/messari.network.v1.rs"] +pub(in crate::pb) mod network_v1; -pub mod entity { +pub mod network { pub mod v1 { - pub use super::super::entity_v1::*; - } -} - -#[rustfmt::skip] -#[path = "../target/pb/messari.erc20.v1.rs"] -pub(in crate::pb) mod erc20_v1; - -pub mod erc20 { - pub mod v1 { - pub use super::super::erc20_v1::*; + pub use super::super::network_v1::*; } }