From 8f8a561aa9f48f84e22fcf8d4ff5a81d33db0d9c Mon Sep 17 00:00:00 2001 From: Shreerang Kale Date: Fri, 25 Jul 2025 11:29:21 +0530 Subject: [PATCH] Add script to run commands for publishing records from container --- .env.example | 5 +- deploy/README.md | 29 +++--- deploy/laconic-cli.sh | 50 ++++++++++ deploy/publish-pricing.md | 168 ++++++++++++++++++-------------- src/app/api/registry/route.ts | 6 -- src/components/PaymentModal.tsx | 3 - src/config/index.ts | 12 +-- src/services/registry.ts | 4 +- src/types/index.ts | 3 - 9 files changed, 167 insertions(+), 113 deletions(-) create mode 100755 deploy/laconic-cli.sh diff --git a/.env.example b/.env.example index df7daba..fb64ae2 100644 --- a/.env.example +++ b/.env.example @@ -20,9 +20,8 @@ NEXT_PUBLIC_EXAMPLE_URL=https://git.vdb.to/cerc-io/test-progressive-web-app NEXT_PUBLIC_REGISTRY_CHAIN_ID=laconic-mainnet NEXT_PUBLIC_REGISTRY_RPC_ENDPOINT=https://laconicd-mainnet-1.laconic.com NEXT_PUBLIC_REGISTRY_GQL_ENDPOINT=https://laconicd-mainnet-1.laconic.com/graphql -NEXT_PUBLIC_REGISTRY_GAS_PRICE=0.001 -NEXT_PUBLIC_ALNT_COST_LRN= -NEXT_PUBLIC_DEPLOYMENT_COST_LRN= +NEXT_PUBLIC_ALNT_COST_LRN=lrn://laconic/pricing/alnt +NEXT_PUBLIC_DEPLOYMENT_COST_LRN=lrn://laconic/pricing/webapp-deployment REGISTRY_BOND_ID= REGISTRY_AUTHORITY= REGISTRY_USER_KEY= diff --git a/deploy/README.md b/deploy/README.md index be5ed5f..71a087f 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -1,17 +1,26 @@ # Deploy +## Prerequisites + +This project requires pricing records for cost of deployment and cost of alnt to be published + +- Cost of deployment: `lrn://laconic/pricing/webapp-deployment` +- Cost of alnt: `lrn://laconic/pricing/alnt` + +If these records are not available, [follow these steps to publish them](./publish-pricing.md) + ## Setup ### gor-deploy -* Clone the repo: +- Clone the repo: ```bash git clone git@git.vdb.to:LaconicNetwork/gor-deploy.git cd gor-deploy/deploy ``` -* Build registry CLI image: +- Build registry CLI image: ```bash docker build -t cerc/laconic-registry-cli . @@ -19,13 +28,13 @@ # Builds image cerc/laconic-registry-cli:latest ``` -* Configure `userKey` and `bondId` in the [registry CLI config](./config.yml): +- Configure `userKey` and `bondId` in the [registry CLI config](./config.yml): ```bash nano config.yml ``` -* Add configuration for registry operations: +- Add configuration for registry operations: ```bash cp .registry.env.example .registry.env @@ -34,7 +43,7 @@ nano .registry.env ``` -* Add configuration for the app: +- Add configuration for the app: ```bash curl -s https://git.vdb.to/LaconicNetwork/gor-deploy/src/branch/main/.env.example -o .app.env @@ -45,9 +54,7 @@ ## Run -### gor-deploy - -* Deploy `gor-deploy` App: +- Deploy `gor-deploy` App: ```bash # In gor-deploy/deploy dir @@ -58,13 +65,13 @@ ./deploy.sh ``` -* Check deployment logs on deployer UI: +- Check deployment logs on deployer UI: -* Visit deployed app: +- Visit deployed app: ### Remove deployment -* Remove deployment: +- Remove deployment: ```bash # In gor-deploy/deploy dir diff --git a/deploy/laconic-cli.sh b/deploy/laconic-cli.sh new file mode 100755 index 0000000..2325582 --- /dev/null +++ b/deploy/laconic-cli.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +# Laconic Registry CLI Docker wrapper script +# This script wraps the Docker command to run laconic registry CLI commands +# Run this script from the deploy directory + +# Check if docker is available +if ! command -v docker &> /dev/null; then + echo "Error: Docker is not installed or not in PATH" + exit 1 +fi + +# Check if the cerc/laconic-registry-cli image exists +if ! docker image inspect cerc/laconic-registry-cli &> /dev/null; then + echo "Error: cerc/laconic-registry-cli Docker image not found" + echo "Please build the image first: docker build -t cerc/laconic-registry-cli ." + exit 1 +fi + +# Get current directory (should be deploy directory) +CURRENT_DIR="$(pwd)" +PROJECT_ROOT="$(dirname "$CURRENT_DIR")" + +# Verify we're in the deploy directory +if [ ! -f "config.yml" ] || [ ! -f "laconic-cli.sh" ]; then + echo "Error: This script must be run from the deploy directory" + echo "Current directory: $CURRENT_DIR" + echo "Please cd to the deploy directory and run: ./laconic-cli.sh" + exit 1 +fi + +# Set up volume mounts +DEPLOY_MOUNT="-v $CURRENT_DIR:/app/deploy" +OUT_MOUNT="" + +# Create out directory if it doesn't exist and always mount it +if [ ! -d "out" ]; then + mkdir -p "out" +fi +OUT_MOUNT="-v $CURRENT_DIR/out:/app/out" + +# Run the Docker command with processed arguments +docker run --rm \ + --add-host=host.docker.internal:host-gateway \ + $DEPLOY_MOUNT \ + $OUT_MOUNT \ + -w /app/deploy \ + cerc/laconic-registry-cli \ + laconic registry -c config.yml \ + "$@" diff --git a/deploy/publish-pricing.md b/deploy/publish-pricing.md index 7133299..79b077a 100644 --- a/deploy/publish-pricing.md +++ b/deploy/publish-pricing.md @@ -1,35 +1,36 @@ # publish-pricing -## Prerequisites - -- Install packages: - - ```bash - npm install - ``` - ## Setup +- Clone the repo: + + ```bash + git clone git@git.vdb.to:LaconicNetwork/gor-deploy.git + cd gor-deploy/deploy + ``` + +- Build the Docker container: + + ```bash + docker build -t cerc/laconic-registry-cli . + + # Builds image cerc/laconic-registry-cli:latest + ``` + +- Make the CLI script executable: + + ```bash + chmod +x laconic-cli.sh + ``` + - Configure `userKey` in the [registry CLI config](./config.yml): + NOTE: User key should be of the account that owns the `laconic` authority + ```bash nano config.yml ``` -## Create Bond (optional) - -- Create bond: - - ```bash - npm run laconic -- bond create --type alnt --quantity 100000000 - ``` - -- Get bond info: - - ```bash - npm run laconic -- bond get --id - ``` - ## Publish Record NOTE: Publishing record requires a bond with enough funds, if you don't have a bond check [steps to create bond](#create-bond-optional) @@ -48,18 +49,18 @@ NOTE: Publishing record requires a bond with enough funds, if you don't have a b - Amount calculation: - Cost of 1 deployment is `12960` in terms of `alnt` or `5` in terms of `USD` - - So cost of 1 `alnt` comes out be `0.000385802 USD` rounded off to 6 decimals + - Hence, cost of 1 `alnt` comes out be `0.000385802 USD` rounded off to 6 decimals - Publish the record: ```bash - npm run laconic -- record publish --filename deploy/pricing.yml --bond-id + ./laconic-cli.sh record publish --filename pricing.yml --bond-id ``` - Get record info: ```bash - npm run laconic -- record get --id + ./laconic-cli.sh record get --id ``` ### Publish Record for Cost of Deployment @@ -77,73 +78,29 @@ NOTE: Publishing record requires a bond with enough funds, if you don't have a b - Publish the record: ```bash - npm run laconic -- record publish --filename deploy/pricing.yml --bond-id + ./laconic-cli.sh record publish --filename pricing.yml --bond-id ``` - Get record info: ```bash - npm run laconic -- record get --id - ``` - -## Reserve a New Authority (optional) - -- Reserve authority: - - ```bash - npm run laconic -- authority reserve laconic - ``` - -- Check authority info: - - ```bash - npm run laconic -- authority whois laconic - ``` - - - Note down auction ID from authority info as it is required in next steps - -- Get auction info: - - ```bash - npm run laconic -- auction get - ``` - -- Commit an auction bid: - - ```bash - npm run laconic -- auction bid commit 25000000 alnt - - Reveal file: ./out/bafyreiay2rccax64yn4ljhvzvm3jkbebvzheyucuma5jlbpzpzd5i5gjuy.json - ``` - -- Reveal bid: - - ```bash - npm run laconic -- auction bid reveal ./out/bafyreiay2rccax64yn4ljhvzvm3jkbebvzheyucuma5jlbpzpzd5i5gjuy.json - ``` - -### Set Authority Bond - -- Set authority bond after winning auction: - - ```bash - npm run laconic -- authority bond set laconic + ./laconic-cli.sh record get --id ``` ## Set Record Name -NOTE: To set record name an authority with an authority bond is required +NOTE: To set record name an authority with an authority bond is required, if you don't have an authority check [steps to reserve a new authority](#reserve-a-new-authority-optional) - Set record name for cost of alnt record ```bash - npm run laconic -- name set lrn:///pricing/alnt + ./laconic-cli.sh name set lrn://laconic/pricing/alnt ``` - Set record name for cost of deployment record ```bash - npm run laconic -- name set lrn:///pricing/webapp-deployment + ./laconic-cli.sh name set lrn://laconic/pricing/webapp-deployment ``` ## Delete Record Name @@ -151,5 +108,66 @@ NOTE: To set record name an authority with an authority bond is required - Delete record name: ```bash - npm run laconic -- name delete + ./laconic-cli.sh name delete + ``` + +## Create Bond (optional) + +- Create bond: + + ```bash + ./laconic-cli.sh bond create --type alnt --quantity 100000000 + ``` + +- Get bond info: + + ```bash + ./laconic-cli.sh bond get --id + ``` + +## Reserve a New Authority (optional) + +Below steps are used to reserve `laconic` authority + +- Reserve authority: + + ```bash + ./laconic-cli.sh authority reserve laconic + ``` + +- Check authority info: + + ```bash + ./laconic-cli.sh authority whois laconic + ``` + + - Note down auction ID from authority info as it is required in next steps + +- Get auction info: + + ```bash + ./laconic-cli.sh auction get + ``` + +- Commit an auction bid: + + ```bash + ./laconic-cli.sh auction bid commit 25000000 alnt + + # Path inside container + Reveal file: /app/deploy/out/bafyreiay2rccax64yn4ljhvzvm3jkbebvzheyucuma5jlbpzpzd5i5gjuy.json + ``` + +- Reveal bid: + + ```bash + ./laconic-cli.sh auction bid reveal /app/deploy/out/bafyreiay2rccax64yn4ljhvzvm3jkbebvzheyucuma5jlbpzpzd5i5gjuy.json + ``` + +### Set Authority Bond + +- Set authority bond after winning auction: + + ```bash + ./laconic-cli.sh authority bond set laconic ``` diff --git a/src/app/api/registry/route.ts b/src/app/api/registry/route.ts index 7ec48f0..78f1388 100644 --- a/src/app/api/registry/route.ts +++ b/src/app/api/registry/route.ts @@ -3,9 +3,7 @@ import { NextRequest, NextResponse } from 'next/server'; import axios from 'axios'; import assert from 'assert'; -import { GasPrice } from '@cosmjs/stargate'; import { Connection } from '@solana/web3.js'; -import { DENOM as ALNT_DENOM } from '@cerc-io/registry-sdk'; import { verifyUnusedSolanaPayment } from '@/utils/solana-verify'; import { transferLNTTokens } from '@/services/laconic-transfer'; @@ -351,10 +349,6 @@ export async function POST(request: NextRequest) { const deployerLrn = process.env.DEPLOYER_LRN!; - // Create Registry client instance - const gasPrice = GasPrice.fromString(config.fee.gasPrice + ALNT_DENOM); - console.log('Using manual gas price:', gasPrice); - const registry = getRegistry() // Create LRN for the application with commit hash diff --git a/src/components/PaymentModal.tsx b/src/components/PaymentModal.tsx index be9e330..2e6f212 100644 --- a/src/components/PaymentModal.tsx +++ b/src/components/PaymentModal.tsx @@ -17,9 +17,6 @@ assert(!IS_NAT_GOR_TRANSFER_ENABLED || process.env.NEXT_PUBLIC_GORBAGANA_RPC_URL const GORBAGANA_RPC_URL = process.env.NEXT_PUBLIC_GORBAGANA_RPC_URL; -assert(process.env.NEXT_PUBLIC_SOLANA_RPC_URL, 'SOLANA_RPC_URL is required'); -assert(process.env.NEXT_PUBLIC_PRICING_RECORD_LRN, 'DEPLOYMENT_RECORD_LRN is required'); - export default function PaymentModal({ isOpen, onClose, diff --git a/src/config/index.ts b/src/config/index.ts index 0a9954b..bbd2591 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -1,5 +1,4 @@ -import { Registry, DENOM as ALNT_DENOM } from '@cerc-io/registry-sdk'; -import { GasPrice } from '@cosmjs/stargate'; +import { Registry } from '@cerc-io/registry-sdk'; import { RegistryConfig } from '../types'; @@ -8,12 +7,11 @@ let registryInstance: Registry | null = null; export const getRegistry = (): Registry => { if (!registryInstance) { const config = getClientRegistryConfig(); - const gasPrice = GasPrice.fromString(config.fee.gasPrice + ALNT_DENOM); registryInstance = new Registry( config.gqlEndpoint, config.rpcEndpoint, - { chainId: config.chainId, gasPrice } + { chainId: config.chainId } ); } return registryInstance; @@ -24,9 +22,6 @@ export const getClientRegistryConfig = () => { chainId: process.env.NEXT_PUBLIC_REGISTRY_CHAIN_ID!, rpcEndpoint: process.env.NEXT_PUBLIC_REGISTRY_RPC_ENDPOINT!, gqlEndpoint: process.env.NEXT_PUBLIC_REGISTRY_GQL_ENDPOINT!, - fee: { - gasPrice: process.env.NEXT_PUBLIC_REGISTRY_GAS_PRICE!, - }, }; }; @@ -54,8 +49,5 @@ export const getRegistryConfig = (): RegistryConfig => { bondId: process.env.REGISTRY_BOND_ID!, authority: process.env.REGISTRY_AUTHORITY!, privateKey: process.env.REGISTRY_USER_KEY!, - fee: { - gasPrice: process.env.REGISTRY_GAS_PRICE || '0.001', - }, }; }; diff --git a/src/services/registry.ts b/src/services/registry.ts index 4962d89..8a9c226 100644 --- a/src/services/registry.ts +++ b/src/services/registry.ts @@ -3,8 +3,8 @@ import assert from 'assert'; import { getRegistry } from '@/config'; import { CreateRecordResponse, PricingRecordAttributes, PaymentMethod } from '../types'; -assert(process.env.NEXT_PUBLIC_DEPLOYMENT_COST_LRN, 'DEPLOYMENT_RECORD_LRN is required'); -assert(process.env.NEXT_PUBLIC_ALNT_COST_LRN, 'DEPLOYMENT_RECORD_LRN is required'); +assert(process.env.NEXT_PUBLIC_DEPLOYMENT_COST_LRN, 'DEPLOYMENT_COST_LRN is required'); +assert(process.env.NEXT_PUBLIC_ALNT_COST_LRN, 'ALNT_COST_LRN is required'); const DEPLOYMENT_COST_LRN = process.env.NEXT_PUBLIC_DEPLOYMENT_COST_LRN; const DEPLOYMENT = 'webapp-deployment'; diff --git a/src/types/index.ts b/src/types/index.ts index 9dab16e..16258a6 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -10,9 +10,6 @@ export interface RegistryConfig { bondId: string; authority: string; privateKey: string; - fee: { - gasPrice: string; - }; } export interface CreateRecordResponse {