@layerzerolabs/protocol-stellar-v2 0.2.18 → 0.2.19
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 +275 -248
- package/.turbo/turbo-lint.log +52 -58
- package/.turbo/turbo-test.log +1224 -1358
- package/Cargo.lock +8 -5
- package/Cargo.toml +1 -1
- package/contracts/ERROR_SPEC.md +1 -1
- package/contracts/message-libs/uln-302/src/send_uln.rs +1 -1
- package/contracts/oapps/oapp/src/oapp_receiver.rs +1 -1
- package/contracts/oapps/oft/Cargo.toml +10 -7
- package/contracts/oapps/{oft-std → oft}/integration-tests/extensions/test_oft_fee.rs +3 -4
- package/contracts/oapps/{oft-std → oft}/integration-tests/extensions/test_pausable.rs +2 -3
- package/contracts/oapps/{oft-std → oft}/integration-tests/extensions/test_rate_limiter.rs +1 -1
- package/contracts/oapps/oft/integration-tests/mod.rs +1 -1
- package/contracts/oapps/oft/integration-tests/setup.rs +28 -127
- package/contracts/oapps/oft/integration-tests/utils.rs +254 -21
- package/contracts/oapps/oft/src/extensions/oft_fee.rs +5 -6
- package/contracts/oapps/oft/src/lib.rs +10 -14
- package/contracts/oapps/oft/src/oft.rs +151 -189
- package/contracts/oapps/oft/src/oft_types/lock_unlock.rs +9 -11
- package/contracts/oapps/oft/src/oft_types/mint_burn.rs +32 -12
- package/contracts/oapps/oft/src/oft_types/mod.rs +13 -0
- package/contracts/oapps/{oft-std → oft-core}/Cargo.toml +6 -4
- package/contracts/oapps/{oft-std → oft-core}/integration-tests/mod.rs +1 -1
- package/contracts/oapps/{oft-std → oft-core}/integration-tests/setup.rs +126 -29
- package/contracts/oapps/{oft → oft-core}/integration-tests/test_with_sml.rs +3 -3
- package/contracts/oapps/oft-core/integration-tests/utils.rs +201 -0
- package/contracts/oapps/oft-core/src/lib.rs +18 -0
- package/contracts/oapps/oft-core/src/oft_core.rs +439 -0
- package/contracts/oapps/{oft → oft-core}/src/tests/mod.rs +0 -2
- package/contracts/oapps/{oft → oft-core}/src/tests/test_lz_receive.rs +7 -7
- package/contracts/oapps/{oft → oft-core}/src/tests/test_oft_msg_codec.rs +4 -4
- package/contracts/oapps/{oft → oft-core}/src/tests/test_resolve_address.rs +3 -3
- package/contracts/oapps/{oft → oft-core}/src/tests/test_utils.rs +44 -25
- package/contracts/oapps/{oft → oft-core}/src/utils.rs +1 -1
- package/contracts/utils/src/errors.rs +5 -1
- package/contracts/utils/src/ownable.rs +125 -3
- package/contracts/utils/src/tests/option_ext.rs +1 -1
- package/contracts/utils/src/tests/ownable.rs +445 -7
- package/contracts/utils/src/tests/ttl_configurable.rs +2 -2
- package/package.json +4 -5
- package/sdk/.turbo/turbo-test.log +216 -206
- package/sdk/dist/generated/bml.d.ts +30 -0
- package/sdk/dist/generated/bml.js +28 -5
- package/sdk/dist/generated/counter.d.ts +122 -2
- package/sdk/dist/generated/counter.js +36 -7
- package/sdk/dist/generated/dvn.d.ts +30 -0
- package/sdk/dist/generated/dvn.js +28 -5
- package/sdk/dist/generated/dvn_fee_lib.d.ts +122 -2
- package/sdk/dist/generated/dvn_fee_lib.js +36 -7
- package/sdk/dist/generated/endpoint.d.ts +122 -2
- package/sdk/dist/generated/endpoint.js +36 -7
- package/sdk/dist/generated/executor.d.ts +122 -2
- package/sdk/dist/generated/executor.js +36 -7
- package/sdk/dist/generated/executor_fee_lib.d.ts +122 -2
- package/sdk/dist/generated/executor_fee_lib.js +36 -7
- package/sdk/dist/generated/executor_helper.d.ts +30 -0
- package/sdk/dist/generated/executor_helper.js +28 -5
- package/sdk/dist/generated/oft.d.ts +1842 -0
- package/sdk/dist/generated/oft.js +345 -0
- package/sdk/dist/generated/price_feed.d.ts +122 -2
- package/sdk/dist/generated/price_feed.js +36 -7
- package/sdk/dist/generated/sml.d.ts +122 -2
- package/sdk/dist/generated/sml.js +36 -7
- package/sdk/dist/generated/treasury.d.ts +122 -2
- package/sdk/dist/generated/treasury.js +36 -7
- package/sdk/dist/generated/uln302.d.ts +122 -2
- package/sdk/dist/generated/uln302.js +36 -7
- package/sdk/dist/generated/upgrader.d.ts +15 -0
- package/sdk/dist/generated/upgrader.js +18 -0
- package/sdk/dist/index.d.ts +1 -2
- package/sdk/dist/index.js +1 -3
- package/sdk/package.json +3 -2
- package/sdk/src/index.ts +1 -4
- package/sdk/test/oft-sml.test.ts +16 -16
- package/sdk/turbo.json +8 -0
- package/tools/ts-bindings-gen/Cargo.toml +2 -0
- package/tools/ts-bindings-gen/src/main.rs +51 -4
- package/turbo.json +0 -2
- package/contracts/oapps/oft/src/interfaces/mint_burn_token.rs +0 -23
- package/contracts/oapps/oft/src/interfaces/mod.rs +0 -3
- package/contracts/oapps/oft/src/oft_impl.rs +0 -201
- package/contracts/oapps/oft/src/tests/extensions/mod.rs +0 -11
- package/contracts/oapps/oft/src/tests/extensions/setup.rs +0 -917
- package/contracts/oapps/oft/src/tests/extensions/test_oft_fee.rs +0 -751
- package/contracts/oapps/oft/src/tests/extensions/test_pausable.rs +0 -434
- package/contracts/oapps/oft/src/tests/extensions/test_rate_limiter.rs +0 -1080
- package/contracts/oapps/oft-std/integration-tests/utils.rs +0 -427
- package/contracts/oapps/oft-std/src/lib.rs +0 -16
- package/contracts/oapps/oft-std/src/oft.rs +0 -174
- package/sdk/dist/generated/oft_std.d.ts +0 -1722
- package/sdk/dist/generated/oft_std.js +0 -316
- package/sdk/dist/wasm/blocked-message-lib.d.ts +0 -1
- package/sdk/dist/wasm/blocked-message-lib.js +0 -2
- package/sdk/dist/wasm/counter.d.ts +0 -1
- package/sdk/dist/wasm/counter.js +0 -2
- package/sdk/dist/wasm/dvn-fee-lib.d.ts +0 -1
- package/sdk/dist/wasm/dvn-fee-lib.js +0 -2
- package/sdk/dist/wasm/dvn.d.ts +0 -1
- package/sdk/dist/wasm/dvn.js +0 -2
- package/sdk/dist/wasm/endpoint-v2.d.ts +0 -1
- package/sdk/dist/wasm/endpoint-v2.js +0 -2
- package/sdk/dist/wasm/executor-fee-lib.d.ts +0 -1
- package/sdk/dist/wasm/executor-fee-lib.js +0 -2
- package/sdk/dist/wasm/executor-helper.d.ts +0 -1
- package/sdk/dist/wasm/executor-helper.js +0 -2
- package/sdk/dist/wasm/executor.d.ts +0 -1
- package/sdk/dist/wasm/executor.js +0 -2
- package/sdk/dist/wasm/layerzero-views.d.ts +0 -1
- package/sdk/dist/wasm/layerzero-views.js +0 -2
- package/sdk/dist/wasm/oft-std.d.ts +0 -1
- package/sdk/dist/wasm/oft-std.js +0 -2
- package/sdk/dist/wasm/price-feed.d.ts +0 -1
- package/sdk/dist/wasm/price-feed.js +0 -2
- package/sdk/dist/wasm/simple-message-lib.d.ts +0 -1
- package/sdk/dist/wasm/simple-message-lib.js +0 -2
- package/sdk/dist/wasm/treasury.d.ts +0 -1
- package/sdk/dist/wasm/treasury.js +0 -2
- package/sdk/dist/wasm/uln302.d.ts +0 -1
- package/sdk/dist/wasm/uln302.js +0 -2
- package/sdk/dist/wasm/upgrader.d.ts +0 -1
- package/sdk/dist/wasm/upgrader.js +0 -2
- package/sdk/dist/wasm.d.ts +0 -15
- package/sdk/dist/wasm.js +0 -15
- /package/contracts/oapps/{oft-std → oft}/integration-tests/extensions/mod.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/codec/mod.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/codec/oft_compose_msg_codec.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/codec/oft_msg_codec.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/errors.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/events.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/storage.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/tests/test_decimals.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/tests/test_oft_compose_msg_codec.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/tests/test_oft_version.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/tests/test_quote_oft.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/tests/test_quote_send.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/tests/test_send.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/tests/test_token.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/types.rs +0 -0
|
@@ -1,39 +1,139 @@
|
|
|
1
|
-
//! Integration test setup for OFT
|
|
1
|
+
//! Integration test setup for OFT.
|
|
2
2
|
//!
|
|
3
|
-
//! This file contains test setup utilities
|
|
3
|
+
//! This file contains TestOFT contract and test setup utilities.
|
|
4
4
|
|
|
5
|
-
extern crate self as oft_std;
|
|
6
5
|
extern crate std;
|
|
7
6
|
|
|
8
7
|
use crate::{
|
|
8
|
+
self as oft_core,
|
|
9
9
|
integration_tests::utils::{address_to_peer_bytes32, peer_bytes32_to_address},
|
|
10
|
-
|
|
10
|
+
oft_core::{initialize_oft, lz_receive, OFTClient, OFTCore, OFTInternal},
|
|
11
|
+
storage::OFTStorage,
|
|
12
|
+
types::OFTReceipt,
|
|
11
13
|
};
|
|
12
|
-
use
|
|
14
|
+
use common_macros::contract_impl;
|
|
15
|
+
use endpoint_v2::{EndpointV2, EndpointV2Client, ILayerZeroComposer, Origin};
|
|
16
|
+
use oapp::oapp_receiver::LzReceiveInternal;
|
|
13
17
|
use simple_message_lib::{SimpleMessageLib, SimpleMessageLibClient};
|
|
14
18
|
use soroban_sdk::{
|
|
15
|
-
contract, contractimpl, log,
|
|
19
|
+
contract, contractimpl, contracttype, log, symbol_short,
|
|
16
20
|
testutils::{Address as _, MockAuth, MockAuthInvoke},
|
|
17
|
-
token::TokenClient,
|
|
18
|
-
Address, BytesN, Env, IntoVal,
|
|
21
|
+
token::{StellarAssetClient, TokenClient},
|
|
22
|
+
Address, Bytes, BytesN, Env, IntoVal,
|
|
19
23
|
};
|
|
20
24
|
|
|
21
25
|
// ============================================================================
|
|
22
|
-
//
|
|
26
|
+
// Test OFT Contract
|
|
23
27
|
// ============================================================================
|
|
24
28
|
|
|
29
|
+
#[oapp_macros::oapp]
|
|
30
|
+
pub struct TestOFT;
|
|
31
|
+
|
|
32
|
+
impl LzReceiveInternal for TestOFT {
|
|
33
|
+
fn __lz_receive(
|
|
34
|
+
env: &Env,
|
|
35
|
+
origin: &Origin,
|
|
36
|
+
guid: &BytesN<32>,
|
|
37
|
+
message: &Bytes,
|
|
38
|
+
extra_data: &Bytes,
|
|
39
|
+
executor: &Address,
|
|
40
|
+
value: i128,
|
|
41
|
+
) {
|
|
42
|
+
lz_receive::<Self>(env, executor, origin, guid, message, extra_data, value)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
#[contract_impl]
|
|
47
|
+
impl TestOFT {
|
|
48
|
+
pub fn __constructor(
|
|
49
|
+
env: &Env,
|
|
50
|
+
token: &Address,
|
|
51
|
+
owner: &Address,
|
|
52
|
+
endpoint: &Address,
|
|
53
|
+
delegate: &Option<Address>,
|
|
54
|
+
shared_decimals: u32,
|
|
55
|
+
) {
|
|
56
|
+
initialize_oft::<Self>(env, owner, token, endpoint, delegate, shared_decimals)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
#[contractimpl(contracttrait)]
|
|
61
|
+
impl OFTCore for TestOFT {}
|
|
62
|
+
|
|
63
|
+
impl OFTInternal for TestOFT {
|
|
64
|
+
fn __debit(env: &Env, sender: &Address, amount_ld: i128, min_amount_ld: i128, dst_eid: u32) -> OFTReceipt {
|
|
65
|
+
// Get the receipt (handles decimal conversion, fees, etc.)
|
|
66
|
+
let receipt = Self::__debit_view(env, amount_ld, min_amount_ld, dst_eid);
|
|
67
|
+
// Actually burn tokens from sender
|
|
68
|
+
StellarAssetClient::new(env, &OFTStorage::token(env).unwrap()).burn(sender, &receipt.amount_sent_ld);
|
|
69
|
+
receipt
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
fn __credit(env: &Env, to: &Address, amount_ld: i128, _src_eid: u32) -> i128 {
|
|
73
|
+
// Actually mint tokens to recipient
|
|
74
|
+
StellarAssetClient::new(env, &OFTStorage::token(env).unwrap()).mint(to, &amount_ld);
|
|
75
|
+
amount_ld
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// ============================================================================
|
|
80
|
+
// Dummy Composer for testing compose messages
|
|
81
|
+
// ============================================================================
|
|
82
|
+
|
|
83
|
+
#[contracttype]
|
|
84
|
+
pub struct ComposeMessage {
|
|
85
|
+
pub executor: Address,
|
|
86
|
+
pub from: Address,
|
|
87
|
+
pub guid: BytesN<32>,
|
|
88
|
+
pub index: u32,
|
|
89
|
+
pub message: Bytes,
|
|
90
|
+
pub extra_data: Bytes,
|
|
91
|
+
pub value: i128,
|
|
92
|
+
}
|
|
93
|
+
|
|
25
94
|
#[contract]
|
|
26
|
-
pub struct
|
|
95
|
+
pub struct DummyComposer;
|
|
27
96
|
|
|
28
|
-
#[
|
|
29
|
-
impl
|
|
30
|
-
pub fn __constructor(
|
|
97
|
+
#[contract_impl]
|
|
98
|
+
impl DummyComposer {
|
|
99
|
+
pub fn __constructor(env: &Env, endpoint: &Address) {
|
|
100
|
+
env.storage().instance().set(&symbol_short!("endpoint"), endpoint);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
pub fn compose_message(env: &Env) -> Option<ComposeMessage> {
|
|
104
|
+
env.storage().instance().get(&symbol_short!("msg"))
|
|
105
|
+
}
|
|
31
106
|
}
|
|
32
107
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
108
|
+
#[contract_impl]
|
|
109
|
+
impl ILayerZeroComposer for DummyComposer {
|
|
110
|
+
fn lz_compose(
|
|
111
|
+
env: &Env,
|
|
112
|
+
executor: &Address,
|
|
113
|
+
from: &Address,
|
|
114
|
+
guid: &BytesN<32>,
|
|
115
|
+
index: u32,
|
|
116
|
+
message: &Bytes,
|
|
117
|
+
extra_data: &Bytes,
|
|
118
|
+
value: i128,
|
|
119
|
+
) {
|
|
120
|
+
let endpoint_address: Address = env.storage().instance().get(&symbol_short!("endpoint")).unwrap();
|
|
121
|
+
let endpoint = endpoint_v2::MessagingComposerClient::new(env, &endpoint_address);
|
|
122
|
+
endpoint.clear_compose(&env.current_contract_address(), from, guid, &index, message);
|
|
123
|
+
|
|
124
|
+
env.storage().instance().set(
|
|
125
|
+
&symbol_short!("msg"),
|
|
126
|
+
&ComposeMessage {
|
|
127
|
+
executor: executor.clone(),
|
|
128
|
+
from: from.clone(),
|
|
129
|
+
guid: guid.clone(),
|
|
130
|
+
index,
|
|
131
|
+
message: message.clone(),
|
|
132
|
+
extra_data: extra_data.clone(),
|
|
133
|
+
value,
|
|
134
|
+
},
|
|
135
|
+
);
|
|
136
|
+
}
|
|
37
137
|
}
|
|
38
138
|
|
|
39
139
|
// ============================================================================
|
|
@@ -44,16 +144,16 @@ pub struct ChainSetup<'a> {
|
|
|
44
144
|
pub eid: u32,
|
|
45
145
|
pub owner: Address,
|
|
46
146
|
pub native_token: Address,
|
|
47
|
-
pub zro_token: Address,
|
|
48
147
|
pub oft_token: Address,
|
|
49
148
|
pub endpoint: EndpointV2Client<'a>,
|
|
50
149
|
pub sml: SimpleMessageLibClient<'a>,
|
|
51
|
-
pub oft:
|
|
52
|
-
pub
|
|
150
|
+
pub oft: OFTClient<'a>,
|
|
151
|
+
pub composer: DummyComposerClient<'a>,
|
|
53
152
|
}
|
|
54
153
|
|
|
55
154
|
pub struct TestSetup<'a> {
|
|
56
155
|
pub env: Env,
|
|
156
|
+
|
|
57
157
|
pub chain_a: ChainSetup<'a>,
|
|
58
158
|
pub chain_b: ChainSetup<'a>,
|
|
59
159
|
}
|
|
@@ -61,13 +161,9 @@ pub struct TestSetup<'a> {
|
|
|
61
161
|
fn setup_chain<'a>(env: &Env) -> ChainSetup<'a> {
|
|
62
162
|
let owner = Address::generate(env);
|
|
63
163
|
|
|
64
|
-
// Create native token FIRST - this must match the endpoint's NATIVE_TOKEN constant
|
|
65
164
|
let sac = env.register_stellar_asset_contract_v2(owner.clone());
|
|
66
165
|
let native_token = sac.address();
|
|
67
166
|
|
|
68
|
-
// Generate fee_collector AFTER native_token to not affect the address derivation
|
|
69
|
-
let fee_collector = Address::generate(env);
|
|
70
|
-
|
|
71
167
|
// Create ZRO token
|
|
72
168
|
let zro_sac = env.register_stellar_asset_contract_v2(owner.clone());
|
|
73
169
|
let zro_token = zro_sac.address();
|
|
@@ -81,12 +177,13 @@ fn setup_chain<'a>(env: &Env) -> ChainSetup<'a> {
|
|
|
81
177
|
let sml_address = env.register(SimpleMessageLib, (&owner, &endpoint_address, &fee_recipient));
|
|
82
178
|
let delegate: Option<Address> = Some(owner.clone());
|
|
83
179
|
let shared_decimals: u32 = 6; // Default shared decimals
|
|
84
|
-
let
|
|
85
|
-
let
|
|
180
|
+
let oft_address = env.register(TestOFT, (&oft_token, &owner, &endpoint_address, &delegate, &shared_decimals));
|
|
181
|
+
let composer_address = env.register(DummyComposer, (&endpoint_address,));
|
|
86
182
|
|
|
87
183
|
let endpoint = EndpointV2Client::new(env, &endpoint_address);
|
|
88
184
|
let sml = SimpleMessageLibClient::new(env, &sml_address);
|
|
89
|
-
let oft =
|
|
185
|
+
let oft = OFTClient::new(env, &oft_address);
|
|
186
|
+
let composer = DummyComposerClient::new(env, &composer_address);
|
|
90
187
|
|
|
91
188
|
// Set ZRO token in endpoint
|
|
92
189
|
env.mock_auths(&[MockAuth {
|
|
@@ -103,7 +200,7 @@ fn setup_chain<'a>(env: &Env) -> ChainSetup<'a> {
|
|
|
103
200
|
register_library(env, &owner, &endpoint, &sml.address);
|
|
104
201
|
|
|
105
202
|
let eid = endpoint.eid();
|
|
106
|
-
ChainSetup { eid, owner, native_token,
|
|
203
|
+
ChainSetup { eid, owner, native_token, oft_token, endpoint, sml, oft, composer }
|
|
107
204
|
}
|
|
108
205
|
|
|
109
206
|
pub fn setup<'a>() -> TestSetup<'a> {
|
|
@@ -160,7 +257,7 @@ pub fn wire_oft(env: &Env, chains: &[&ChainSetup<'_>]) {
|
|
|
160
257
|
}
|
|
161
258
|
}
|
|
162
259
|
|
|
163
|
-
pub fn set_peer(env: &Env, owner: &Address, oft: &
|
|
260
|
+
pub fn set_peer(env: &Env, owner: &Address, oft: &OFTClient<'_>, dst_eid: u32, peer: &BytesN<32>) {
|
|
164
261
|
env.mock_auths(&[MockAuth {
|
|
165
262
|
address: owner,
|
|
166
263
|
invoke: &MockAuthInvoke {
|
|
@@ -13,7 +13,7 @@ use crate::{
|
|
|
13
13
|
},
|
|
14
14
|
tests::test_utils::create_recipient_address,
|
|
15
15
|
types::SendParam,
|
|
16
|
-
utils::
|
|
16
|
+
utils::address_payload,
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
#[test]
|
|
@@ -43,7 +43,7 @@ fn test_send_vanilla() {
|
|
|
43
43
|
|
|
44
44
|
let send_param = SendParam {
|
|
45
45
|
dst_eid: chain_b.eid,
|
|
46
|
-
to:
|
|
46
|
+
to: address_payload(&receiver),
|
|
47
47
|
amount_ld: 10e7 as i128,
|
|
48
48
|
min_amount_ld: 10e7 as i128,
|
|
49
49
|
extra_options: bytes!(&env),
|
|
@@ -99,7 +99,7 @@ fn test_send_composed() {
|
|
|
99
99
|
|
|
100
100
|
let send_param = SendParam {
|
|
101
101
|
dst_eid: chain_b.eid,
|
|
102
|
-
to:
|
|
102
|
+
to: address_payload(&receiver),
|
|
103
103
|
amount_ld: 10e7 as i128,
|
|
104
104
|
min_amount_ld: 10e7 as i128,
|
|
105
105
|
extra_options: bytes!(&env),
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
use core::ops::Mul;
|
|
2
|
+
|
|
3
|
+
use crate::{
|
|
4
|
+
codec::{oft_compose_msg_codec::OFTComposeMsg, oft_msg_codec},
|
|
5
|
+
integration_tests::setup::{decode_packet, ChainSetup},
|
|
6
|
+
types::{OFTFeeDetail, OFTLimit, OFTReceipt, SendParam},
|
|
7
|
+
};
|
|
8
|
+
use endpoint_v2::{MessagingFee, Origin, OutboundPacket};
|
|
9
|
+
use message_lib_common::packet_codec_v1;
|
|
10
|
+
use soroban_sdk::{
|
|
11
|
+
address_payload::AddressPayload,
|
|
12
|
+
testutils::{Events, MockAuth, MockAuthInvoke},
|
|
13
|
+
token::StellarAssetClient,
|
|
14
|
+
xdr::ToXdr,
|
|
15
|
+
Address, Bytes, BytesN, Env, IntoVal, Map, Symbol, Val, Vec,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
pub fn address_to_peer_bytes32(address: &Address) -> BytesN<32> {
|
|
19
|
+
match address.to_payload().unwrap() {
|
|
20
|
+
AddressPayload::ContractIdHash(payload) => payload,
|
|
21
|
+
AddressPayload::AccountIdPublicKeyEd25519(_) => panic!("peer must be a contract"),
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
pub fn peer_bytes32_to_address(env: &Env, bytes32: &BytesN<32>) -> Address {
|
|
26
|
+
AddressPayload::ContractIdHash(bytes32.clone()).to_address(env)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
pub fn quote_oft(chain: &ChainSetup<'_>, send_param: &SendParam) -> (OFTLimit, Vec<OFTFeeDetail>, OFTReceipt) {
|
|
30
|
+
chain.oft.quote_oft(send_param)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
pub fn quote_send(
|
|
34
|
+
env: &Env,
|
|
35
|
+
chain: &ChainSetup<'_>,
|
|
36
|
+
sender: &Address,
|
|
37
|
+
send_param: &SendParam,
|
|
38
|
+
pay_in_zro: bool,
|
|
39
|
+
) -> MessagingFee {
|
|
40
|
+
env.mock_auths(&[MockAuth {
|
|
41
|
+
address: sender,
|
|
42
|
+
invoke: &MockAuthInvoke {
|
|
43
|
+
contract: &chain.oft.address,
|
|
44
|
+
fn_name: "quote_send",
|
|
45
|
+
args: (sender, send_param, &pay_in_zro).into_val(env),
|
|
46
|
+
sub_invokes: &[],
|
|
47
|
+
},
|
|
48
|
+
}]);
|
|
49
|
+
chain.oft.quote_send(sender, send_param, &pay_in_zro)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
pub fn send(
|
|
53
|
+
env: &Env,
|
|
54
|
+
chain: &ChainSetup<'_>,
|
|
55
|
+
sender: &Address,
|
|
56
|
+
send_param: &SendParam,
|
|
57
|
+
fee: &MessagingFee,
|
|
58
|
+
refund_address: &Address,
|
|
59
|
+
oft_receipt: &OFTReceipt,
|
|
60
|
+
) {
|
|
61
|
+
env.mock_auths(&[MockAuth {
|
|
62
|
+
address: sender,
|
|
63
|
+
invoke: &MockAuthInvoke {
|
|
64
|
+
contract: &chain.oft.address,
|
|
65
|
+
fn_name: "send",
|
|
66
|
+
args: (sender, send_param, fee, refund_address).into_val(env),
|
|
67
|
+
sub_invokes: &[
|
|
68
|
+
MockAuthInvoke {
|
|
69
|
+
contract: &chain.native_token,
|
|
70
|
+
fn_name: "transfer",
|
|
71
|
+
args: (sender, &chain.endpoint.address, &fee.native_fee).into_val(env),
|
|
72
|
+
sub_invokes: &[],
|
|
73
|
+
},
|
|
74
|
+
MockAuthInvoke {
|
|
75
|
+
contract: &chain.oft_token,
|
|
76
|
+
fn_name: "burn",
|
|
77
|
+
args: (sender, &oft_receipt.amount_received_ld).into_val(env),
|
|
78
|
+
sub_invokes: &[],
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
}]);
|
|
83
|
+
chain.oft.send(sender, send_param, fee, refund_address);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
pub fn validate_packet(env: &Env, chain: &ChainSetup<'_>, packet_event: &(Bytes, Bytes, Address)) {
|
|
87
|
+
let packet = decode_packet(env, &packet_event.0);
|
|
88
|
+
let encoded_header = packet_codec_v1::encode_packet_header(env, &packet);
|
|
89
|
+
let payload_hash = packet_codec_v1::payload_hash(env, &packet);
|
|
90
|
+
|
|
91
|
+
env.mock_auths(&[MockAuth {
|
|
92
|
+
address: &chain.owner,
|
|
93
|
+
invoke: &MockAuthInvoke {
|
|
94
|
+
contract: &chain.sml.address,
|
|
95
|
+
fn_name: "validate_packet",
|
|
96
|
+
args: (&encoded_header, &payload_hash).into_val(env),
|
|
97
|
+
sub_invokes: &[],
|
|
98
|
+
},
|
|
99
|
+
}]);
|
|
100
|
+
chain.sml.validate_packet(&encoded_header, &payload_hash);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
pub fn lz_receive(
|
|
104
|
+
env: &Env,
|
|
105
|
+
chain: &ChainSetup<'_>,
|
|
106
|
+
executor: &Address,
|
|
107
|
+
packet: &OutboundPacket,
|
|
108
|
+
recipient: &Address,
|
|
109
|
+
value: i128,
|
|
110
|
+
) {
|
|
111
|
+
let origin =
|
|
112
|
+
Origin { src_eid: packet.src_eid, sender: address_to_peer_bytes32(&packet.sender), nonce: packet.nonce };
|
|
113
|
+
let extra_options = recipient.to_xdr(env);
|
|
114
|
+
|
|
115
|
+
env.mock_auths(&[MockAuth {
|
|
116
|
+
address: executor,
|
|
117
|
+
invoke: &MockAuthInvoke {
|
|
118
|
+
contract: &chain.oft.address,
|
|
119
|
+
fn_name: "lz_receive",
|
|
120
|
+
args: (executor, &origin, &packet.guid, &packet.message, &extra_options, &value).into_val(env),
|
|
121
|
+
sub_invokes: &[],
|
|
122
|
+
},
|
|
123
|
+
}]);
|
|
124
|
+
endpoint_v2::LayerZeroReceiverClient::new(env, &chain.oft.address).lz_receive(
|
|
125
|
+
executor,
|
|
126
|
+
&origin,
|
|
127
|
+
&packet.guid,
|
|
128
|
+
&packet.message,
|
|
129
|
+
&extra_options,
|
|
130
|
+
&value,
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
pub fn lz_compose(
|
|
135
|
+
env: &Env,
|
|
136
|
+
chain: &ChainSetup<'_>,
|
|
137
|
+
executor: &Address,
|
|
138
|
+
packet: &OutboundPacket,
|
|
139
|
+
index: u32,
|
|
140
|
+
extra_data: &Bytes,
|
|
141
|
+
value: i128,
|
|
142
|
+
) {
|
|
143
|
+
let oft_msg = oft_msg_codec::OFTMessage::decode(&packet.message);
|
|
144
|
+
let oft_compose_msg = OFTComposeMsg {
|
|
145
|
+
nonce: packet.nonce,
|
|
146
|
+
src_eid: packet.src_eid,
|
|
147
|
+
amount_ld: (oft_msg.amount_sd as i128).mul(chain.oft.decimal_conversion_rate()),
|
|
148
|
+
compose_from: oft_msg.compose_from.unwrap(),
|
|
149
|
+
compose_msg: oft_msg.compose_msg.unwrap(),
|
|
150
|
+
}
|
|
151
|
+
.encode(&env);
|
|
152
|
+
|
|
153
|
+
chain.composer.lz_compose(executor, &chain.oft.address, &packet.guid, &index, &oft_compose_msg, extra_data, &value);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// returns (encoded_payload, options, send_library)
|
|
157
|
+
pub fn scan_packet_sent_event(env: &Env, endpoint: &Address) -> Option<(Bytes, Bytes, Address)> {
|
|
158
|
+
let mut packet = None;
|
|
159
|
+
for (emitter, topics, data) in env.events().all() {
|
|
160
|
+
let packet_sent_symbol = Symbol::new(env, "packet_sent").to_val();
|
|
161
|
+
if emitter == *endpoint && topics.contains(packet_sent_symbol) {
|
|
162
|
+
let map: Map<Symbol, Val> = data.into_val(env);
|
|
163
|
+
|
|
164
|
+
let encoded_payload: Bytes = map.get(Symbol::new(env, "encoded_packet")).unwrap().into_val(env);
|
|
165
|
+
let options: Bytes = map.get(Symbol::new(env, "options")).unwrap().into_val(env);
|
|
166
|
+
let send_library: Address = map.get(Symbol::new(env, "send_library")).unwrap().into_val(env);
|
|
167
|
+
|
|
168
|
+
packet = Some((encoded_payload, options, send_library));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
packet
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
pub fn mint_to(env: &Env, owner: &Address, token: &Address, to: &Address, amount: i128) {
|
|
176
|
+
env.mock_auths(&[MockAuth {
|
|
177
|
+
address: owner,
|
|
178
|
+
invoke: &MockAuthInvoke {
|
|
179
|
+
contract: token,
|
|
180
|
+
fn_name: "mint",
|
|
181
|
+
args: (to, amount).into_val(env),
|
|
182
|
+
sub_invokes: &[],
|
|
183
|
+
},
|
|
184
|
+
}]);
|
|
185
|
+
|
|
186
|
+
let sac = StellarAssetClient::new(env, token);
|
|
187
|
+
sac.mint(to, &amount);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
pub fn transfer_sac_admin(env: &Env, owner: &Address, token: &Address, new_admin: &Address) {
|
|
191
|
+
env.mock_auths(&[MockAuth {
|
|
192
|
+
address: owner,
|
|
193
|
+
invoke: &MockAuthInvoke {
|
|
194
|
+
contract: token,
|
|
195
|
+
fn_name: "set_admin",
|
|
196
|
+
args: (new_admin,).into_val(env),
|
|
197
|
+
sub_invokes: &[],
|
|
198
|
+
},
|
|
199
|
+
}]);
|
|
200
|
+
StellarAssetClient::new(env, token).set_admin(new_admin);
|
|
201
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#![no_std]
|
|
2
|
+
|
|
3
|
+
pub mod codec;
|
|
4
|
+
pub mod errors;
|
|
5
|
+
pub mod events;
|
|
6
|
+
pub mod oft_core;
|
|
7
|
+
pub mod storage;
|
|
8
|
+
pub mod types;
|
|
9
|
+
pub mod utils;
|
|
10
|
+
|
|
11
|
+
pub use oft_core::*;
|
|
12
|
+
|
|
13
|
+
#[cfg(test)]
|
|
14
|
+
#[path = "../integration-tests/mod.rs"]
|
|
15
|
+
pub mod integration_tests;
|
|
16
|
+
|
|
17
|
+
#[cfg(test)]
|
|
18
|
+
pub mod tests;
|