@layerzerolabs/protocol-stellar-v2 0.2.41 ā 0.2.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +146 -144
- package/.turbo/turbo-lint.log +165 -96
- package/.turbo/turbo-test.log +1810 -1755
- package/Cargo.lock +22 -127
- package/Cargo.toml +4 -6
- package/contracts/macro-integration-tests/tests/runtime/oapp/mod.rs +3 -5
- package/contracts/macro-integration-tests/tests/runtime/oapp/sender.rs +2 -1
- package/contracts/macro-integration-tests/tests/runtime/ownable/mod.rs +1 -1
- package/contracts/macro-integration-tests/tests/ui/oapp/fail/missing_auth_trait.rs +28 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/fail/missing_auth_trait.stderr +397 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/fail/missing_lz_receive_internal.rs +1 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/fail/missing_lz_receive_internal.stderr +10 -10
- package/contracts/macro-integration-tests/tests/ui/oapp/pass/custom_all.rs +1 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/pass/custom_single_trait.rs +4 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/pass/minimal_contract.rs +5 -4
- package/contracts/macro-integration-tests/tests/ui/oapp/pass/struct_with_fields.rs +2 -0
- package/contracts/oapps/counter/src/counter.rs +4 -3
- package/contracts/oapps/oapp/src/oapp_core.rs +1 -1
- package/contracts/oapps/oapp/src/tests/oapp_core.rs +2 -1
- package/contracts/oapps/oapp/src/tests/oapp_options_type3.rs +6 -3
- package/contracts/oapps/oapp/src/tests/oapp_receiver.rs +2 -1
- package/contracts/oapps/oapp/src/tests/oapp_sender.rs +2 -1
- package/contracts/oapps/oapp/src/tests/test_macros.rs +10 -0
- package/contracts/oapps/oapp-macros/src/generators.rs +6 -9
- package/contracts/oapps/oapp-macros/src/lib.rs +1 -1
- package/contracts/oapps/oapp-macros/src/tests/snapshots/oapp_macros__tests__oapp__snapshot_generate_oapp.snap +0 -7
- package/contracts/oapps/oft/src/oft.rs +2 -1
- package/contracts/oapps/oft/src/tests/oft_types/lock_unlock.rs +1 -0
- package/contracts/oapps/oft-core/integration-tests/setup.rs +1 -0
- package/contracts/oapps/oft-core/src/oft_core.rs +2 -2
- package/contracts/oapps/oft-core/src/tests/test_utils.rs +2 -0
- package/docs/oapp-guide.md +14 -9
- package/package.json +5 -4
- package/sdk/.turbo/turbo-test.log +294 -298
- package/sdk/dist/generated/counter.d.ts +137 -137
- package/sdk/dist/generated/counter.js +27 -27
- package/sdk/dist/generated/oft.d.ts +136 -136
- package/sdk/dist/generated/oft.js +27 -27
- package/sdk/package.json +1 -1
- package/ts-bindings-gen.toml +67 -0
- package/tools/ts-bindings-gen/Cargo.toml +0 -16
- package/tools/ts-bindings-gen/src/main.rs +0 -214
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Protocol contracts
|
|
2
|
+
[[contracts]]
|
|
3
|
+
wasm_name = "endpoint_v2"
|
|
4
|
+
output_name = "endpoint.ts"
|
|
5
|
+
|
|
6
|
+
[[contracts]]
|
|
7
|
+
wasm_name = "simple_message_lib"
|
|
8
|
+
output_name = "sml.ts"
|
|
9
|
+
|
|
10
|
+
[[contracts]]
|
|
11
|
+
wasm_name = "blocked_message_lib"
|
|
12
|
+
output_name = "bml.ts"
|
|
13
|
+
|
|
14
|
+
[[contracts]]
|
|
15
|
+
wasm_name = "uln302"
|
|
16
|
+
output_name = "uln302.ts"
|
|
17
|
+
|
|
18
|
+
[[contracts]]
|
|
19
|
+
wasm_name = "treasury"
|
|
20
|
+
output_name = "treasury.ts"
|
|
21
|
+
|
|
22
|
+
[[contracts]]
|
|
23
|
+
wasm_name = "upgrader"
|
|
24
|
+
output_name = "upgrader.ts"
|
|
25
|
+
|
|
26
|
+
# Worker contracts
|
|
27
|
+
[[contracts]]
|
|
28
|
+
wasm_name = "dvn"
|
|
29
|
+
output_name = "dvn.ts"
|
|
30
|
+
|
|
31
|
+
[[contracts]]
|
|
32
|
+
wasm_name = "dvn_fee_lib"
|
|
33
|
+
output_name = "dvn_fee_lib.ts"
|
|
34
|
+
|
|
35
|
+
[[contracts]]
|
|
36
|
+
wasm_name = "executor"
|
|
37
|
+
output_name = "executor.ts"
|
|
38
|
+
|
|
39
|
+
[[contracts]]
|
|
40
|
+
wasm_name = "executor_fee_lib"
|
|
41
|
+
output_name = "executor_fee_lib.ts"
|
|
42
|
+
|
|
43
|
+
[[contracts]]
|
|
44
|
+
wasm_name = "executor_helper"
|
|
45
|
+
output_name = "executor_helper.ts"
|
|
46
|
+
|
|
47
|
+
[[contracts]]
|
|
48
|
+
wasm_name = "price_feed"
|
|
49
|
+
output_name = "price_feed.ts"
|
|
50
|
+
|
|
51
|
+
# OApp contracts
|
|
52
|
+
[[contracts]]
|
|
53
|
+
wasm_name = "counter"
|
|
54
|
+
output_name = "counter.ts"
|
|
55
|
+
|
|
56
|
+
[[contracts]]
|
|
57
|
+
wasm_name = "oft"
|
|
58
|
+
output_name = "oft.ts"
|
|
59
|
+
|
|
60
|
+
[[contracts]]
|
|
61
|
+
wasm_name = "sac_manager"
|
|
62
|
+
output_name = "sac_manager.ts"
|
|
63
|
+
|
|
64
|
+
# View contracts
|
|
65
|
+
[[contracts]]
|
|
66
|
+
wasm_name = "layerzero_views"
|
|
67
|
+
output_name = "layerzero_view.ts"
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
[package]
|
|
2
|
-
name = "ts-bindings-gen"
|
|
3
|
-
version.workspace = true
|
|
4
|
-
edition.workspace = true
|
|
5
|
-
license.workspace = true
|
|
6
|
-
|
|
7
|
-
[[bin]]
|
|
8
|
-
name = "ts-bindings-gen"
|
|
9
|
-
path = "src/main.rs"
|
|
10
|
-
|
|
11
|
-
[dependencies]
|
|
12
|
-
soroban-spec-typescript = { workspace = true }
|
|
13
|
-
anyhow = { workspace = true }
|
|
14
|
-
sha2 = { workspace = true }
|
|
15
|
-
base64 = { workspace = true }
|
|
16
|
-
|
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
use anyhow::Result;
|
|
2
|
-
use base64::{engine::general_purpose::STANDARD as BASE64, Engine};
|
|
3
|
-
use sha2::{Digest, Sha256};
|
|
4
|
-
use soroban_spec_typescript::generate_from_file;
|
|
5
|
-
use std::{fs, path::Path};
|
|
6
|
-
|
|
7
|
-
/// Generate the imports header for TypeScript bindings
|
|
8
|
-
fn generate_imports_header() -> &'static str {
|
|
9
|
-
r#"import { Buffer } from "buffer";
|
|
10
|
-
import { Address } from '@stellar/stellar-sdk';
|
|
11
|
-
import {
|
|
12
|
-
AssembledTransaction,
|
|
13
|
-
Client as ContractClient,
|
|
14
|
-
ClientOptions as ContractClientOptions,
|
|
15
|
-
MethodOptions,
|
|
16
|
-
Result,
|
|
17
|
-
Spec as ContractSpec,
|
|
18
|
-
} from '@stellar/stellar-sdk/contract';
|
|
19
|
-
import type {
|
|
20
|
-
u32,
|
|
21
|
-
i32,
|
|
22
|
-
u64,
|
|
23
|
-
i64,
|
|
24
|
-
u128,
|
|
25
|
-
i128,
|
|
26
|
-
u256,
|
|
27
|
-
i256,
|
|
28
|
-
Option,
|
|
29
|
-
Typepoint,
|
|
30
|
-
Duration,
|
|
31
|
-
} from '@stellar/stellar-sdk/contract';
|
|
32
|
-
export * from '@stellar/stellar-sdk'
|
|
33
|
-
export * as contract from '@stellar/stellar-sdk/contract'
|
|
34
|
-
export * as rpc from '@stellar/stellar-sdk/rpc'
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"#
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/// Generate embedded WASM code section
|
|
42
|
-
fn generate_wasm_embed(wasm_bytes: &[u8]) -> String {
|
|
43
|
-
// Compute SHA-256 hash (this is what Stellar uses for wasmHash)
|
|
44
|
-
let wasm_hash = Sha256::digest(wasm_bytes);
|
|
45
|
-
let wasm_hash_hex = format!("{:x}", wasm_hash);
|
|
46
|
-
|
|
47
|
-
// Base64 encode the WASM bytes
|
|
48
|
-
let wasm_base64 = BASE64.encode(wasm_bytes);
|
|
49
|
-
|
|
50
|
-
format!(
|
|
51
|
-
r#"/**
|
|
52
|
-
* Embedded WASM bytecode (base64-encoded)
|
|
53
|
-
* Size: {} bytes ({:.2} KB)
|
|
54
|
-
*/
|
|
55
|
-
export const WASM_BASE64 = "{}";
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Pre-computed WASM hash (SHA-256)
|
|
59
|
-
* Use this when the WASM is already uploaded on-chain
|
|
60
|
-
*/
|
|
61
|
-
export const WASM_HASH = "{}";
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Get the WASM bytecode as a Buffer
|
|
65
|
-
* Use this to upload the WASM to the network
|
|
66
|
-
*/
|
|
67
|
-
export function getWasmBuffer(): Buffer {{
|
|
68
|
-
return Buffer.from(WASM_BASE64, 'base64');
|
|
69
|
-
}}
|
|
70
|
-
|
|
71
|
-
"#,
|
|
72
|
-
wasm_bytes.len(),
|
|
73
|
-
wasm_bytes.len() as f64 / 1024.0,
|
|
74
|
-
wasm_base64,
|
|
75
|
-
wasm_hash_hex
|
|
76
|
-
)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
fn main() -> Result<()> {
|
|
80
|
-
println!("š Generating TypeScript bindings for Stellar contracts...\n");
|
|
81
|
-
|
|
82
|
-
// Define the base paths
|
|
83
|
-
let wasm_base = Path::new("target/wasm32v1-none/release");
|
|
84
|
-
let sdk_output = Path::new("sdk/src/generated");
|
|
85
|
-
|
|
86
|
-
// Configuration for each contract
|
|
87
|
-
// Format: (wasm_filename, ts_filename)
|
|
88
|
-
let contracts = vec![
|
|
89
|
-
// Protocol contracts
|
|
90
|
-
("endpoint_v2", "endpoint.ts"),
|
|
91
|
-
("simple_message_lib", "sml.ts"),
|
|
92
|
-
("blocked_message_lib", "bml.ts"),
|
|
93
|
-
("uln302", "uln302.ts"),
|
|
94
|
-
("treasury", "treasury.ts"),
|
|
95
|
-
("upgrader", "upgrader.ts"),
|
|
96
|
-
// Worker contracts
|
|
97
|
-
("dvn", "dvn.ts"),
|
|
98
|
-
("dvn_fee_lib", "dvn_fee_lib.ts"),
|
|
99
|
-
("executor", "executor.ts"),
|
|
100
|
-
("executor_fee_lib", "executor_fee_lib.ts"),
|
|
101
|
-
("executor_helper", "executor_helper.ts"),
|
|
102
|
-
("price_feed", "price_feed.ts"),
|
|
103
|
-
// OApp contracts
|
|
104
|
-
("counter", "counter.ts"),
|
|
105
|
-
("oft", "oft.ts"),
|
|
106
|
-
("sac_manager", "sac_manager.ts"),
|
|
107
|
-
// View contracts
|
|
108
|
-
("layerzero_views", "layerzero_view.ts"),
|
|
109
|
-
// Add more contracts here as needed:
|
|
110
|
-
];
|
|
111
|
-
|
|
112
|
-
// Create output directory
|
|
113
|
-
fs::create_dir_all(sdk_output)?;
|
|
114
|
-
|
|
115
|
-
// Track generated contracts for index.ts
|
|
116
|
-
let mut generated_contracts = Vec::new();
|
|
117
|
-
|
|
118
|
-
for (wasm_name, ts_filename) in contracts {
|
|
119
|
-
let wasm_path = wasm_base.join(format!("{}.wasm", wasm_name));
|
|
120
|
-
let output_file = sdk_output.join(ts_filename);
|
|
121
|
-
|
|
122
|
-
println!("š¦ Processing contract: {}", wasm_name);
|
|
123
|
-
println!(" WASM: {}", wasm_path.display());
|
|
124
|
-
println!(" Output: {}", output_file.display());
|
|
125
|
-
|
|
126
|
-
// Check if WASM file exists
|
|
127
|
-
if !wasm_path.exists() {
|
|
128
|
-
eprintln!("ā ļø WASM file not found: {}", wasm_path.display());
|
|
129
|
-
eprintln!(" Skipping {}. Build the contract first with:", wasm_name);
|
|
130
|
-
eprintln!(" stellar contract build -p {}\n", wasm_name);
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// Read WASM bytes for embedding
|
|
135
|
-
let wasm_bytes = fs::read(&wasm_path)?;
|
|
136
|
-
println!(" WASM size: {} bytes ({:.2} KB)", wasm_bytes.len(), wasm_bytes.len() as f64 / 1024.0);
|
|
137
|
-
|
|
138
|
-
// Generate the embedded WASM section
|
|
139
|
-
let wasm_embed = generate_wasm_embed(&wasm_bytes);
|
|
140
|
-
|
|
141
|
-
// Generate TypeScript bindings
|
|
142
|
-
println!(" Generating bindings...");
|
|
143
|
-
let wasm_path_str =
|
|
144
|
-
wasm_path.to_str().ok_or_else(|| anyhow::anyhow!("Invalid path: {}", wasm_path.display()))?;
|
|
145
|
-
let ts_code = generate_from_file(wasm_path_str, None)?;
|
|
146
|
-
|
|
147
|
-
// Replace 'options?' parameter name with 'txnOptions?' to avoid naming conflicts
|
|
148
|
-
// This replaces the last parameter in function signatures from 'options?' to 'txnOptions?'
|
|
149
|
-
let ts_code = ts_code.replace(
|
|
150
|
-
r#"options?: {
|
|
151
|
-
/**
|
|
152
|
-
* The fee to pay for the transaction. Default: BASE_FEE
|
|
153
|
-
*/
|
|
154
|
-
fee?: number;
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* The maximum amount of time to wait for the transaction to complete. Default: DEFAULT_TIMEOUT
|
|
158
|
-
*/
|
|
159
|
-
timeoutInSeconds?: number;
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Whether to automatically simulate the transaction when constructing the AssembledTransaction. Default: true
|
|
163
|
-
*/
|
|
164
|
-
simulate?: boolean;
|
|
165
|
-
}"#,
|
|
166
|
-
r#"txnOptions?: {
|
|
167
|
-
/**
|
|
168
|
-
* The fee to pay for the transaction. Default: BASE_FEE
|
|
169
|
-
*/
|
|
170
|
-
fee?: number;
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* The maximum amount of time to wait for the transaction to complete. Default: DEFAULT_TIMEOUT
|
|
174
|
-
*/
|
|
175
|
-
timeoutInSeconds?: number;
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Whether to automatically simulate the transaction when constructing the AssembledTransaction. Default: true
|
|
179
|
-
*/
|
|
180
|
-
simulate?: boolean;
|
|
181
|
-
}"#,
|
|
182
|
-
);
|
|
183
|
-
|
|
184
|
-
// Also replace 'options?: MethodOptions' with 'txnOptions?: MethodOptions' for the same reason
|
|
185
|
-
// This handles functions that use the MethodOptions type alias instead of inline options
|
|
186
|
-
let ts_code = ts_code.replace(", options?: MethodOptions)", ", txnOptions?: MethodOptions)");
|
|
187
|
-
|
|
188
|
-
// Combine imports header + embedded WASM + generated code
|
|
189
|
-
let complete_code = format!("{}{}{}", generate_imports_header(), wasm_embed, ts_code);
|
|
190
|
-
|
|
191
|
-
// Write to contract-specific TypeScript file
|
|
192
|
-
fs::write(&output_file, &complete_code)?;
|
|
193
|
-
println!(" ā Generated: {}", output_file.display());
|
|
194
|
-
|
|
195
|
-
// Store info for index.ts generation
|
|
196
|
-
let module_name = ts_filename.trim_end_matches(".ts");
|
|
197
|
-
generated_contracts.push(module_name);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
println!("\nā
TypeScript binding generation complete!");
|
|
201
|
-
println!(" Generated {} contract(s) with embedded WASM", generated_contracts.len());
|
|
202
|
-
|
|
203
|
-
if generated_contracts.is_empty() {
|
|
204
|
-
println!("\nš” Tip: Build your contracts first before generating bindings:");
|
|
205
|
-
println!(" stellar contract build");
|
|
206
|
-
} else {
|
|
207
|
-
println!("\nš¦ Generated files in sdk/src/generated/:");
|
|
208
|
-
for module_name in &generated_contracts {
|
|
209
|
-
println!(" - {}.ts", module_name);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
Ok(())
|
|
214
|
-
}
|