register_loyalty_program
Register deployed tokens as loyalty programs in the database to manage on-chain rewards, track balances, and handle marketplace offers on Base L2.
Instructions
Register a deployed token as a loyalty program in the database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Program name | |
| symbol | Yes | Token symbol | |
| token_address | Yes | Deployed token contract address (0x...) | |
| expiration_days | No | Duration in days (default: 365) |
Implementation Reference
- supabase/functions/loyalty-mcp/index.ts:65-67 (registration)Registration of the register_loyalty_program tool within the MCP server.
mcpServer.tool("register_loyalty_program", { description: "Register a deployed token as a loyalty program in the database", inputSchema: { type: "object" as const, properties: { name: { type: "string", description: "Program name" }, symbol: { type: "string", description: "Token symbol" }, token_address: { type: "string", description: "Deployed token contract address (0x...)" }, expiration_days: { type: "number", description: "Duration in days (default: 365)" } }, required: ["name", "symbol", "token_address"] }, - Handler function for register_loyalty_program, which inserts the program into the database.
handler: async ({ name, symbol, token_address, expiration_days }: any) => { const err = authGuard(["mint", "create_program"]); if (err) return T(err); if (!/^0x[a-fA-F0-9]{40}$/.test(token_address)) return T('{"error":"Invalid token_address"}'); const d = db(); const { data: existing } = await d.from("loyalty_programs").select("id").eq("token_address", token_address.toLowerCase()).single(); if (existing) return T('{"error":"Program already registered"}'); const days = expiration_days || 365; const expDate = new Date(Date.now() + days * 24 * 60 * 60 * 1000).toISOString(); const { data: program, error } = await d.from("loyalty_programs").insert({ name: name.trim(), symbol: symbol.toUpperCase().trim(), token_address: token_address.toLowerCase(), merchant_address: agent.ownerAddress, status: "inactive", expiration_date: expDate }).select("id,name,symbol,token_address,status,expiration_date,created_at").single(); if (error) return T(JSON.stringify({ error: error.message })); return T(JSON.stringify({ program, message: "Program registered as inactive. Call activate_loyalty_program next." })); },