@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,20 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
//! Utility functions for OFT-STD integration tests.
|
|
2
2
|
|
|
3
|
-
use crate::
|
|
4
|
-
|
|
5
|
-
integration_tests::setup::{decode_packet, ChainSetup},
|
|
6
|
-
types::{OFTFeeDetail, OFTLimit, OFTReceipt, SendParam},
|
|
7
|
-
};
|
|
3
|
+
use crate::extensions::rate_limiter::Direction;
|
|
4
|
+
use crate::integration_tests::setup::{decode_packet, ChainSetup};
|
|
8
5
|
use endpoint_v2::{MessagingFee, Origin, OutboundPacket};
|
|
9
6
|
use message_lib_common::packet_codec_v1;
|
|
7
|
+
use oft_core::types::{OFTFeeDetail, OFTLimit, OFTReceipt, SendParam};
|
|
10
8
|
use soroban_sdk::{
|
|
11
9
|
address_payload::AddressPayload,
|
|
12
|
-
testutils::{Events, MockAuth, MockAuthInvoke},
|
|
10
|
+
testutils::{Events, Ledger, MockAuth, MockAuthInvoke},
|
|
13
11
|
token::StellarAssetClient,
|
|
14
12
|
xdr::ToXdr,
|
|
15
13
|
Address, Bytes, BytesN, Env, IntoVal, Map, Symbol, Val, Vec,
|
|
16
14
|
};
|
|
17
15
|
|
|
16
|
+
// ============================================================================
|
|
17
|
+
// Address Conversion Utilities
|
|
18
|
+
// ============================================================================
|
|
19
|
+
|
|
18
20
|
pub fn address_to_peer_bytes32(address: &Address) -> BytesN<32> {
|
|
19
21
|
match address.to_payload().unwrap() {
|
|
20
22
|
AddressPayload::ContractIdHash(payload) => payload,
|
|
@@ -26,6 +28,16 @@ pub fn peer_bytes32_to_address(env: &Env, bytes32: &BytesN<32>) -> Address {
|
|
|
26
28
|
AddressPayload::ContractIdHash(bytes32.clone()).to_address(env)
|
|
27
29
|
}
|
|
28
30
|
|
|
31
|
+
#[allow(dead_code)]
|
|
32
|
+
pub fn create_recipient_address(env: &Env) -> Address {
|
|
33
|
+
let bytes = BytesN::from_array(env, &[0u8; 32]);
|
|
34
|
+
peer_bytes32_to_address(env, &bytes)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// ============================================================================
|
|
38
|
+
// OFT Core Operations
|
|
39
|
+
// ============================================================================
|
|
40
|
+
|
|
29
41
|
pub fn quote_oft(chain: &ChainSetup<'_>, send_param: &SendParam) -> (OFTLimit, Vec<OFTFeeDetail>, OFTReceipt) {
|
|
30
42
|
chain.oft.quote_oft(send_param)
|
|
31
43
|
}
|
|
@@ -49,6 +61,7 @@ pub fn quote_send(
|
|
|
49
61
|
chain.oft.quote_send(sender, send_param, &pay_in_zro)
|
|
50
62
|
}
|
|
51
63
|
|
|
64
|
+
/// Send without fee (standard OFT send)
|
|
52
65
|
pub fn send(
|
|
53
66
|
env: &Env,
|
|
54
67
|
chain: &ChainSetup<'_>,
|
|
@@ -83,6 +96,88 @@ pub fn send(
|
|
|
83
96
|
chain.oft.send(sender, send_param, fee, refund_address);
|
|
84
97
|
}
|
|
85
98
|
|
|
99
|
+
/// Send with fee (OFT fee extension enabled)
|
|
100
|
+
/// Order: transfer fee to deposit -> burn tokens -> transfer native fee
|
|
101
|
+
pub fn send_with_fee(
|
|
102
|
+
env: &Env,
|
|
103
|
+
chain: &ChainSetup<'_>,
|
|
104
|
+
sender: &Address,
|
|
105
|
+
send_param: &SendParam,
|
|
106
|
+
fee: &MessagingFee,
|
|
107
|
+
refund_address: &Address,
|
|
108
|
+
oft_receipt: &OFTReceipt,
|
|
109
|
+
fee_deposit_address: &Address,
|
|
110
|
+
) {
|
|
111
|
+
let fee_amount = oft_receipt.amount_sent_ld - oft_receipt.amount_received_ld;
|
|
112
|
+
env.mock_auths(&[MockAuth {
|
|
113
|
+
address: sender,
|
|
114
|
+
invoke: &MockAuthInvoke {
|
|
115
|
+
contract: &chain.oft.address,
|
|
116
|
+
fn_name: "send",
|
|
117
|
+
args: (sender, send_param, fee, refund_address).into_val(env),
|
|
118
|
+
sub_invokes: &[
|
|
119
|
+
MockAuthInvoke {
|
|
120
|
+
contract: &chain.oft_token,
|
|
121
|
+
fn_name: "transfer",
|
|
122
|
+
args: (sender, fee_deposit_address, &fee_amount).into_val(env),
|
|
123
|
+
sub_invokes: &[],
|
|
124
|
+
},
|
|
125
|
+
MockAuthInvoke {
|
|
126
|
+
contract: &chain.oft_token,
|
|
127
|
+
fn_name: "burn",
|
|
128
|
+
args: (sender, &oft_receipt.amount_received_ld).into_val(env),
|
|
129
|
+
sub_invokes: &[],
|
|
130
|
+
},
|
|
131
|
+
MockAuthInvoke {
|
|
132
|
+
contract: &chain.native_token,
|
|
133
|
+
fn_name: "transfer",
|
|
134
|
+
args: (sender, &chain.endpoint.address, &fee.native_fee).into_val(env),
|
|
135
|
+
sub_invokes: &[],
|
|
136
|
+
},
|
|
137
|
+
],
|
|
138
|
+
},
|
|
139
|
+
}]);
|
|
140
|
+
chain.oft.send(sender, send_param, fee, refund_address);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
pub fn try_send(
|
|
144
|
+
env: &Env,
|
|
145
|
+
chain: &ChainSetup<'_>,
|
|
146
|
+
sender: &Address,
|
|
147
|
+
send_param: &SendParam,
|
|
148
|
+
fee: &MessagingFee,
|
|
149
|
+
refund_address: &Address,
|
|
150
|
+
oft_receipt: &OFTReceipt,
|
|
151
|
+
) -> bool {
|
|
152
|
+
env.mock_auths(&[MockAuth {
|
|
153
|
+
address: sender,
|
|
154
|
+
invoke: &MockAuthInvoke {
|
|
155
|
+
contract: &chain.oft.address,
|
|
156
|
+
fn_name: "send",
|
|
157
|
+
args: (sender, send_param, fee, refund_address).into_val(env),
|
|
158
|
+
sub_invokes: &[
|
|
159
|
+
MockAuthInvoke {
|
|
160
|
+
contract: &chain.native_token,
|
|
161
|
+
fn_name: "transfer",
|
|
162
|
+
args: (sender, &chain.endpoint.address, &fee.native_fee).into_val(env),
|
|
163
|
+
sub_invokes: &[],
|
|
164
|
+
},
|
|
165
|
+
MockAuthInvoke {
|
|
166
|
+
contract: &chain.oft_token,
|
|
167
|
+
fn_name: "burn",
|
|
168
|
+
args: (sender, &oft_receipt.amount_received_ld).into_val(env),
|
|
169
|
+
sub_invokes: &[],
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
},
|
|
173
|
+
}]);
|
|
174
|
+
chain.oft.try_send(sender, send_param, fee, refund_address).is_ok()
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// ============================================================================
|
|
178
|
+
// Packet Handling
|
|
179
|
+
// ============================================================================
|
|
180
|
+
|
|
86
181
|
pub fn validate_packet(env: &Env, chain: &ChainSetup<'_>, packet_event: &(Bytes, Bytes, Address)) {
|
|
87
182
|
let packet = decode_packet(env, &packet_event.0);
|
|
88
183
|
let encoded_header = packet_codec_v1::encode_packet_header(env, &packet);
|
|
@@ -131,26 +226,30 @@ pub fn lz_receive(
|
|
|
131
226
|
);
|
|
132
227
|
}
|
|
133
228
|
|
|
134
|
-
pub fn
|
|
229
|
+
pub fn try_lz_receive(
|
|
135
230
|
env: &Env,
|
|
136
231
|
chain: &ChainSetup<'_>,
|
|
137
232
|
executor: &Address,
|
|
138
233
|
packet: &OutboundPacket,
|
|
139
|
-
|
|
140
|
-
extra_data: &Bytes,
|
|
234
|
+
recipient: &Address,
|
|
141
235
|
value: i128,
|
|
142
|
-
) {
|
|
143
|
-
let
|
|
144
|
-
|
|
145
|
-
|
|
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);
|
|
236
|
+
) -> bool {
|
|
237
|
+
let origin =
|
|
238
|
+
Origin { src_eid: packet.src_eid, sender: address_to_peer_bytes32(&packet.sender), nonce: packet.nonce };
|
|
239
|
+
let extra_options = recipient.to_xdr(env);
|
|
152
240
|
|
|
153
|
-
|
|
241
|
+
env.mock_auths(&[MockAuth {
|
|
242
|
+
address: executor,
|
|
243
|
+
invoke: &MockAuthInvoke {
|
|
244
|
+
contract: &chain.oft.address,
|
|
245
|
+
fn_name: "lz_receive",
|
|
246
|
+
args: (executor, &origin, &packet.guid, &packet.message, &extra_options, &value).into_val(env),
|
|
247
|
+
sub_invokes: &[],
|
|
248
|
+
},
|
|
249
|
+
}]);
|
|
250
|
+
endpoint_v2::LayerZeroReceiverClient::new(env, &chain.oft.address)
|
|
251
|
+
.try_lz_receive(executor, &origin, &packet.guid, &packet.message, &extra_options, &value)
|
|
252
|
+
.is_ok()
|
|
154
253
|
}
|
|
155
254
|
|
|
156
255
|
// returns (encoded_payload, options, send_library)
|
|
@@ -172,6 +271,10 @@ pub fn scan_packet_sent_event(env: &Env, endpoint: &Address) -> Option<(Bytes, B
|
|
|
172
271
|
packet
|
|
173
272
|
}
|
|
174
273
|
|
|
274
|
+
// ============================================================================
|
|
275
|
+
// Token Operations
|
|
276
|
+
// ============================================================================
|
|
277
|
+
|
|
175
278
|
pub fn mint_to(env: &Env, owner: &Address, token: &Address, to: &Address, amount: i128) {
|
|
176
279
|
env.mock_auths(&[MockAuth {
|
|
177
280
|
address: owner,
|
|
@@ -199,3 +302,133 @@ pub fn transfer_sac_admin(env: &Env, owner: &Address, token: &Address, new_admin
|
|
|
199
302
|
}]);
|
|
200
303
|
StellarAssetClient::new(env, token).set_admin(new_admin);
|
|
201
304
|
}
|
|
305
|
+
|
|
306
|
+
pub fn token_balance(env: &Env, token: &Address, account: &Address) -> i128 {
|
|
307
|
+
soroban_sdk::token::TokenClient::new(env, token).balance(account)
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// ============================================================================
|
|
311
|
+
// Pausable Extension Operations
|
|
312
|
+
// ============================================================================
|
|
313
|
+
|
|
314
|
+
pub fn set_paused(env: &Env, chain: &ChainSetup<'_>, paused: bool) {
|
|
315
|
+
env.mock_auths(&[MockAuth {
|
|
316
|
+
address: &chain.owner,
|
|
317
|
+
invoke: &MockAuthInvoke {
|
|
318
|
+
contract: &chain.oft.address,
|
|
319
|
+
fn_name: "set_paused",
|
|
320
|
+
args: (&paused,).into_val(env),
|
|
321
|
+
sub_invokes: &[],
|
|
322
|
+
},
|
|
323
|
+
}]);
|
|
324
|
+
chain.oft.set_paused(&paused);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
pub fn is_paused(chain: &ChainSetup<'_>) -> bool {
|
|
328
|
+
chain.oft.is_paused()
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// ============================================================================
|
|
332
|
+
// OFT Fee Extension Operations
|
|
333
|
+
// ============================================================================
|
|
334
|
+
|
|
335
|
+
pub fn set_fee_deposit_address(env: &Env, chain: &ChainSetup<'_>, deposit_address: &Address) {
|
|
336
|
+
env.mock_auths(&[MockAuth {
|
|
337
|
+
address: &chain.owner,
|
|
338
|
+
invoke: &MockAuthInvoke {
|
|
339
|
+
contract: &chain.oft.address,
|
|
340
|
+
fn_name: "set_fee_deposit_address",
|
|
341
|
+
args: (deposit_address,).into_val(env),
|
|
342
|
+
sub_invokes: &[],
|
|
343
|
+
},
|
|
344
|
+
}]);
|
|
345
|
+
chain.oft.set_fee_deposit_address(deposit_address);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
pub fn set_default_fee_bps(env: &Env, chain: &ChainSetup<'_>, fee_bps: u64) {
|
|
349
|
+
env.mock_auths(&[MockAuth {
|
|
350
|
+
address: &chain.owner,
|
|
351
|
+
invoke: &MockAuthInvoke {
|
|
352
|
+
contract: &chain.oft.address,
|
|
353
|
+
fn_name: "set_default_fee_bps",
|
|
354
|
+
args: (&fee_bps,).into_val(env),
|
|
355
|
+
sub_invokes: &[],
|
|
356
|
+
},
|
|
357
|
+
}]);
|
|
358
|
+
chain.oft.set_default_fee_bps(&fee_bps);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
pub fn set_fee_bps(env: &Env, chain: &ChainSetup<'_>, dst_eid: u32, fee_bps: u64) {
|
|
362
|
+
env.mock_auths(&[MockAuth {
|
|
363
|
+
address: &chain.owner,
|
|
364
|
+
invoke: &MockAuthInvoke {
|
|
365
|
+
contract: &chain.oft.address,
|
|
366
|
+
fn_name: "set_fee_bps",
|
|
367
|
+
args: (&dst_eid, &fee_bps).into_val(env),
|
|
368
|
+
sub_invokes: &[],
|
|
369
|
+
},
|
|
370
|
+
}]);
|
|
371
|
+
chain.oft.set_fee_bps(&dst_eid, &fee_bps);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// ============================================================================
|
|
375
|
+
// Rate Limiter Extension Operations
|
|
376
|
+
// ============================================================================
|
|
377
|
+
|
|
378
|
+
pub fn set_rate_limit(
|
|
379
|
+
env: &Env,
|
|
380
|
+
chain: &ChainSetup<'_>,
|
|
381
|
+
direction: &Direction,
|
|
382
|
+
dst_eid: u32,
|
|
383
|
+
limit: i128,
|
|
384
|
+
window_seconds: u64,
|
|
385
|
+
) {
|
|
386
|
+
env.mock_auths(&[MockAuth {
|
|
387
|
+
address: &chain.owner,
|
|
388
|
+
invoke: &MockAuthInvoke {
|
|
389
|
+
contract: &chain.oft.address,
|
|
390
|
+
fn_name: "set_rate_limit",
|
|
391
|
+
args: (direction, &dst_eid, &limit, &window_seconds).into_val(env),
|
|
392
|
+
sub_invokes: &[],
|
|
393
|
+
},
|
|
394
|
+
}]);
|
|
395
|
+
chain.oft.set_rate_limit(direction, &dst_eid, &limit, &window_seconds);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
pub fn rate_limit_capacity(chain: &ChainSetup<'_>, direction: &Direction, eid: u32) -> i128 {
|
|
399
|
+
chain.oft.rate_limit_capacity(direction, &eid)
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
pub fn rate_limit_in_flight(chain: &ChainSetup<'_>, direction: &Direction, eid: u32) -> i128 {
|
|
403
|
+
chain.oft.rate_limit_in_flight(direction, &eid)
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// ============================================================================
|
|
407
|
+
// Time Utilities
|
|
408
|
+
// ============================================================================
|
|
409
|
+
|
|
410
|
+
pub fn advance_time(env: &Env, seconds: u64) {
|
|
411
|
+
let current = env.ledger().timestamp();
|
|
412
|
+
env.ledger().set_timestamp(current + seconds);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
#[allow(dead_code)]
|
|
416
|
+
pub fn set_timestamp(env: &Env, timestamp: u64) {
|
|
417
|
+
env.ledger().set_timestamp(timestamp);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// ============================================================================
|
|
421
|
+
// SendParam Builder
|
|
422
|
+
// ============================================================================
|
|
423
|
+
|
|
424
|
+
pub fn create_send_param(env: &Env, dst_eid: u32, amount_ld: i128, min_amount_ld: i128, to: &BytesN<32>) -> SendParam {
|
|
425
|
+
SendParam {
|
|
426
|
+
dst_eid,
|
|
427
|
+
to: to.clone(),
|
|
428
|
+
amount_ld,
|
|
429
|
+
min_amount_ld,
|
|
430
|
+
extra_options: Bytes::new(env),
|
|
431
|
+
compose_msg: Bytes::new(env),
|
|
432
|
+
oft_cmd: Bytes::new(env),
|
|
433
|
+
}
|
|
434
|
+
}
|
|
@@ -118,15 +118,15 @@ pub trait OFTFee: OFTFeeInternal + Ownable + Sized {
|
|
|
118
118
|
/// Internal trait for OFT fee operations used by OFT hooks.
|
|
119
119
|
/// Contains only truly internal methods that are called from OFTInner implementations.
|
|
120
120
|
pub trait OFTFeeInternal {
|
|
121
|
-
/// Calculates the amount
|
|
122
|
-
/// Used internally by `__debit_view` to calculate
|
|
121
|
+
/// Calculates the fee amount for a given transfer (read-only).
|
|
122
|
+
/// Used internally by `__debit_view` to calculate the fee.
|
|
123
123
|
///
|
|
124
124
|
/// # Arguments
|
|
125
125
|
/// * `dst_eid` - Destination endpoint ID to determine which fee rate to apply
|
|
126
126
|
/// * `amount_ld` - The original amount in local decimals
|
|
127
127
|
///
|
|
128
128
|
/// # Returns
|
|
129
|
-
/// The
|
|
129
|
+
/// The fee amount to be deducted
|
|
130
130
|
fn __fee_view(env: &Env, dst_eid: u32, amount_ld: i128) -> i128 {
|
|
131
131
|
// Calculate effective fee (destination-specific or default)
|
|
132
132
|
let fee_bps = if OFTFeeStorage::has_fee_bps(env, dst_eid) {
|
|
@@ -135,7 +135,7 @@ pub trait OFTFeeInternal {
|
|
|
135
135
|
OFTFeeStorage::default_fee_bps(env)
|
|
136
136
|
};
|
|
137
137
|
if fee_bps == 0 {
|
|
138
|
-
return
|
|
138
|
+
return 0;
|
|
139
139
|
}
|
|
140
140
|
// Check that fee deposit address is set (required for fee collection)
|
|
141
141
|
assert_with_error!(
|
|
@@ -143,8 +143,7 @@ pub trait OFTFeeInternal {
|
|
|
143
143
|
OFTFeeStorage::fee_deposit_address(env).is_some(),
|
|
144
144
|
OFTFeeError::InvalidFeeDepositAddress
|
|
145
145
|
);
|
|
146
|
-
|
|
147
|
-
amount_ld - preliminary_fee
|
|
146
|
+
(amount_ld * fee_bps as i128) / BASE_FEE_BPS as i128
|
|
148
147
|
}
|
|
149
148
|
|
|
150
149
|
/// Charges the fee by transferring the fee amount from sender to the fee deposit address.
|
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
#![no_std]
|
|
2
2
|
|
|
3
|
-
pub mod codec;
|
|
4
|
-
pub mod errors;
|
|
5
|
-
pub mod events;
|
|
6
3
|
pub mod extensions;
|
|
7
|
-
pub mod interfaces;
|
|
8
|
-
pub mod oft;
|
|
9
|
-
pub mod oft_impl;
|
|
10
4
|
pub mod oft_types;
|
|
11
|
-
pub mod storage;
|
|
12
|
-
pub mod types;
|
|
13
|
-
pub mod utils;
|
|
14
5
|
|
|
15
|
-
|
|
16
|
-
pub use
|
|
6
|
+
pub use extensions::*;
|
|
7
|
+
pub use oft_types::*;
|
|
8
|
+
|
|
9
|
+
cfg_if::cfg_if! {
|
|
10
|
+
// Include implementation when NOT in library mode, OR when testutils is enabled (for tests)
|
|
11
|
+
if #[cfg(any(not(feature = "library"), feature = "testutils"))] {
|
|
12
|
+
mod oft;
|
|
13
|
+
pub use oft::*;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
17
16
|
|
|
18
17
|
#[cfg(test)]
|
|
19
18
|
#[path = "../integration-tests/mod.rs"]
|
|
20
19
|
pub mod integration_tests;
|
|
21
|
-
|
|
22
|
-
#[cfg(test)]
|
|
23
|
-
pub mod tests;
|