@@ -12,6 +12,8 @@ import (
1212 "time"
1313
1414 "github.com/ethereum/go-ethereum/common"
15+ "github.com/nathfavour/settlerengine/internal/adapters/crypto/erc8004"
16+ "github.com/nathfavour/settlerengine/internal/adapters/crypto/mantle"
1517 "github.com/nathfavour/settlerengine/internal/domain"
1618 "github.com/nathfavour/settlerengine/pkg/anyisland"
1719 "github.com/nathfavour/settlerengine/pkg/crypto"
@@ -41,6 +43,8 @@ func main() {
4143 runFacilitator (os .Args [2 :])
4244 case "pay" :
4345 runPay (os .Args [2 :])
46+ case "demo" :
47+ runDemo (os .Args [2 :])
4448 case "help" :
4549 printUsage ()
4650 default :
@@ -58,9 +62,75 @@ func printUsage() {
5862 fmt .Println (" proxy Start the x402 reverse proxy" )
5963 fmt .Println (" facilitator Start the settlement facilitator daemon" )
6064 fmt .Println (" pay Execute a policy-protected payment" )
65+ fmt .Println (" demo Run a full agentic demo with Mantle on-chain anchoring" )
6166 fmt .Println (" help Show this help message" )
6267}
6368
69+ func runDemo (args []string ) {
70+ fmt .Println ("🎬 Starting SettlerEngine Agentic Demo..." )
71+
72+ privKey := os .Getenv ("PRIVATE_KEY" )
73+ if privKey == "" {
74+ log .Fatal ("❌ PRIVATE_KEY environment variable is required for demo" )
75+ }
76+
77+ // 1. ERC-8004 Identity Resolution
78+ fmt .Println ("🤖 [1/3] Resolving Agent Identity (ERC-8004)..." )
79+ registry , _ := erc8004 .NewRegistryClient (
80+ "https://rpc.sepolia.mantle.xyz" ,
81+ common .HexToAddress ("0x8004000000000000000000000000000000000001" ),
82+ common .HexToAddress ("0x8004000000000000000000000000000000000002" ),
83+ common .HexToAddress ("0x8004000000000000000000000000000000000003" ),
84+ )
85+
86+ agentID := big .NewInt (42 )
87+ identity , _ := registry .ResolveAgent (context .Background (), agentID )
88+ fmt .Printf ("✅ Identity Verified: %s\n " , identity .Metadata .Name )
89+
90+ // 2. Policy-Protected Payment Handshake
91+ fmt .Println ("💰 [2/3] Performing Policy-Protected Payment..." )
92+ max , _ := new (big.Int ).SetString ("1000000000000000000" , 10 )
93+ policy := domain .NewPaymentPolicy ("demo-policy" , max , nil , time.Time {})
94+
95+ amount := big .NewInt (1000 )
96+ recipient := common .HexToAddress ("0x1234567890123456789012345678901234567890" )
97+
98+ if err := policy .Check (amount , recipient ); err != nil {
99+ log .Fatalf ("❌ Policy Violation: %v" , err )
100+ }
101+ fmt .Println ("✅ Payment Approved by local guardrails." )
102+
103+ // 3. Mantle On-Chain Anchoring
104+ fmt .Println ("⚓ [3/3] Anchoring transaction to Mantle Sepolia..." )
105+ mantleClient , err := mantle .NewRegistryClient (
106+ "https://rpc.sepolia.mantle.xyz" ,
107+ common .HexToAddress ("0x33aE8331a2406EEc3A33483001aC5650DA2e0662" ),
108+ big .NewInt (5003 ),
109+ )
110+ if err != nil {
111+ log .Fatalf ("❌ Failed to connect to Mantle: %v" , err )
112+ }
113+
114+ var agentBytes [32 ]byte
115+ copy (agentBytes [:], agentID .Bytes ())
116+
117+ txHash , err := mantleClient .LogPayment (
118+ context .Background (),
119+ privKey ,
120+ agentBytes ,
121+ big .NewInt (1337 ), // Demo Invoice ID
122+ amount ,
123+ "Demo agent payment anchored via SettlerEngine" ,
124+ )
125+ if err != nil {
126+ log .Fatalf ("❌ On-chain anchoring failed: %v" , err )
127+ }
128+
129+ fmt .Printf ("🚀 SUCCESS! On-chain footprint created.\n " )
130+ fmt .Printf ("🔗 Transaction Hash: %s\n " , txHash )
131+ fmt .Printf ("🌍 Explorer: https://explorer.sepolia.mantle.xyz/tx/%s\n " , txHash )
132+ }
133+
64134func runPay (args []string ) {
65135 fs := flag .NewFlagSet ("pay" , flag .ExitOnError )
66136 fs .String ("rpc" , "https://sepolia.base.org" , "Ethereum RPC URL" )
0 commit comments