holic / chirp-city

a lil birb told me
https://chirp.city
3 stars 0 forks source link

Parse @-mentions for ENS names in subgraph? #3

Closed holic closed 2 years ago

holic commented 2 years ago

My intention is to get the frontend wired up in a way that @-mentions link up automatically to profiles (like Twitter), but swap out the @-mention text for the corresponding address (if @-mentioning a username) before writing to the contract. So something like

@frolic.eth hey!

becomes

@0xC9C... hey!

(frontend will turn this back into @frolic.eth during display)

That way the subgraph will have an easy time parsing out addresses.

Alternatively, I could just let these get written to the contract as @-mentions of ENS names and let the subgraph parse them out + look up the address. Subgraphs do (as I understand it) do point-in-time calls to other contracts. However, the ENS contracts expect a namehash, which is generally calculated off-chain because it's messy and doing this in Solidity would be too gas heavy (if not impossible). May not be possible without some help from Graph Protocol folks to bake in some ENS helpers.

holic commented 2 years ago

I think in order to map ENS names back to an address via subgraph or contract call, the subgraph would need a way to create a namehash from the ENS name. Looks pretty tricky since subgraph mapping code is compiled down AssemblyScript, which has limited capabilities compared to a full JS VM, and can't use any standard npm module. Would probably need a lot of work to port this over, so I'm gonna punt on this for now.

https://docs.ens.domains/contract-api-reference/name-processing https://github.com/hexonet/idna-uts46/blob/master/uts46.js https://github.com/mathiasbynens/punycode.js/blob/master/punycode.js

Maybe there's something in the ENS subgraph code that we can replicate? https://github.com/ensdomains/ens-subgraph/tree/master/src