@layerzerolabs/protocol-stellar-v2 0.2.64 → 0.2.66
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 +230 -307
- package/.turbo/turbo-lint.log +175 -175
- package/.turbo/turbo-test.log +2047 -1975
- package/Cargo.lock +0 -16
- package/Cargo.toml +0 -1
- package/contracts/oapps/oft/integration-tests/extensions/test_oft_fee.rs +22 -0
- package/contracts/oapps/oft/integration-tests/extensions/test_pausable.rs +9 -2
- package/contracts/oapps/oft/integration-tests/extensions/test_rate_limiter.rs +27 -2
- package/contracts/oapps/oft/integration-tests/setup.rs +22 -18
- package/contracts/oapps/oft/integration-tests/utils.rs +81 -34
- package/contracts/oapps/oft/src/extensions/oft_fee.rs +13 -0
- package/contracts/oapps/oft/src/oft.rs +10 -2
- package/package.json +5 -5
- package/sdk/.turbo/turbo-test.log +284 -291
- package/sdk/dist/generated/oft.d.ts +3 -3
- package/sdk/dist/generated/oft.js +3 -3
- package/sdk/node_modules/.bin/vitest +2 -2
- package/sdk/package.json +2 -2
- package/contracts/oapps/console-oft/Cargo.toml +0 -30
- package/contracts/oapps/console-oft/integration-tests/extensions/mod.rs +0 -5
- package/contracts/oapps/console-oft/integration-tests/extensions/test_combined.rs +0 -90
- package/contracts/oapps/console-oft/integration-tests/extensions/test_oft_fee.rs +0 -186
- package/contracts/oapps/console-oft/integration-tests/extensions/test_ownership.rs +0 -161
- package/contracts/oapps/console-oft/integration-tests/extensions/test_pausable.rs +0 -154
- package/contracts/oapps/console-oft/integration-tests/extensions/test_rate_limiter.rs +0 -479
- package/contracts/oapps/console-oft/integration-tests/mod.rs +0 -3
- package/contracts/oapps/console-oft/integration-tests/setup.rs +0 -303
- package/contracts/oapps/console-oft/integration-tests/utils.rs +0 -685
- package/contracts/oapps/console-oft/src/errors.rs +0 -7
- package/contracts/oapps/console-oft/src/extensions/mod.rs +0 -3
- package/contracts/oapps/console-oft/src/extensions/oft_fee.rs +0 -239
- package/contracts/oapps/console-oft/src/extensions/pausable.rs +0 -185
- package/contracts/oapps/console-oft/src/extensions/rate_limiter.rs +0 -478
- package/contracts/oapps/console-oft/src/interfaces/mintable.rs +0 -14
- package/contracts/oapps/console-oft/src/interfaces/mod.rs +0 -3
- package/contracts/oapps/console-oft/src/lib.rs +0 -26
- package/contracts/oapps/console-oft/src/oft.rs +0 -208
- package/contracts/oapps/console-oft/src/oft_access_control.rs +0 -93
- package/contracts/oapps/console-oft/src/oft_types/lock_unlock.rs +0 -50
- package/contracts/oapps/console-oft/src/oft_types/mint_burn.rs +0 -50
- package/contracts/oapps/console-oft/src/oft_types/mod.rs +0 -24
- package/contracts/oapps/console-oft/src/tests/extensions/mod.rs +0 -3
- package/contracts/oapps/console-oft/src/tests/extensions/oft_fee.rs +0 -255
- package/contracts/oapps/console-oft/src/tests/extensions/pausable.rs +0 -212
- package/contracts/oapps/console-oft/src/tests/extensions/rate_limiter.rs +0 -992
- package/contracts/oapps/console-oft/src/tests/mod.rs +0 -2
- package/contracts/oapps/console-oft/src/tests/oft_types/lock_unlock.rs +0 -185
- package/contracts/oapps/console-oft/src/tests/oft_types/mod.rs +0 -1
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
//! Integration test setup for OFT-STD with real EndpointV2 and SimpleMessageLib.
|
|
2
|
-
//!
|
|
3
|
-
//! This file contains test setup utilities for OFT-STD with all extensions enabled.
|
|
4
|
-
|
|
5
|
-
extern crate std;
|
|
6
|
-
|
|
7
|
-
use crate::{
|
|
8
|
-
integration_tests::utils::{address_to_peer_bytes32, peer_bytes32_to_address},
|
|
9
|
-
oft::{OFTClient, OFT},
|
|
10
|
-
oft_types::OftType,
|
|
11
|
-
};
|
|
12
|
-
use endpoint_v2::{EndpointV2, EndpointV2Client};
|
|
13
|
-
|
|
14
|
-
use simple_message_lib::{SimpleMessageLib, SimpleMessageLibClient};
|
|
15
|
-
use soroban_sdk::{
|
|
16
|
-
contract, contractimpl, contracttype, log,
|
|
17
|
-
testutils::{Address as _, MockAuth, MockAuthInvoke},
|
|
18
|
-
token::{StellarAssetClient, TokenClient},
|
|
19
|
-
Address, BytesN, Env, IntoVal,
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
// ============================================================================
|
|
23
|
-
// Mock SAC Wrapper - implements Mintable for integration tests
|
|
24
|
-
// ============================================================================
|
|
25
|
-
// Wraps a Stellar Asset Contract (SAC). The wrapper is set as SAC admin and
|
|
26
|
-
// implements mint(env, to, amount, operation) so the OFT uses it for credit (mint).
|
|
27
|
-
// OFT burns on the token directly; this mock still has burn for completeness.
|
|
28
|
-
|
|
29
|
-
#[contracttype]
|
|
30
|
-
pub enum MockSacWrapperKey {
|
|
31
|
-
Sac,
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
#[contract]
|
|
35
|
-
pub struct MockSacWrapper;
|
|
36
|
-
|
|
37
|
-
#[contractimpl]
|
|
38
|
-
impl MockSacWrapper {
|
|
39
|
-
pub fn __constructor(env: &Env, sac: Address) {
|
|
40
|
-
env.storage().instance().set(&MockSacWrapperKey::Sac, &sac);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/// Mintable::mint - mints on the underlying SAC (wrapper must be SAC admin).
|
|
44
|
-
pub fn mint(env: &Env, to: &Address, amount: i128, _operation: &Address) {
|
|
45
|
-
let sac: Address = env.storage().instance().get(&MockSacWrapperKey::Sac).unwrap();
|
|
46
|
-
StellarAssetClient::new(env, &sac).mint(to, &amount);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// ============================================================================
|
|
51
|
-
// Dummy Recipient - used to create valid contract addresses for recipients
|
|
52
|
-
// ============================================================================
|
|
53
|
-
|
|
54
|
-
#[contract]
|
|
55
|
-
pub struct DummyRecipient;
|
|
56
|
-
|
|
57
|
-
#[contractimpl]
|
|
58
|
-
impl DummyRecipient {
|
|
59
|
-
pub fn __constructor(_env: &Env) {}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/// Creates a valid recipient address by deploying a dummy contract.
|
|
63
|
-
/// Use this in tests when the address needs to pass the `.exists()` check.
|
|
64
|
-
pub fn create_recipient_address(env: &Env) -> Address {
|
|
65
|
-
env.register(DummyRecipient, ())
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// ============================================================================
|
|
69
|
-
// Test Setup
|
|
70
|
-
// ============================================================================
|
|
71
|
-
|
|
72
|
-
pub struct ChainSetup<'a> {
|
|
73
|
-
pub eid: u32,
|
|
74
|
-
pub owner: Address,
|
|
75
|
-
pub native_token: Address,
|
|
76
|
-
pub zro_token: Address,
|
|
77
|
-
/// Underlying SAC for the OFT token (used for balance, transfer, mint_to).
|
|
78
|
-
pub oft_token: Address,
|
|
79
|
-
/// Mock SAC wrapper implementing Mintable; OFT uses it for mint on credit.
|
|
80
|
-
pub sac_wrapper: Address,
|
|
81
|
-
pub endpoint: EndpointV2Client<'a>,
|
|
82
|
-
pub sml: SimpleMessageLibClient<'a>,
|
|
83
|
-
pub oft: OFTClient<'a>,
|
|
84
|
-
pub fee_collector: Address,
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
pub struct TestSetup<'a> {
|
|
88
|
-
pub env: Env,
|
|
89
|
-
pub chain_a: ChainSetup<'a>,
|
|
90
|
-
pub chain_b: ChainSetup<'a>,
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
fn setup_chain<'a>(env: &Env) -> ChainSetup<'a> {
|
|
94
|
-
let owner = Address::generate(env);
|
|
95
|
-
|
|
96
|
-
// Create native token FIRST - this must match the endpoint's NATIVE_TOKEN constant
|
|
97
|
-
let sac = env.register_stellar_asset_contract_v2(owner.clone());
|
|
98
|
-
let native_token = sac.address();
|
|
99
|
-
|
|
100
|
-
// Generate fee_collector AFTER native_token to not affect the address derivation
|
|
101
|
-
let fee_collector = Address::generate(env);
|
|
102
|
-
|
|
103
|
-
// Create ZRO token
|
|
104
|
-
let zro_sac = env.register_stellar_asset_contract_v2(owner.clone());
|
|
105
|
-
let zro_token = zro_sac.address();
|
|
106
|
-
|
|
107
|
-
// Create OFT token (SAC) and a mock SAC wrapper that implements Mintable.
|
|
108
|
-
let oft_sac = env.register_stellar_asset_contract_v2(owner.clone());
|
|
109
|
-
let oft_token = oft_sac.address();
|
|
110
|
-
let sac_wrapper_address = env.register(MockSacWrapper, (&oft_token,));
|
|
111
|
-
env.mock_auths(&[MockAuth {
|
|
112
|
-
address: &owner,
|
|
113
|
-
invoke: &MockAuthInvoke {
|
|
114
|
-
contract: &oft_token,
|
|
115
|
-
fn_name: "set_admin",
|
|
116
|
-
args: (&sac_wrapper_address,).into_val(env),
|
|
117
|
-
sub_invokes: &[],
|
|
118
|
-
},
|
|
119
|
-
}]);
|
|
120
|
-
StellarAssetClient::new(env, &oft_token).set_admin(&sac_wrapper_address);
|
|
121
|
-
|
|
122
|
-
let eid: u32 = 30400; // Test EID
|
|
123
|
-
let endpoint_address = env.register(EndpointV2, (&owner, eid, &native_token));
|
|
124
|
-
let fee_recipient = Address::generate(env);
|
|
125
|
-
let sml_address = env.register(SimpleMessageLib, (&owner, &endpoint_address, &fee_recipient));
|
|
126
|
-
let delegate: Option<Address> = Some(owner.clone());
|
|
127
|
-
let shared_decimals: u32 = 6; // Default shared decimals
|
|
128
|
-
// MintBurn with SAC wrapper: OFT uses wrapper for mint on credit; burn is on token directly.
|
|
129
|
-
let mode = OftType::MintBurn(sac_wrapper_address.clone());
|
|
130
|
-
let oft_address =
|
|
131
|
-
env.register(OFT, (&oft_token, &shared_decimals, &mode, &endpoint_address, delegate.as_ref().unwrap(), &fee_collector));
|
|
132
|
-
|
|
133
|
-
let endpoint = EndpointV2Client::new(env, &endpoint_address);
|
|
134
|
-
let sml = SimpleMessageLibClient::new(env, &sml_address);
|
|
135
|
-
let oft = OFTClient::new(env, &oft_address);
|
|
136
|
-
|
|
137
|
-
// Set ZRO token in endpoint
|
|
138
|
-
env.mock_auths(&[MockAuth {
|
|
139
|
-
address: &owner,
|
|
140
|
-
invoke: &MockAuthInvoke {
|
|
141
|
-
contract: &endpoint_address,
|
|
142
|
-
fn_name: "set_zro",
|
|
143
|
-
args: (&zro_token,).into_val(env),
|
|
144
|
-
sub_invokes: &[],
|
|
145
|
-
},
|
|
146
|
-
}]);
|
|
147
|
-
endpoint.set_zro(&zro_token);
|
|
148
|
-
|
|
149
|
-
register_library(env, &owner, &endpoint, &sml.address);
|
|
150
|
-
ChainSetup {
|
|
151
|
-
eid,
|
|
152
|
-
owner,
|
|
153
|
-
native_token,
|
|
154
|
-
zro_token,
|
|
155
|
-
oft_token,
|
|
156
|
-
sac_wrapper: sac_wrapper_address,
|
|
157
|
-
endpoint,
|
|
158
|
-
sml,
|
|
159
|
-
oft,
|
|
160
|
-
fee_collector,
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
pub fn setup<'a>() -> TestSetup<'a> {
|
|
165
|
-
let env = Env::default();
|
|
166
|
-
let chain_a = setup_chain(&env);
|
|
167
|
-
let chain_b = setup_chain(&env);
|
|
168
|
-
|
|
169
|
-
let chain_a_oft_token_decimals = TokenClient::new(&env, &chain_a.oft_token).decimals();
|
|
170
|
-
let chain_b_oft_token_decimals = TokenClient::new(&env, &chain_b.oft_token).decimals();
|
|
171
|
-
|
|
172
|
-
log!(&env, "endpoint_a: {:?}", chain_a.endpoint.address);
|
|
173
|
-
log!(&env, "native_token_a: {:?}", chain_a.native_token);
|
|
174
|
-
log!(&env, "oft_token_a: {:?}", chain_a.oft.token());
|
|
175
|
-
log!(&env, "oft_token_a decimals: {:?}", chain_a_oft_token_decimals);
|
|
176
|
-
log!(&env, "oft_a: {:?}", chain_a.oft.address);
|
|
177
|
-
log!(&env, "sml_a: {:?}", chain_a.sml.address);
|
|
178
|
-
|
|
179
|
-
log!(&env, "endpoint_b: {:?}", chain_b.endpoint.address);
|
|
180
|
-
log!(&env, "native_token_b: {:?}", chain_b.native_token);
|
|
181
|
-
log!(&env, "oft_token_b: {:?}", chain_b.oft.token());
|
|
182
|
-
log!(&env, "oft_token_b decimals: {:?}", chain_b_oft_token_decimals);
|
|
183
|
-
log!(&env, "oft_b: {:?}", chain_b.oft.address);
|
|
184
|
-
log!(&env, "sml_b: {:?}", chain_b.sml.address);
|
|
185
|
-
|
|
186
|
-
TestSetup { env, chain_a, chain_b }
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
pub fn wire_endpoint(env: &Env, chains: &[&ChainSetup<'_>]) {
|
|
190
|
-
for chain in chains {
|
|
191
|
-
for other_chain in chains {
|
|
192
|
-
if chain.endpoint.address == other_chain.endpoint.address {
|
|
193
|
-
continue;
|
|
194
|
-
}
|
|
195
|
-
set_default_send_library(env, &chain.owner, &chain.endpoint, other_chain.eid, &chain.sml.address);
|
|
196
|
-
set_default_receive_library(env, &chain.owner, &chain.endpoint, other_chain.eid, &chain.sml.address);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
pub fn wire_oft(env: &Env, chains: &[&ChainSetup<'_>]) {
|
|
202
|
-
for chain in chains {
|
|
203
|
-
for other_chain in chains {
|
|
204
|
-
if chain.endpoint.address == other_chain.endpoint.address {
|
|
205
|
-
continue;
|
|
206
|
-
}
|
|
207
|
-
set_peer(
|
|
208
|
-
env,
|
|
209
|
-
&chain.owner,
|
|
210
|
-
&chain.oft,
|
|
211
|
-
other_chain.eid,
|
|
212
|
-
&address_to_peer_bytes32(&other_chain.oft.address),
|
|
213
|
-
);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
pub fn set_peer(env: &Env, owner: &Address, oft: &OFTClient<'_>, dst_eid: u32, peer: &BytesN<32>) {
|
|
219
|
-
let peer_option = Some(peer.clone());
|
|
220
|
-
env.mock_auths(&[MockAuth {
|
|
221
|
-
address: owner,
|
|
222
|
-
invoke: &MockAuthInvoke {
|
|
223
|
-
contract: &oft.address,
|
|
224
|
-
fn_name: "set_peer",
|
|
225
|
-
args: (&dst_eid, &peer_option, owner).into_val(env),
|
|
226
|
-
sub_invokes: &[],
|
|
227
|
-
},
|
|
228
|
-
}]);
|
|
229
|
-
oapp::oapp_core::OAppCoreClient::new(env, &oft.address).set_peer(&dst_eid, &peer_option, owner);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
pub fn register_library(env: &Env, owner: &Address, endpoint: &EndpointV2Client<'_>, lib: &Address) {
|
|
233
|
-
env.mock_auths(&[MockAuth {
|
|
234
|
-
address: owner,
|
|
235
|
-
invoke: &MockAuthInvoke {
|
|
236
|
-
contract: &endpoint.address,
|
|
237
|
-
fn_name: "register_library",
|
|
238
|
-
args: (lib,).into_val(env),
|
|
239
|
-
sub_invokes: &[],
|
|
240
|
-
},
|
|
241
|
-
}]);
|
|
242
|
-
endpoint.register_library(lib);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
pub fn set_default_send_library(
|
|
246
|
-
env: &Env,
|
|
247
|
-
owner: &Address,
|
|
248
|
-
endpoint: &EndpointV2Client<'_>,
|
|
249
|
-
dst_eid: u32,
|
|
250
|
-
lib: &Address,
|
|
251
|
-
) {
|
|
252
|
-
env.mock_auths(&[MockAuth {
|
|
253
|
-
address: owner,
|
|
254
|
-
invoke: &MockAuthInvoke {
|
|
255
|
-
contract: &endpoint.address,
|
|
256
|
-
fn_name: "set_default_send_library",
|
|
257
|
-
args: (&dst_eid, lib).into_val(env),
|
|
258
|
-
sub_invokes: &[],
|
|
259
|
-
},
|
|
260
|
-
}]);
|
|
261
|
-
endpoint.set_default_send_library(&dst_eid, lib);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
pub fn set_default_receive_library(
|
|
265
|
-
env: &Env,
|
|
266
|
-
owner: &Address,
|
|
267
|
-
endpoint: &EndpointV2Client<'_>,
|
|
268
|
-
src_eid: u32,
|
|
269
|
-
lib: &Address,
|
|
270
|
-
) {
|
|
271
|
-
env.mock_auths(&[MockAuth {
|
|
272
|
-
address: owner,
|
|
273
|
-
invoke: &MockAuthInvoke {
|
|
274
|
-
contract: &endpoint.address,
|
|
275
|
-
fn_name: "set_default_receive_library",
|
|
276
|
-
args: (&src_eid, lib, &0u64).into_val(env),
|
|
277
|
-
sub_invokes: &[],
|
|
278
|
-
},
|
|
279
|
-
}]);
|
|
280
|
-
endpoint.set_default_receive_library(&src_eid, lib, &0u64);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
pub fn decode_packet(env: &Env, encoded_packet: &soroban_sdk::Bytes) -> endpoint_v2::OutboundPacket {
|
|
284
|
-
use message_lib_common::packet_codec_v1::*;
|
|
285
|
-
use utils::buffer_reader::BufferReader;
|
|
286
|
-
|
|
287
|
-
let header = decode_packet_header(env, &encoded_packet.slice(0..HEADER_LENGTH));
|
|
288
|
-
let payload = encoded_packet.slice(HEADER_LENGTH..);
|
|
289
|
-
|
|
290
|
-
let mut payload_reader = BufferReader::new(&payload);
|
|
291
|
-
let guid = payload_reader.read_bytes_n::<32>();
|
|
292
|
-
let message = payload_reader.read_bytes_until_end();
|
|
293
|
-
|
|
294
|
-
endpoint_v2::OutboundPacket {
|
|
295
|
-
nonce: header.nonce,
|
|
296
|
-
src_eid: header.src_eid,
|
|
297
|
-
sender: peer_bytes32_to_address(env, &header.sender),
|
|
298
|
-
dst_eid: header.dst_eid,
|
|
299
|
-
receiver: header.receiver,
|
|
300
|
-
guid,
|
|
301
|
-
message,
|
|
302
|
-
}
|
|
303
|
-
}
|