Skip to content

Instantly share code, notes, and snippets.

@infu
Created July 1, 2022 13:21
Show Gist options
  • Save infu/ec29a89de63308378a33bbf6dc64a884 to your computer and use it in GitHub Desktop.
Save infu/ec29a89de63308378a33bbf6dc64a884 to your computer and use it in GitHub Desktop.
Anvil - Glue integration proposal
Variant 1)
@challenge_data has inside {@role, @guild_id, custom_matching_patterns (this will allow matching like strenght > 10 or has_tag, glue doesn't care about it, for glue its just a blob)}
1) User clicks a link leading to Glue
2) User uses "Log In With Discord" (glue backend now has: @guild_id, @user_id, @challenge_data)
3) User clicks "Connect with Anvil" or "Prove with Anvil" and gets sent to https://nftanvil.com (anvil frontend now has: @return_url, @challenge_data)
4) User selects an NFT and then clicks "Prove".
5) Anvil's smart contracts parse the @challenge_data and verify if it matches
6) A transaction is generated with @memo (32byte hash of @challenge_data)
7) Anvil frontend sends the user back to @return_url giving it @transaction_id
8) Glue backend queries Anvil and checks if the @transaction_id has the exact @memo
(limitation 2 - users can pass the nft around and all get the role with one NFT, unless glue keeps track of nft_id-user_id and removes user roles)
Variant 2)
1) User clicks a link leading to Glue
2) User uses "Log In With Discord" (glue backend now has: @guild_id, @user_id, @subaccount)
3) User clicks "Connect with Anvil" gets sent to https://nftanvil.com
4) User hits "Sign message"
5) Message is sent back to Glue, which can verify that a principal has signed it
6) Glue checks if @principal+@subaccount owns NFT
(limitation 1 - can only proof if user has nft collection or not)
(limitation 2 - users can pass the nft around and all get the role with one NFT)
Variant 3)
(Server admin adds @name:text - @role:id - @challenge:blob) Anvil will provide interface to the user so they can create these challenges and use will copy/paste them to Glue add command
1) Glue bot provides menu like this https://discord.com/developers/docs/interactions/message-components#select-menus
with role->challenges added by server owner.
2) When triggered, Glue makes http request to Anvil's backend (not web3) and gets a request specific link which it gives to the user (invisible to others)
3) User clicks on the link and does something, glue doesn't care what exactly
4) Anvil triggers Glue web hook with success or failiure
5) When user transfers or burns the used nft at some point in time, Anvil backend (listening to Anvil transaction blockchain - like CAP) will call
the web hook and tell Glue challenge is not valid anymore, so Glue will remove the role.
(cons: uses the Anvil centralised backend)
(pros: more versatile and Glue doesn't have to understand the challenges, nor keep track of every IC blockchain)
@infu
Copy link
Author

infu commented Jul 1, 2022

I prefer 3. It is on the roadmap to create transaction listening (state rebuilding) nodejs daemon. Anyone can run these, which will make Variant 3 decentralised at some point

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment