convex-lisp

작성자: convex-dev

Convex Lisp 언어 참조 — CVM 규칙, 라이브러리 코드 호출, 액터 정의, juice 및 오류 코드. CVM 소스를 작성하거나 디버깅할 때 사용합니다…

npx skills add https://github.com/convex-dev/convex --skill convex-lisp

Convex Lisp

Shared conventions for all CVM source. The query, transact, deploy, token and transfer skills assume what is written here.

Units and Notation

  • Coin amounts are in copper. 1 CVM coin = 1,000,000,000 copper (10^9). Convert for display: report "1.5 CVM", not "1500000000".
  • Account addresses take a # prefix: #13, #1337.
  • CNS names take an @ prefix when resolved in source: @convex.fungible.

Calling Library Code

Resolve libraries through CNS rather than hardcoding addresses:

(@convex.fungible/balance #128 #13)

This is the idiom used throughout the codebase — match it. A let-bound address also works ((let [f @convex.fungible] (f/balance …))) and is occasionally tidier for repeated calls, but is rare in practice.

Never use import in query or transaction source. It mutates the account environment and costs extra juice on every transaction that carries it. Use the @name/fn form instead.

Library and actor bodies are different: they are deployed once, so an import at the top of a .cvx library resolves once and is idiomatic — the core libraries do it, for instance convex/trust/monitors.cvx. Do not "fix" those.

Actors

Actors are on-chain accounts with their own address, balance and state.

(deploy
  '(do
     (def counter 0)

     (defn ^:callable increment []
       (set! counter (+ counter 1))
       counter)))
  • ^:callable is the only export mechanism. There is no export form. The map form ^{:callable true} is equivalent and equally common in the core libraries.
  • defs in the actor body that are not ^:callable are private state. Update them from inside with set!.
  • deploy returns the new address. deploy also accepts a vector of code forms, which is how library builders are composed: (deploy [(build-token …) (add-mint …)]).
  • (set-controller #ADDR) sets who may upgrade the actor.

Juice and Memory

Transactions consume juice, paid in copper by the origin account, and consume memory allowance if they grow the state. Queries are free — they execute against current state and are discarded, so prefer a query whenever you only need to read.

See the juice skill for execution costs and memory for storage — including how to minimise and reclaim on-chain storage, which is worth reading before designing an actor that stores anything.

Error Codes

Errors surface as keywords. The ones you will actually hit:

CodeMeaning
:UNDECLAREDSymbol does not exist — usually a wrong function name
:CASTWrong type passed to a function
:ARGUMENTRight type, invalid value
:ARITYWrong number of arguments
:STATEOperation invalid for current state (e.g. missing callable)
:TRUSTCaller lacks rights for the operation
:FUNDSInsufficient coin balance
:JUICERan out of juice — transaction too expensive
:MEMORYInsufficient memory allowance
:NOBODYTarget account does not exist
:COMPILESource did not compile

:UNDECLARED on a library call almost always means the function name is wrong. Check the library source in convex-core/src/main/cvx/ rather than guessing — several plausible names (quantity, supply) do not exist.

Protocol Version

Write against protocol version 1 semantics — see the protocol-versions skill. Several core behaviours are fixed there rather than at genesis, so a network still at version 0 differs:

  • update and update-in drop an argument in their variadic (5+ arg) arities
  • quasiquote of a set or map containing an unquote yields a call form, ~false does not unquote, define evaluates its value twice, and call with too many arguments silently does nothing
  • dotimes, for, for-loop and switch can capture user variables in their expansions (#602) — v1 rebinds them hygienically
  • gensym, cat and splice do not exist (:UNDECLARED), and char? fails :CAST rather than :UNDECLARED — it is installed but version-gated, so do not read its pre-v1 failure as a missing function

If you hit one of these, it is a known genesis gap fixed by v1 — not something to work around in new code.

convex-dev의 다른 스킬

ecosystem
convex-dev
Convex 생태계에서의 방향 안내 — 어떤 리포지토리에 무엇이 있는지, 사양과 문서가 어디에 있는지, 그리고 어떤 클라이언트 라이브러리가 존재하는지. 컨텍스트가 필요할 때 사용하세요…
local-network
convex-dev
로컬 Convex 테스트 네트워크를 개발용으로 실행합니다. 라이브 네트워크에 대한 변경 사항을 테스트하거나, 피어 문제를 재현하거나, 원격 네트워크가 없을 때 사용합니다.
protocol-versions
convex-dev
프로토콜 버전, 마이그레이션 및 v1 업그레이드 — 어떤 의미론을 기준으로 작성할지, 그리고 네트워크를 포크하지 않고 CVM 동작을 변경하는 방법. 다음 경우에 사용하세요…
etch
convex-dev
Etch 스토어를 검사하고 유지 관리합니다 — Convex의 콘텐츠 주소 지정 데이터베이스입니다. 피어 저장소를 검사하거나, 손상을 진단하거나, 가비지 컬렉션을 수행할 때 사용합니다.
juice
convex-dev
Juice 회계 — CVM에서의 연산 및 대역폭 비용. 트랜잭션 실행 비용을 추론하거나, :JUICE 실패를 진단하거나, …할 때 사용합니다.
trust
convex-dev
Trust 모니터 — Convex의 구성 가능한 온체인 인가 모델. 접근 제어 작성, 액터 함수 제한, 발행 권한 정의 시 사용합니다…
memory
convex-dev
메모리 회계 및 허용량 — 온체인 저장 비용, 그리고 이를 최소화하고 회수하는 방법. 상태 성장에 대해 추론하거나, 진단할 때 사용하세요…
peer
convex-dev
Convex 피어를 운영합니다 — 네트워크 제네시스를 생성, 시작, 나열, 백업 또는 인스턴스화합니다. 네트워크에 대해 피어를 실행하거나 새 네트워크를 설정할 때 사용합니다.