Skip to content

Commit 80c20d3

Browse files
committed
feat: add Txtx language
Add support for Txtx, a declarative language for Web3 smart contract runbooks. Includes grammar, samples, and language configuration.
1 parent a7e40d3 commit 80c20d3

11 files changed

Lines changed: 740 additions & 0 deletions

File tree

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,6 +1307,9 @@
13071307
[submodule "vendor/grammars/turtle.tmbundle"]
13081308
path = vendor/grammars/turtle.tmbundle
13091309
url = https://github.com/peta/turtle.tmbundle
1310+
[submodule "vendor/grammars/txtx-grammar"]
1311+
path = vendor/grammars/txtx-grammar
1312+
url = https://github.com/txtx/txtx-grammar.git
13101313
[submodule "vendor/grammars/typespec"]
13111314
path = vendor/grammars/typespec
13121315
url = https://github.com/microsoft/typespec.git

grammars.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,8 @@ vendor/grammars/toml.tmbundle:
11621162
vendor/grammars/turtle.tmbundle:
11631163
- source.sparql
11641164
- source.turtle
1165+
vendor/grammars/txtx-grammar:
1166+
- source.tx
11651167
vendor/grammars/typespec:
11661168
- source.tsp
11671169
vendor/grammars/typst-grammar:

lib/linguist/languages.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7909,6 +7909,16 @@ Twig:
79097909
codemirror_mode: twig
79107910
codemirror_mime_type: text/x-twig
79117911
language_id: 377
7912+
Txtx:
7913+
type: programming
7914+
color: "#00D992"
7915+
aliases:
7916+
- tx
7917+
extensions:
7918+
- ".tx"
7919+
tm_scope: source.tx
7920+
ace_mode: text
7921+
language_id: 871036660
79127922
Type Language:
79137923
type: data
79147924
aliases:

samples/Txtx/bns-registration.tx

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
addon "stacks" {
2+
network_id = input.stacks_network_id
3+
rpc_api_url = input.stacks_api_url
4+
}
5+
6+
signer "alice" "stacks::web_wallet" {
7+
expected_address = "ST2JHG361ZXG51QTKY2NQCVBPPRRE2KZB1HR05NNC"
8+
}
9+
10+
action "get_name_price" "stacks::call_readonly_fn" {
11+
description = "Preorder name"
12+
contract_id = "ST000000000000000000002AMW42H.bns"
13+
function_name = "get-name-price"
14+
function_args = [
15+
stacks::cv_buff(encode_hex(variable.namespace)),
16+
stacks::cv_buff(encode_hex(variable.name))
17+
]
18+
sender = "ST2JHG361ZXG51QTKY2NQCVBPPRRE2KZB1HR05NNC"
19+
}
20+
21+
action "send_name_preorder" "stacks::call_contract" {
22+
description = "Send Preorder ${variable.name}.${variable.namespace} transaction"
23+
contract_id = "ST000000000000000000002AMW42H.bns"
24+
function_name = "name-preorder"
25+
function_args = [
26+
stacks::cv_buff(
27+
ripemd160(sha256(
28+
[
29+
encode_hex("${variable.name}.${variable.namespace}"),
30+
encode_hex(variable.salt)
31+
]
32+
))
33+
),
34+
stacks::cv_uint(action.get_name_price.value),
35+
]
36+
post_condition_mode = "allow"
37+
signer = signer.alice
38+
confirmations = 1
39+
}
40+
41+
action "send_name_register" "stacks::call_contract" {
42+
description = "Register name"
43+
contract_id = "ST000000000000000000002AMW42H.bns"
44+
function_name = "name-register"
45+
function_args = [
46+
stacks::cv_buff(encode_hex(variable.namespace)),
47+
stacks::cv_buff(encode_hex(variable.name)),
48+
stacks::cv_buff(encode_hex(variable.salt)),
49+
stacks::cv_buff(encode_hex(variable.zonefile)),
50+
]
51+
signer = signer.alice
52+
confirmations = 1
53+
depends_on = [action.send_name_preorder]
54+
}

