@layerzerolabs/protocol-stellar-v2 0.2.20 → 0.2.21
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 +783 -802
- package/.turbo/turbo-lint.log +320 -157
- package/.turbo/turbo-test.log +1414 -1457
- package/Cargo.lock +109 -108
- package/Cargo.toml +32 -18
- package/contracts/common-macros/Cargo.toml +7 -7
- package/contracts/common-macros/src/auth.rs +18 -37
- package/contracts/common-macros/src/contract_ttl.rs +2 -2
- package/contracts/common-macros/src/lib.rs +27 -10
- package/contracts/common-macros/src/lz_contract.rs +38 -7
- package/contracts/common-macros/src/storage.rs +251 -292
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__auth__snapshot_generated_multisig_code.snap +6 -12
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__auth__snapshot_generated_ownable_code.snap +12 -17
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ttl_configurable__snapshot_generated_ttl_configurable_code.snap +2 -7
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__upgradeable__snapshot_generated_upgradeable_code.snap +20 -9
- package/contracts/common-macros/src/tests/upgradeable.rs +26 -4
- package/contracts/common-macros/src/ttl_configurable.rs +2 -10
- package/contracts/common-macros/src/ttl_extendable.rs +2 -10
- package/contracts/common-macros/src/upgradeable.rs +56 -15
- package/contracts/common-macros/src/utils.rs +0 -9
- package/contracts/endpoint-v2/src/lib.rs +3 -2
- package/contracts/endpoint-v2/src/tests/endpoint_v2/clear.rs +2 -2
- package/contracts/endpoint-v2/src/tests/endpoint_v2/lz_receive_alert.rs +3 -3
- package/contracts/endpoint-v2/src/tests/endpoint_v2/send.rs +4 -4
- package/contracts/endpoint-v2/src/tests/endpoint_v2/set_delegate.rs +17 -5
- package/contracts/endpoint-v2/src/tests/endpoint_v2/set_zro.rs +4 -4
- package/contracts/endpoint-v2/src/tests/endpoint_v2/verify.rs +2 -2
- package/contracts/endpoint-v2/src/tests/message_lib_manager/register_library.rs +2 -2
- package/contracts/endpoint-v2/src/tests/message_lib_manager/set_default_receive_lib_timeout.rs +6 -6
- package/contracts/endpoint-v2/src/tests/message_lib_manager/set_default_receive_library.rs +67 -37
- package/contracts/endpoint-v2/src/tests/message_lib_manager/set_default_send_library.rs +5 -5
- package/contracts/endpoint-v2/src/tests/message_lib_manager/set_receive_library.rs +44 -54
- package/contracts/endpoint-v2/src/tests/message_lib_manager/set_receive_library_timeout.rs +7 -7
- package/contracts/endpoint-v2/src/tests/message_lib_manager/set_send_library.rs +8 -8
- package/contracts/endpoint-v2/src/tests/messaging_channel/burn.rs +3 -3
- package/contracts/endpoint-v2/src/tests/messaging_channel/nilify.rs +4 -4
- package/contracts/endpoint-v2/src/tests/messaging_channel/skip.rs +3 -3
- package/contracts/endpoint-v2/src/tests/messaging_composer/clear_compose.rs +2 -2
- package/contracts/endpoint-v2/src/tests/messaging_composer/lz_compose_alert.rs +3 -3
- package/contracts/endpoint-v2/src/tests/messaging_composer/send_compose.rs +2 -2
- package/contracts/layerzero-views/Cargo.toml +0 -1
- package/contracts/layerzero-views/src/layerzero_view.rs +1 -13
- package/contracts/macro-integration-tests/Cargo.toml +5 -15
- package/contracts/macro-integration-tests/tests/runtime/oapp/mod.rs +48 -0
- package/contracts/macro-integration-tests/tests/runtime/oapp/oapp_core.rs +170 -0
- package/contracts/macro-integration-tests/tests/runtime/oapp/options_type3.rs +154 -0
- package/contracts/macro-integration-tests/tests/runtime/oapp/receiver.rs +338 -0
- package/contracts/macro-integration-tests/tests/runtime/oapp/sender.rs +435 -0
- package/contracts/macro-integration-tests/tests/runtime.rs +1 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/fail/custom_wrong_value.rs +8 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/fail/custom_wrong_value.stderr +5 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/fail/missing_lz_receive_internal.rs +8 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/fail/missing_lz_receive_internal.stderr +71 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/fail/non_struct_input.rs +10 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/fail/non_struct_input.stderr +5 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/fail/unknown_custom_option.rs +8 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/fail/unknown_custom_option.stderr +5 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/fail/wrong_key.rs +8 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/fail/wrong_key.stderr +5 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/pass/custom_all.rs +38 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/pass/custom_single_trait.rs +96 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/pass/minimal_contract.rs +64 -0
- package/contracts/macro-integration-tests/tests/ui/oapp/pass/struct_with_fields.rs +46 -0
- package/contracts/macro-integration-tests/tests/ui/ownable/fail/only_auth_missing_env.stderr +8 -0
- package/contracts/macro-integration-tests/tests/ui/ownable/pass/namespacing_and_imports.rs +1 -1
- package/contracts/macro-integration-tests/tests/ui/ownable/pass/only_auth_env_param_variants.rs +1 -1
- package/contracts/macro-integration-tests/tests/ui_oapp.rs +11 -0
- package/contracts/message-libs/message-lib-common/Cargo.toml +0 -1
- package/contracts/message-libs/message-lib-common/src/errors.rs +1 -1
- package/contracts/message-libs/treasury/Cargo.toml +0 -2
- package/contracts/message-libs/treasury/src/tests/treasury_tests.rs +2 -2
- package/contracts/message-libs/uln-302/src/tests/receive_uln302/effective_receive_uln_config.rs +2 -2
- package/contracts/message-libs/uln-302/src/tests/receive_uln302/set_default_receive_uln_configs.rs +2 -2
- package/contracts/message-libs/uln-302/src/tests/receive_uln302/verify.rs +2 -2
- package/contracts/message-libs/uln-302/src/tests/send_uln302/effective_executor_config.rs +2 -2
- package/contracts/message-libs/uln-302/src/tests/send_uln302/effective_send_uln_config.rs +2 -2
- package/contracts/message-libs/uln-302/src/tests/send_uln302/send.rs +7 -27
- package/contracts/message-libs/uln-302/src/tests/send_uln302/set_default_executor_configs.rs +2 -2
- package/contracts/message-libs/uln-302/src/tests/send_uln302/set_default_send_uln_configs.rs +2 -2
- package/contracts/oapps/counter/Cargo.toml +4 -6
- package/contracts/oapps/counter/integration_tests/utils.rs +19 -12
- package/contracts/oapps/oapp/src/errors.rs +1 -1
- package/contracts/oapps/oapp/src/interfaces/mod.rs +3 -0
- package/contracts/oapps/oapp/src/interfaces/oapp_msg_inspector.rs +47 -0
- package/contracts/oapps/oapp/src/lib.rs +1 -0
- package/contracts/oapps/oapp/src/macro_tests/test_macros.rs +4 -4
- package/contracts/oapps/oapp/src/oapp_core.rs +5 -5
- package/contracts/oapps/oapp/src/oapp_options_type3.rs +12 -4
- package/contracts/oapps/oapp/src/oapp_receiver.rs +14 -9
- package/contracts/oapps/oapp/src/tests/mod.rs +4 -4
- package/contracts/oapps/oapp/src/tests/{test_oapp_core.rs → oapp_core.rs} +4 -4
- package/contracts/oapps/oapp/src/tests/{test_oapp_options_type3.rs → oapp_options_type3.rs} +3 -4
- package/contracts/oapps/oapp-macros/Cargo.toml +8 -4
- package/contracts/oapps/oapp-macros/src/generators.rs +9 -34
- package/contracts/oapps/oapp-macros/src/lib.rs +3 -0
- package/contracts/oapps/oapp-macros/src/tests/mod.rs +2 -0
- package/contracts/oapps/oapp-macros/src/tests/oapp.rs +88 -0
- package/contracts/oapps/oapp-macros/src/tests/parse_custom_impls.rs +86 -0
- package/contracts/oapps/oapp-macros/src/tests/snapshots/oapp_macros__tests__oapp__snapshot_generate_oapp.snap +103 -0
- package/contracts/oapps/oft/integration-tests/utils.rs +28 -8
- package/contracts/oapps/oft/src/extensions/oft_fee.rs +136 -74
- package/contracts/oapps/oft/src/extensions/pausable.rs +44 -10
- package/contracts/oapps/oft/src/extensions/rate_limiter.rs +170 -130
- package/contracts/oapps/oft/src/oft.rs +19 -12
- package/contracts/oapps/oft/src/oft_types/lock_unlock.rs +1 -1
- package/contracts/oapps/oft/src/oft_types/mint_burn.rs +1 -1
- package/contracts/oapps/oft-core/Cargo.toml +1 -4
- package/contracts/oapps/oft-core/integration-tests/setup.rs +2 -2
- package/contracts/oapps/oft-core/integration-tests/utils.rs +21 -3
- package/contracts/oapps/oft-core/src/errors.rs +3 -2
- package/contracts/oapps/oft-core/src/events.rs +6 -0
- package/contracts/oapps/oft-core/src/lib.rs +1 -1
- package/contracts/oapps/oft-core/src/oft_core.rs +115 -60
- package/contracts/oapps/oft-core/src/storage.rs +7 -3
- package/contracts/oapps/oft-core/src/tests/mod.rs +1 -0
- package/contracts/oapps/oft-core/src/tests/test_decimals.rs +37 -2
- package/contracts/oapps/oft-core/src/tests/test_lz_receive.rs +2 -2
- package/contracts/oapps/oft-core/src/tests/test_msg_inspector.rs +323 -0
- package/contracts/oapps/oft-core/src/tests/test_send.rs +2 -2
- package/contracts/oapps/oft-core/src/tests/test_utils.rs +59 -14
- package/contracts/utils/Cargo.toml +0 -1
- package/contracts/utils/src/errors.rs +1 -1
- package/contracts/utils/src/multisig.rs +17 -8
- package/contracts/utils/src/ownable.rs +6 -6
- package/contracts/utils/src/testing_utils.rs +124 -54
- package/contracts/utils/src/tests/multisig.rs +12 -12
- package/contracts/utils/src/tests/ownable.rs +6 -6
- package/contracts/utils/src/tests/testing_utils.rs +50 -167
- package/contracts/utils/src/tests/ttl_configurable.rs +5 -5
- package/contracts/utils/src/tests/upgradeable.rs +1 -1
- package/contracts/utils/src/ttl_configurable.rs +10 -4
- package/contracts/utils/src/upgradeable.rs +5 -5
- package/contracts/workers/dvn/Cargo.toml +5 -6
- package/contracts/workers/dvn/src/dvn.rs +2 -12
- package/contracts/workers/dvn-fee-lib/Cargo.toml +1 -1
- package/contracts/workers/dvn-fee-lib/src/dvn_fee_lib.rs +37 -19
- package/contracts/workers/dvn-fee-lib/src/lib.rs +12 -2
- package/contracts/workers/dvn-fee-lib/src/tests/dvn_fee_lib.rs +15 -13
- package/contracts/workers/executor/Cargo.toml +3 -0
- package/contracts/workers/executor/src/executor.rs +2 -12
- package/contracts/workers/executor/src/lib.rs +2 -2
- package/contracts/workers/executor/src/tests/auth.rs +394 -0
- package/contracts/workers/executor/src/tests/executor.rs +410 -0
- package/contracts/workers/executor/src/tests/mod.rs +3 -0
- package/contracts/workers/executor/src/tests/setup.rs +250 -0
- package/contracts/workers/executor-fee-lib/Cargo.toml +5 -0
- package/contracts/workers/executor-fee-lib/src/executor_fee_lib.rs +1 -12
- package/contracts/workers/executor-fee-lib/src/lib.rs +8 -2
- package/contracts/workers/executor-helper/Cargo.toml +0 -1
- package/contracts/workers/price-feed/Cargo.toml +5 -0
- package/contracts/workers/price-feed/src/lib.rs +9 -4
- package/contracts/workers/price-feed/src/price_feed.rs +1 -11
- package/contracts/workers/worker/src/errors.rs +1 -1
- package/contracts/workers/worker/src/tests/setup.rs +1 -1
- package/contracts/workers/worker/src/tests/worker.rs +55 -41
- package/contracts/workers/worker/src/worker.rs +34 -25
- package/docs/error-spec.md +55 -0
- package/docs/layerzero-v2-on-stellar.md +447 -0
- package/docs/oapp-guide.md +212 -0
- package/docs/oft-guide.md +314 -0
- package/package.json +3 -3
- package/sdk/.turbo/turbo-test.log +260 -257
- package/sdk/dist/generated/bml.d.ts +3 -3
- package/sdk/dist/generated/bml.js +4 -4
- package/sdk/dist/generated/counter.d.ts +295 -295
- package/sdk/dist/generated/counter.js +43 -43
- package/sdk/dist/generated/dvn.d.ts +91 -91
- package/sdk/dist/generated/dvn.js +24 -24
- package/sdk/dist/generated/dvn_fee_lib.d.ts +92 -92
- package/sdk/dist/generated/dvn_fee_lib.js +25 -25
- package/sdk/dist/generated/endpoint.d.ts +99 -99
- package/sdk/dist/generated/endpoint.js +16 -16
- package/sdk/dist/generated/executor.d.ts +91 -91
- package/sdk/dist/generated/executor.js +24 -24
- package/sdk/dist/generated/executor_fee_lib.d.ts +92 -92
- package/sdk/dist/generated/executor_fee_lib.js +25 -25
- package/sdk/dist/generated/executor_helper.d.ts +3 -3
- package/sdk/dist/generated/executor_helper.js +4 -4
- package/sdk/dist/generated/layerzero_view.d.ts +186 -186
- package/sdk/dist/generated/layerzero_view.js +35 -35
- package/sdk/dist/generated/oft.d.ts +366 -352
- package/sdk/dist/generated/oft.js +74 -79
- package/sdk/dist/generated/price_feed.d.ts +198 -198
- package/sdk/dist/generated/price_feed.js +39 -39
- package/sdk/dist/generated/sml.d.ts +99 -99
- package/sdk/dist/generated/sml.js +16 -16
- package/sdk/dist/generated/treasury.d.ts +99 -99
- package/sdk/dist/generated/treasury.js +16 -16
- package/sdk/dist/generated/uln302.d.ts +99 -99
- package/sdk/dist/generated/uln302.js +16 -16
- package/sdk/dist/generated/upgrader.d.ts +3 -3
- package/sdk/dist/generated/upgrader.js +3 -3
- package/sdk/package.json +1 -1
- package/sdk/test/suites/localnet.ts +84 -20
- package/contracts/ERROR_SPEC.md +0 -51
- package/contracts/endpoint-v2/ARCHITECTURE.md +0 -233
- /package/contracts/oapps/oapp/src/tests/{test_oapp_receiver.rs → oapp_receiver.rs} +0 -0
- /package/contracts/oapps/oapp/src/tests/{test_oapp_sender.rs → oapp_sender.rs} +0 -0
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
import { $, sleep } from 'zx';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
DEFAULT_DEPLOYER,
|
|
6
|
+
EXECUTOR_ADMIN,
|
|
7
|
+
FRIENDBOT_URL,
|
|
8
|
+
RPC_URL,
|
|
9
|
+
ZRO_DISTRIBUTOR,
|
|
10
|
+
} from './constants';
|
|
5
11
|
import { deployNativeSac, deployZroToken } from './deploy';
|
|
6
12
|
|
|
7
13
|
const CONTAINER_NAME = 'stellar-localnet';
|
|
8
|
-
const QUICKSTART_IMAGE = 'stellar/quickstart';
|
|
14
|
+
const QUICKSTART_IMAGE = 'stellar/quickstart:testing';
|
|
15
|
+
|
|
16
|
+
// Timeout configuration (in milliseconds)
|
|
17
|
+
const STARTUP_TIMEOUT_MS = 300_000; // 5 minutes total timeout for localnet startup
|
|
18
|
+
const REQUEST_TIMEOUT_MS = 10_000; // 10 seconds per request
|
|
19
|
+
const RETRY_INTERVAL_MS = 2_000; // 2 seconds between retries
|
|
9
20
|
|
|
10
21
|
export async function startStellarLocalnet(): Promise<void> {
|
|
11
22
|
console.log('🚀 Starting Stellar localnet...');
|
|
@@ -23,34 +34,87 @@ export async function startStellarLocalnet(): Promise<void> {
|
|
|
23
34
|
// Start the stellar/quickstart container directly (no Stellar CLI needed)
|
|
24
35
|
await $`docker run -d --name ${CONTAINER_NAME} -p 8086:8000 ${QUICKSTART_IMAGE} --local`;
|
|
25
36
|
|
|
26
|
-
|
|
27
|
-
|
|
37
|
+
const startTime = Date.now();
|
|
38
|
+
|
|
39
|
+
// Wait for RPC to be healthy first (friendbot depends on it)
|
|
40
|
+
console.log('⏳ Waiting for Stellar RPC to be healthy...');
|
|
41
|
+
await waitForRpcHealth(startTime);
|
|
42
|
+
console.log('✅ Stellar RPC is healthy');
|
|
43
|
+
|
|
44
|
+
// Wait for friendbot to be ready and fund accounts
|
|
45
|
+
console.log('⏳ Waiting for friendbot to be ready...');
|
|
46
|
+
await waitForFriendbotAndFundAccounts(startTime);
|
|
47
|
+
|
|
48
|
+
await deployNativeSac();
|
|
49
|
+
await deployZroToken();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function waitForRpcHealth(startTime: number): Promise<void> {
|
|
53
|
+
while (Date.now() - startTime < STARTUP_TIMEOUT_MS) {
|
|
28
54
|
try {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
55
|
+
const response = await axios.post(
|
|
56
|
+
RPC_URL,
|
|
57
|
+
{ jsonrpc: '2.0', id: 1, method: 'getHealth' },
|
|
58
|
+
{
|
|
59
|
+
timeout: REQUEST_TIMEOUT_MS,
|
|
60
|
+
headers: { 'Content-Type': 'application/json' },
|
|
61
|
+
},
|
|
62
|
+
);
|
|
63
|
+
if (response.data?.result?.status === 'healthy') {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
} catch {
|
|
67
|
+
// RPC not ready yet
|
|
42
68
|
}
|
|
69
|
+
await sleep(RETRY_INTERVAL_MS);
|
|
43
70
|
}
|
|
44
|
-
|
|
45
|
-
|
|
71
|
+
throw new Error(
|
|
72
|
+
`Stellar RPC failed to become healthy within ${STARTUP_TIMEOUT_MS / 1000} seconds`,
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async function waitForFriendbotAndFundAccounts(startTime: number): Promise<void> {
|
|
77
|
+
const accountsToFund = [
|
|
78
|
+
{ keypair: DEFAULT_DEPLOYER, name: 'DEFAULT_DEPLOYER' },
|
|
79
|
+
{ keypair: ZRO_DISTRIBUTOR, name: 'ZRO_DISTRIBUTOR' },
|
|
80
|
+
{ keypair: EXECUTOR_ADMIN, name: 'EXECUTOR_ADMIN' },
|
|
81
|
+
];
|
|
82
|
+
|
|
83
|
+
for (const { keypair, name } of accountsToFund) {
|
|
84
|
+
let funded = false;
|
|
85
|
+
while (Date.now() - startTime < STARTUP_TIMEOUT_MS) {
|
|
86
|
+
try {
|
|
87
|
+
await fundAccount(keypair.publicKey());
|
|
88
|
+
console.log(`✅ Account ${name} (${keypair.publicKey()}) funded`);
|
|
89
|
+
funded = true;
|
|
90
|
+
break;
|
|
91
|
+
} catch (_error) {
|
|
92
|
+
const elapsed = Math.round((Date.now() - startTime) / 1000);
|
|
93
|
+
console.log(`⏳ [${elapsed}s] Waiting for friendbot to fund ${name}...`);
|
|
94
|
+
await sleep(RETRY_INTERVAL_MS);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (!funded) {
|
|
98
|
+
throw new Error(
|
|
99
|
+
`Failed to fund account ${name} within ${STARTUP_TIMEOUT_MS / 1000} seconds`,
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
console.log('✅ Stellar localnet started');
|
|
46
104
|
}
|
|
47
105
|
|
|
48
106
|
export async function fundAccount(publicKey: string): Promise<void> {
|
|
49
|
-
await axios.get(FRIENDBOT_URL, {
|
|
107
|
+
const response = await axios.get(FRIENDBOT_URL, {
|
|
50
108
|
params: {
|
|
51
109
|
addr: publicKey,
|
|
52
110
|
},
|
|
111
|
+
timeout: REQUEST_TIMEOUT_MS,
|
|
53
112
|
});
|
|
113
|
+
|
|
114
|
+
// Check for error responses (friendbot returns 400 if already funded, which is OK)
|
|
115
|
+
if (response.status >= 500) {
|
|
116
|
+
throw new Error(`Friendbot returned error: ${response.status}`);
|
|
117
|
+
}
|
|
54
118
|
}
|
|
55
119
|
|
|
56
120
|
export async function stopStellarLocalnet(): Promise<void> {
|
package/contracts/ERROR_SPEC.md
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
# Stellar LayerZero Protocol - Error Code Specification
|
|
2
|
-
|
|
3
|
-
This document defines the error code allocation strategy for the Stellar LayerZero contracts.
|
|
4
|
-
|
|
5
|
-
## Purpose
|
|
6
|
-
|
|
7
|
-
Each library has a unique error code range to:
|
|
8
|
-
|
|
9
|
-
- **Prevent collisions**: Avoid error code conflicts between different libraries
|
|
10
|
-
- **Enable traceability**: Quickly identify which library an error originated from based on its code
|
|
11
|
-
- **Simplify debugging**: Error codes are globally unique, making it easier to track and diagnose issues
|
|
12
|
-
|
|
13
|
-
## Allocation Rules
|
|
14
|
-
|
|
15
|
-
- **Library allocation**: Each library is allocated a 100-unit block (e.g., 1000-1099, 1100-1199). Total errors in one library should not exceed 100.
|
|
16
|
-
- **Sub-range allocation**: Each error type within a library is allocated a 10-unit block. Example from `utils` (1000-1099):
|
|
17
|
-
|
|
18
|
-
- BufferReaderError: 1000-1009
|
|
19
|
-
- BufferWriterError: 1010-1019
|
|
20
|
-
- TtlConfigurableError: 1020-1029
|
|
21
|
-
- OwnableError: 1030-1039
|
|
22
|
-
- BytesExtError: 1040-1049
|
|
23
|
-
- UpgradeableError: 1050-1059
|
|
24
|
-
- MultisigError: 1060-1069
|
|
25
|
-
|
|
26
|
-
Example from `oft/extensions` (3100-3199):
|
|
27
|
-
|
|
28
|
-
- OFTFeeError: 3100-3109
|
|
29
|
-
- OFTPausableError: 3110-3119
|
|
30
|
-
- RateLimitError: 3120-3129
|
|
31
|
-
|
|
32
|
-
If an error type exceeds 10 errors (e.g., 12 errors), it extends into the next block but the following error type should start at the next 10-unit boundary (e.g., if errors are 1000-1011, next sub-range starts at 1020).
|
|
33
|
-
|
|
34
|
-
- **Auto-increment**: Within each error enum, values auto-increment from the starting value.
|
|
35
|
-
|
|
36
|
-
## Error Code Ranges
|
|
37
|
-
|
|
38
|
-
| Range | Category | Library | Description |
|
|
39
|
-
| ----------- | --------------- | ------------------ | ------------------------------------------------------------ |
|
|
40
|
-
| 1 - 999 | Contract Errors | - | Application-specific contract errors (auto-increment from 1) |
|
|
41
|
-
| 1000 - 1099 | Protocol Lib | utils | `utils/src/errors.rs` |
|
|
42
|
-
| 1100 - 1199 | Protocol Lib | message-lib-common | `message-libs/message-lib-common/src/errors.rs` |
|
|
43
|
-
| 1200 - 1299 | Protocol Lib | worker | `workers/worker/src/errors.rs` |
|
|
44
|
-
| 1300 - 1999 | Protocol Lib | (reserved) | Future protocol libs |
|
|
45
|
-
| 2000 - 2099 | OApp Lib | oapp | `oapps/oapp/src/errors.rs` |
|
|
46
|
-
| 2100 - 2999 | OApp Lib | (reserved) | Future OApp libs |
|
|
47
|
-
| 3000 - 3099 | OFT Lib | oft-core | `oapps/oft-core/src/errors.rs` |
|
|
48
|
-
| 3100 - 3199 | OFT Lib | oft (extensions) | `oapps/oft/src/extensions/` |
|
|
49
|
-
| 3200 - 3999 | OFT Lib | (reserved) | Future OFT libs |
|
|
50
|
-
|
|
51
|
-
---
|
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
# EndpointV2 Architecture
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
**EndpointV2** is the core Soroban contract for LayerZero's cross-chain messaging protocol on Stellar. It serves as the central hub for omnichain applications (OApps) to send and receive cross-chain messages using pluggable message libraries.
|
|
6
|
-
|
|
7
|
-
**Key Architecture Principles:**
|
|
8
|
-
|
|
9
|
-
- **Interfaces exported as library** - External contracts depend on trait definitions only
|
|
10
|
-
- **Contract entry point** - `endpoint_v2.rs` implements all interfaces
|
|
11
|
-
- **Internal modules** - Separate files for business logic implementation
|
|
12
|
-
- **Centralized resources** - Unified `storage.rs`, `errors.rs`, `events.rs`
|
|
13
|
-
|
|
14
|
-
---
|
|
15
|
-
|
|
16
|
-
## Project Structure
|
|
17
|
-
|
|
18
|
-
```
|
|
19
|
-
endpoint-v2/
|
|
20
|
-
├── Cargo.toml # Package configuration with "library" feature
|
|
21
|
-
├── ARCHITECTURE.md # This file - architecture documentation
|
|
22
|
-
│
|
|
23
|
-
├── src/
|
|
24
|
-
|
|
25
|
-
│ ├── interfaces/ # Public interface definitions (library exports)
|
|
26
|
-
│ │ ├── mod.rs
|
|
27
|
-
│ │ ├── layerzero_endpoint_v2.rs # Core endpoint interface
|
|
28
|
-
│ │ ├── layerzero_composer.rs # Interface for Composer
|
|
29
|
-
│ │ ├── layerzero_receiver.rs # Interface for OApp (receive)
|
|
30
|
-
│ │ ├── message_lib.rs # Interface for MessageLib
|
|
31
|
-
│ │ ├── message_lib_manager.rs # Library management interface of EndpointV2
|
|
32
|
-
│ │ ├── send_lib.rs # Interface for SendLib (extends MessageLib)
|
|
33
|
-
│ │ ├── messaging_channel.rs # Channel operations interface of EndpointV2
|
|
34
|
-
│ │ └── messaging_composer.rs # Compose operations interface of EndpointV2
|
|
35
|
-
| |
|
|
36
|
-
│ ├── lib.rs # Module exports & conditional compilation
|
|
37
|
-
│ ├── endpoint_v2.rs # Main contract implementation
|
|
38
|
-
│ ├── message_lib_manager.rs # Internal: Library registration & management
|
|
39
|
-
│ ├── messaging_channel.rs # Internal: Channel logic (nonce, payload)
|
|
40
|
-
│ ├── messaging_composer.rs # Internal: Compose queue management
|
|
41
|
-
│ │
|
|
42
|
-
│ ├── util.rs # Public: Utility functions (GUID, payload, keccak256)
|
|
43
|
-
│ ├── storage.rs # Centralized storage management
|
|
44
|
-
│ ├── errors.rs # Centralized error definitions
|
|
45
|
-
│ ├── events.rs # Centralized event definitions
|
|
46
|
-
│ │
|
|
47
|
-
│ └── tests/ # Comprehensive test suite
|
|
48
|
-
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
---
|
|
52
|
-
|
|
53
|
-
## Design Principles
|
|
54
|
-
|
|
55
|
-
### 1. Interfaces as Library Exports
|
|
56
|
-
|
|
57
|
-
The `interfaces/` directory contains Soroban trait definitions exported as a library for external contracts. Controlled by the `library` feature in `Cargo.toml`.
|
|
58
|
-
|
|
59
|
-
```rust
|
|
60
|
-
// lib.rs - conditional compilation
|
|
61
|
-
cfg_if::cfg_if! {
|
|
62
|
-
if #[cfg(any(not(feature = "library"), feature = "default"))] {
|
|
63
|
-
mod endpoint_v2; // Only included when building contract
|
|
64
|
-
mod errors;
|
|
65
|
-
mod events;
|
|
66
|
-
mod storage;
|
|
67
|
-
|
|
68
|
-
pub use endpoint_v2::{EndpointV2, EndpointV2Client};
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
**Usage Example:**
|
|
74
|
-
|
|
75
|
-
```rust
|
|
76
|
-
// In a MessageLib contract
|
|
77
|
-
use endpoint_v2::{EndpointV2Client, OutboundPacket};
|
|
78
|
-
|
|
79
|
-
let endpoint = EndpointV2Client::new(&env, &endpoint_address);
|
|
80
|
-
endpoint.verify(&origin, &receiver, &payload_hash);
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
**Interface Categories:**
|
|
84
|
-
|
|
85
|
-
- **For OApps**: `ILayerZeroReceiver`, `ILayerZeroComposer`
|
|
86
|
-
- **For MessageLibs**: `IMessageLib`, `ISendLib` (includes `OutboundPacket`, `FeeRecipient`)
|
|
87
|
-
- **For All**: `ILayerZeroEndpointV2` (composes all sub-interfaces)
|
|
88
|
-
- **Utilities**: `util::compute_guid()`, `util::build_payload()`, `util::keccak256()`
|
|
89
|
-
|
|
90
|
-
### 2. Contract Entry Point (`endpoint_v2.rs`)
|
|
91
|
-
|
|
92
|
-
The main Soroban contract that implements all interfaces and delegates to internal modules:
|
|
93
|
-
|
|
94
|
-
```rust
|
|
95
|
-
#[contract]
|
|
96
|
-
pub struct EndpointV2;
|
|
97
|
-
|
|
98
|
-
#[contract_impl]
|
|
99
|
-
impl EndpointV2 {
|
|
100
|
-
pub fn __constructor(env: &Env, eid: u32, native_token: &Address, owner: &Address) {
|
|
101
|
-
storage::EndpointData::set_eid(env, eid);
|
|
102
|
-
storage::EndpointData::set_native_token(env, native_token);
|
|
103
|
-
ownable::set_owner(env, owner);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
pub fn set_ttl_configs(env: &Env, ...) {
|
|
107
|
-
ownable::require_owner_auth(env);
|
|
108
|
-
// Configure TTL settings for storage
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
#[contract_impl]
|
|
113
|
-
impl ILayerZeroEndpointV2 for EndpointV2 {
|
|
114
|
-
fn send(env: &Env, sender: &Address, params: &MessagingParams, ...) -> MessagingReceipt {
|
|
115
|
-
sender.require_auth();
|
|
116
|
-
// Send cross-chain message via SendLib
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
fn lz_receive(env: &Env, origin: &Origin, receiver: &Address, ...) {
|
|
120
|
-
// Verify payload hash and deliver to OApp
|
|
121
|
-
let receiver_client = LayerZeroReceiverClient::new(env, receiver);
|
|
122
|
-
receiver_client.lz_receive(...);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
#[contract_impl]
|
|
127
|
-
impl Ownable for EndpointV2 {
|
|
128
|
-
// Ownership management
|
|
129
|
-
}
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
**Implements:** `ILayerZeroEndpointV2` (which includes `IMessageLibManager`, `IMessagingChannel`, `IMessagingComposer`), `Ownable`
|
|
133
|
-
|
|
134
|
-
### 3. Internal Implementation Modules
|
|
135
|
-
|
|
136
|
-
Internal modules provide business logic implementation for `endpoint_v2.rs`:
|
|
137
|
-
|
|
138
|
-
| Module | Purpose |
|
|
139
|
-
| ---------------------------- | -------------------------------------------------------------------------------------------------------- |
|
|
140
|
-
| **`message_lib_manager.rs`** | Library registration, selection, and configuration. Tracks default/per-OApp libraries per EID. |
|
|
141
|
-
| **`messaging_channel.rs`** | Nonce tracking, payload hash storage/verification, message state transitions (verify → receive → clear). |
|
|
142
|
-
| **`messaging_composer.rs`** | Manages compose message queues for multi-stage execution between OApp and Composers. |
|
|
143
|
-
| **`util.rs`** | Public utilities: `compute_guid()`, `build_payload()`, `keccak256()` for message processing. |
|
|
144
|
-
|
|
145
|
-
### 4. Centralized Resource Management
|
|
146
|
-
|
|
147
|
-
| Module | Purpose | Example |
|
|
148
|
-
| ---------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
|
|
149
|
-
| **`storage.rs`** | Type-safe storage with `#[storage]` derive macro. Organized into: `EndpointData`, `MessagingChannelData`, `MessageLibManagerData`, `MessagingComposerData`. | `EndpointData::eid(env)`, `MessagingChannelData::outbound_nonce(env, sender, dst_eid, receiver)` |
|
|
150
|
-
| **`errors.rs`** | All error codes using `#[contracterror]`. 29 error types including validation, authorization, state, and configuration errors. | `InvalidNonce = 3`, `Unauthorized = 10`, `InsufficientNativeFee = 27` |
|
|
151
|
-
| **`events.rs`** | All events using `#[contractevent]`. Includes config, messaging, library, and compose events. | `PacketSent`, `PacketVerified`, `LibraryRegistered` |
|
|
152
|
-
|
|
153
|
-
---
|
|
154
|
-
|
|
155
|
-
## Key Patterns
|
|
156
|
-
|
|
157
|
-
**1. Interface Composition**
|
|
158
|
-
|
|
159
|
-
```rust
|
|
160
|
-
pub trait ILayerZeroEndpointV2:
|
|
161
|
-
IMessageLibManager + IMessagingChannel + IMessagingComposer
|
|
162
|
-
{
|
|
163
|
-
fn quote(env: &Env, sender: &Address, params: &MessagingParams) -> MessagingFee;
|
|
164
|
-
fn send(env: &Env, sender: &Address, params: &MessagingParams, refund_address: &Address) -> MessagingReceipt;
|
|
165
|
-
fn lz_receive(env: &Env, origin: &Origin, receiver: &Address, guid: &BytesN<32>, message: &Bytes, extra_data: &Bytes);
|
|
166
|
-
// ... more methods
|
|
167
|
-
}
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
Each sub-interface handles one domain, enabling modularity and clear separation of concerns. Ownership is handled through the `Ownable` trait from the `utils` crate.
|
|
171
|
-
|
|
172
|
-
**2. Client Generation**
|
|
173
|
-
|
|
174
|
-
```rust
|
|
175
|
-
#[contractclient(name = "LayerZeroReceiverClient")]
|
|
176
|
-
pub trait ILayerZeroReceiver {
|
|
177
|
-
fn lz_receive(env: &Env, origin: &Origin, guid: &BytesN<32>, message: &Bytes, extra_data: &Bytes);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// Usage: type-safe cross-contract calls
|
|
181
|
-
let receiver = LayerZeroReceiverClient::new(&env, &receiver_address);
|
|
182
|
-
receiver.lz_receive(&origin, &guid, &message, &extra_data);
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
The `#[contractclient]` macro automatically generates type-safe client wrappers for cross-contract calls.
|
|
186
|
-
|
|
187
|
-
---
|
|
188
|
-
|
|
189
|
-
## Message Flows
|
|
190
|
-
|
|
191
|
-
### Sending
|
|
192
|
-
|
|
193
|
-
```
|
|
194
|
-
OApp → EndpointV2.send(sender, params, refund_address)
|
|
195
|
-
↓
|
|
196
|
-
MessageLibManager.get_send_library(sender, dst_eid)
|
|
197
|
-
↓
|
|
198
|
-
MessagingChannel.outbound_nonce++ (create OutboundPacket)
|
|
199
|
-
↓
|
|
200
|
-
SendLib.send(packet, options, pay_in_zro) → Returns (Vec<FeeRecipient>, encoded_packet)
|
|
201
|
-
↓
|
|
202
|
-
Pay fees (native or ZRO) to fee recipients
|
|
203
|
-
↓
|
|
204
|
-
Emit PacketSent event
|
|
205
|
-
↓
|
|
206
|
-
Return MessagingReceipt { guid, nonce, fee }
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
### Receiving
|
|
210
|
-
|
|
211
|
-
```
|
|
212
|
-
Off-chain Verifier → EndpointV2.verify(origin, receiver, payload_hash)
|
|
213
|
-
↓
|
|
214
|
-
Validate library is registered receive lib
|
|
215
|
-
↓
|
|
216
|
-
MessagingChannel.inbound(receiver, origin, payload_hash) → Store payload hash
|
|
217
|
-
↓
|
|
218
|
-
Emit PacketVerified event
|
|
219
|
-
|
|
220
|
-
Later: Executor → OApp.lz_receive(origin, guid, message, extra_data)
|
|
221
|
-
↓
|
|
222
|
-
OApp executes business logic
|
|
223
|
-
↓
|
|
224
|
-
OApp → EndpointV2.clear(caller, origin, receiver, guid, message)
|
|
225
|
-
↓
|
|
226
|
-
Validate caller is OApp or its delegate (require_oapp_auth)
|
|
227
|
-
↓
|
|
228
|
-
Validate payload hash matches keccak256(guid || message)
|
|
229
|
-
↓
|
|
230
|
-
Clear payload hash from storage
|
|
231
|
-
↓
|
|
232
|
-
Emit PacketDelivered event
|
|
233
|
-
```
|
|
File without changes
|
|
File without changes
|