samples/Txtx/evm-deployment.tx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
addon "evm" {
2+
chain_id = 11155111
3+
rpc_api_url = "http://localhost:8545"
4+
}
5+
6+
signer "alice" "evm::web_wallet" {
7+
expected_address = "0xCe246168E59dd8e28e367BB49b38Dc621768F425"
8+
}
9+
10+
variable "contract" {
11+
value = evm::get_contract_from_foundry_project("SimpleStorage")
12+
}
13+
14+
action "deploy_simple_storage" "evm::deploy_contract_create2" {
15+
description = "Deploy SimpleStorage"
16+
contract = evm::get_contract_from_foundry_project("SimpleStorage")
17+
constructor_args = [14]
18+
salt = "0x0000000000000000000000000000000000000000177317f7617d575e615800c7"
19+
confirmations = 4
20+
signer = signer.alice
21+
expected_contract_address = "0x26eA4F95a9D93EB5B97b2cFE6D9D6Dee6DA09E9b"
22+
}
23+
24+
action "call_simple_storage" "evm::call_contract" {
25+
contract_abi = variable.contract.abi
26+
contract_address = action.deploy_simple_storage.contract_address
27+
function_name = "retrieve"
28+
function_args = []
29+
confirmations = 4
30+
signer = signer.alice
31+
}
32+
33+
output "contract_address" {
34+
value = action.deploy_simple_storage.contract_address
35+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
################################################################
2+
# Manage price-feed deployment through Crypto Infrastructure as Code
3+
################################################################
4+
5+
addon "svm" {
6+
rpc_api_url = input.rpc_api_url
7+
network_id = input.network_id
8+
}
9+
10+
action "deploy_price_feed" "svm::deploy_program" {
11+
description = "Deploy price_feed program"
12+
program = svm::get_program_from_anchor_project("price_feed")
13+
authority = signer.authority
14+
payer = signer.payer
15+
}

samples/Txtx/svm-pyth-arbitrage.tx

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
addon "svm" {
2+
rpc_api_url = input.rpc_api_url
3+
network_id = input.network_id
4+
}
5+
6+
variable "program" {
7+
value = svm::get_program_from_anchor_project("hello_pyth")
8+
}
9+
10+
variable "starting_pair" {
11+
description = "BTC/USD"
12+
value = "4cSM2e6rvbGQUFiJbqytoVMi5GgghSMr8LwVrT9VPSPo"
13+
editable = true
14+
}
15+
16+
variable "starting_pair_feed_id" {
17+
description = "BTC/USD feed ID"
18+
value = "0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43"
19+
editable = true
20+
}
21+
22+
variable "bridging_pair" {
23+
description = "ETH/BTC"
24+
value = "5JwbqPPMNpzE2jVAdobWo6m5gkhsDhRdGBo3FYbSfmaK"
25+
editable = true
26+
}
27+
28+
variable "bridging_pair_feed_id" {
29+
description = "ETH/BTC feed ID"
30+
value = "0xc96458d393fe9deb7a7d63a0ac41e2898a67a7750dbd166673279e06c868df0a"
31+
editable = true
32+
}
33+
34+
variable "crossing_pair" {
35+
description = "ETH/USD"
36+
value = "42amVS4KgzR9rA28tkVYqVXjq9Qa8dcZQMbH5EYFX6XC"
37+
editable = true
38+
}
39+
40+
variable "crossing_pair_feed_id" {
41+
description = "ETH/USD feed ID"
42+
value = "0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace"
43+
editable = true
44+
}
45+
46+
action "call" "svm::process_instructions" {
47+
signers = [signer.caller]
48+
instruction {
49+
program_idl = variable.program.idl
50+
instruction_name = "update_triangular_arbitrage"
51+
instruction_args = [
52+
variable.starting_pair_feed_id,
53+
variable.bridging_pair_feed_id,
54+
variable.crossing_pair_feed_id,
55+
]
56+
sender {
57+
public_key = signer.caller.public_key
58+
}
59+
starting_pair_account {
60+
public_key = variable.starting_pair
61+
}
62+
bridging_pair_account {
63+
public_key = variable.bridging_pair
64+
}
65+
crossing_pair_account {
66+
public_key = variable.crossing_pair
67+
}
68+
}
69+
}

samples/Txtx/svm-swap-clmm.tx

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
################################################################
2+
# Swap on Raydium CLMM (v3) - Concentrated Liquidity
3+
#
4+
# This runbook executes a swap on a Raydium CLMM pool.
5+
# CLMM uses concentrated liquidity similar to Uniswap v3.
6+
################################################################
7+
8+
addon "svm" {
9+
rpc_api_url = input.rpc_api_url
10+
network_id = input.network_id
11+
}
12+
13+
signer "user" "svm::secret_key" {
14+
description = "The account executing the swap"
15+
keypair_json = "~/.config/solana/id.json"
16+
}
17+
18+
variable "program" {
19+
description = "The raydium_arbitrage program"
20+
value = svm::get_program_from_anchor_project("raydium_arbitrage")
21+
}
22+
23+
# Token configuration
24+
variable "input_mint" {
25+
description = "Input token mint address"
26+
editable = true
27+
}
28+
29+
variable "output_mint" {
30+
description = "Output token mint address"
31+
editable = true
32+
}
33+
34+
# CLMM Pool configuration
35+
variable "pool_state" {
36+
description = "CLMM pool state account"
37+
editable = true
38+
}
39+
40+
variable "amm_config" {
41+
description = "CLMM AMM config account"
42+
editable = true
43+
}
44+
45+
variable "input_vault" {
46+
description = "CLMM input token vault"
47+
editable = true
48+
}
49+
50+
variable "output_vault" {
51+
description = "CLMM output token vault"
52+
editable = true
53+
}
54+
55+
variable "observation_state" {
56+
description = "CLMM oracle observation state"
57+
editable = true
58+
}
59+
60+
# Swap parameters
61+
variable "amount" {
62+
description = "Amount to swap (in smallest units)"
63+
value = 1000000000
64+
editable = true
65+
}
66+
67+
variable "other_amount_threshold" {
68+
description = "Minimum output or maximum input (depending on is_base_input)"
69+
value = 0
70+
editable = true
71+
}
72+
73+
variable "sqrt_price_limit_x64" {
74+
description = "Price limit for the swap (0 for no limit)"
75+
value = 0
76+
editable = true
77+
}
78+
79+
variable "is_base_input" {
80+
description = "True for exact input swap, false for exact output"
81+
value = true
82+
editable = true
83+
}
84+
85+
# Programs
86+
variable "token_program" {
87+
value = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
88+
}
89+
90+
variable "token_program_2022" {
91+
value = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"
92+
}
93+
94+
variable "memo_program" {
95+
value = "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"
96+
}
97+
98+
variable "clmm_program" {
99+
value = "CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK"
100+
}
101+
102+
action "swap_clmm" "svm::process_instructions" {
103+
description = "Execute CLMM swap"
104+
signers = [signer.user]
105+
106+
instruction {
107+
program_idl = variable.program.idl
108+
instruction_name = "swap_clmm"
109+
instruction_args = [
110+
variable.amount,
111+
variable.other_amount_threshold,
112+
variable.sqrt_price_limit_x64,
113+
variable.is_base_input
114+
]
115+
116+
payer {
117+
public_key = signer.user.public_key
118+
}
119+
amm_config {
120+
public_key = variable.amm_config
121+
}
122+
pool_state {
123+
public_key = variable.pool_state
124+
}
125+
input_token_account {
126+
public_key = svm::get_associated_token_address(signer.user.public_key, variable.input_mint)
127+
}
128+
output_token_account {
129+
public_key = svm::get_associated_token_address(signer.user.public_key, variable.output_mint)
130+
}
131+
input_vault {
132+
public_key = variable.input_vault
133+
}
134+
output_vault {
135+
public_key = variable.output_vault
136+
}
137+
observation_state {
138+
public_key = variable.observation_state
139+
}
140+
token_program {
141+
public_key = variable.token_program
142+
}
143+
token_program_2022 {
144+
public_key = variable.token_program_2022
145+
}
146+
memo_program {
147+
public_key = variable.memo_program
148+
}
149+
input_vault_mint {
150+
public_key = variable.input_mint
151+
}
152+
output_vault_mint {
153+
public_key = variable.output_mint
154+
}
155+
clmm_program {
156+
public_key = variable.clmm_program
157+
}
158+
}
159+
}
160+
161+
output "signature" {
162+
value = action.swap_clmm.signature
163+
}

vendor/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,7 @@ This is a list of grammars that Linguist selects to provide syntax highlighting
631631
- **Turing:** [Alhadis/language-turing](https://github.com/Alhadis/language-turing)
632632
- **Turtle:** [peta/turtle.tmbundle](https://github.com/peta/turtle.tmbundle)
633633
- **Twig:** [Anomareh/PHP-Twig.tmbundle](https://github.com/Anomareh/PHP-Twig.tmbundle)
634+
- **Txtx:** [txtx/txtx-grammar](https://github.com/txtx/txtx-grammar)
634635
- **Type Language:** [goodmind/language-typelanguage](https://github.com/goodmind/language-typelanguage)
635636
- **TypeScript:** [tree-sitter/tree-sitter-typescript](https://github.com/tree-sitter/tree-sitter-typescript) 🐌
636637
- **TypeSpec:** [microsoft/typespec](https://github.com/microsoft/typespec)

vendor/grammars/txtx-grammar

Submodule txtx-grammar added at 712048d

0 commit comments

Comments
 (0)