@layerzerolabs/protocol-stellar-v2 0.2.19 → 0.2.20

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.
Files changed (125) hide show
  1. package/.turbo/turbo-build.log +245 -222
  2. package/.turbo/turbo-lint.log +77 -70
  3. package/.turbo/turbo-test.log +1385 -1221
  4. package/Cargo.lock +13 -3
  5. package/Cargo.toml +2 -0
  6. package/contracts/ERROR_SPEC.md +8 -1
  7. package/contracts/common-macros/src/contract_ttl.rs +18 -7
  8. package/contracts/common-macros/src/lib.rs +4 -4
  9. package/contracts/common-macros/src/tests/contract_ttl.rs +1 -1
  10. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__contract_ttl__snapshot_generated_contractimpl_code.snap +2 -1
  11. package/contracts/common-macros/src/tests/snapshots/common_macros__tests__upgradeable__snapshot_generated_upgradeable_code.snap +7 -12
  12. package/contracts/common-macros/src/upgradeable.rs +15 -21
  13. package/contracts/message-libs/uln-302/src/events.rs +4 -0
  14. package/contracts/message-libs/uln-302/src/send_uln.rs +22 -6
  15. package/contracts/message-libs/uln-302/src/tests/send_uln302/send.rs +38 -64
  16. package/contracts/oapps/counter/Cargo.toml +1 -0
  17. package/contracts/oapps/counter/integration_tests/setup_uln.rs +1 -1
  18. package/contracts/oapps/oapp/src/tests/test_oapp_core.rs +113 -65
  19. package/contracts/oapps/oapp/src/tests/test_oapp_options_type3.rs +111 -82
  20. package/contracts/oapps/oapp/src/tests/test_oapp_receiver.rs +293 -65
  21. package/contracts/oapps/oapp/src/tests/test_oapp_sender.rs +331 -56
  22. package/contracts/oapps/oft/src/extensions/oft_fee.rs +18 -2
  23. package/contracts/oapps/oft/src/extensions/pausable.rs +19 -4
  24. package/contracts/oapps/oft/src/extensions/rate_limiter.rs +52 -28
  25. package/contracts/oapps/oft/src/oft.rs +29 -41
  26. package/contracts/oapps/oft/src/oft_types/mint_burn.rs +3 -25
  27. package/contracts/oapps/oft-core/integration-tests/setup.rs +2 -2
  28. package/contracts/oapps/oft-core/src/oft_core.rs +247 -207
  29. package/contracts/oapps/oft-core/src/tests/test_utils.rs +4 -4
  30. package/contracts/upgrader/src/lib.rs +30 -57
  31. package/contracts/upgrader/src/tests/test_data/test_upgradeable_contract1.wasm +0 -0
  32. package/contracts/upgrader/src/tests/test_data/test_upgradeable_contract2.wasm +0 -0
  33. package/contracts/upgrader/src/tests/test_upgrader.rs +44 -35
  34. package/contracts/utils/src/buffer_reader.rs +1 -0
  35. package/contracts/utils/src/errors.rs +3 -1
  36. package/contracts/utils/src/tests/upgradeable.rs +372 -175
  37. package/contracts/utils/src/ttl_configurable.rs +3 -3
  38. package/contracts/utils/src/upgradeable.rs +48 -23
  39. package/contracts/workers/dvn/Cargo.toml +1 -0
  40. package/contracts/workers/dvn/src/auth.rs +12 -42
  41. package/contracts/workers/dvn/src/dvn.rs +16 -31
  42. package/contracts/workers/dvn/src/errors.rs +0 -1
  43. package/contracts/workers/dvn/src/interfaces/dvn.rs +35 -0
  44. package/contracts/workers/dvn/src/lib.rs +4 -3
  45. package/contracts/workers/dvn/src/tests/auth.rs +1 -1
  46. package/contracts/workers/dvn/src/tests/dvn.rs +19 -15
  47. package/contracts/workers/dvn/src/tests/multisig/set_threshold.rs +2 -4
  48. package/contracts/workers/dvn/src/tests/multisig/verify_signatures.rs +1 -3
  49. package/contracts/workers/dvn/src/tests/setup.rs +5 -9
  50. package/contracts/workers/dvn-fee-lib/Cargo.toml +1 -1
  51. package/contracts/workers/dvn-fee-lib/src/dvn_fee_lib.rs +3 -5
  52. package/contracts/workers/dvn-fee-lib/src/tests/dvn_fee_lib.rs +2 -3
  53. package/contracts/workers/executor/Cargo.toml +1 -0
  54. package/contracts/workers/executor/src/executor.rs +15 -26
  55. package/contracts/workers/executor-fee-lib/Cargo.toml +2 -1
  56. package/contracts/workers/executor-fee-lib/src/executor_fee_lib.rs +63 -5
  57. package/contracts/workers/executor-fee-lib/src/executor_option.rs +28 -1
  58. package/contracts/workers/executor-fee-lib/src/lib.rs +3 -0
  59. package/contracts/workers/executor-fee-lib/src/tests/executor_fee_lib.rs +701 -0
  60. package/contracts/workers/executor-fee-lib/src/tests/executor_option.rs +370 -0
  61. package/contracts/workers/executor-fee-lib/src/tests/mod.rs +4 -0
  62. package/contracts/workers/executor-fee-lib/src/tests/setup.rs +60 -0
  63. package/contracts/workers/executor-helper/src/lib.rs +3 -0
  64. package/contracts/workers/executor-helper/src/tests/executor_helper.rs +184 -0
  65. package/contracts/workers/executor-helper/src/tests/mod.rs +2 -0
  66. package/contracts/workers/executor-helper/src/tests/setup.rs +366 -0
  67. package/contracts/workers/fee-lib-interfaces/Cargo.toml +14 -0
  68. package/contracts/workers/{worker/src/interfaces/mod.rs → fee-lib-interfaces/src/lib.rs} +4 -3
  69. package/contracts/workers/price-feed/Cargo.toml +2 -1
  70. package/contracts/workers/price-feed/src/events.rs +1 -1
  71. package/contracts/workers/price-feed/src/lib.rs +3 -0
  72. package/contracts/workers/price-feed/src/price_feed.rs +6 -12
  73. package/contracts/workers/price-feed/src/storage.rs +1 -1
  74. package/contracts/workers/price-feed/src/tests/mod.rs +2 -0
  75. package/contracts/workers/price-feed/src/tests/price_feed.rs +869 -0
  76. package/contracts/workers/price-feed/src/tests/setup.rs +70 -0
  77. package/contracts/workers/price-feed/src/types.rs +1 -1
  78. package/contracts/workers/worker/src/errors.rs +0 -3
  79. package/contracts/workers/worker/src/lib.rs +0 -2
  80. package/contracts/workers/worker/src/storage.rs +32 -29
  81. package/contracts/workers/worker/src/tests/setup.rs +1 -7
  82. package/contracts/workers/worker/src/tests/worker.rs +50 -42
  83. package/contracts/workers/worker/src/worker.rs +49 -58
  84. package/package.json +3 -3
  85. package/sdk/.turbo/turbo-test.log +220 -218
  86. package/sdk/dist/generated/bml.d.ts +12 -4
  87. package/sdk/dist/generated/bml.js +8 -6
  88. package/sdk/dist/generated/counter.d.ts +12 -4
  89. package/sdk/dist/generated/counter.js +8 -6
  90. package/sdk/dist/generated/dvn.d.ts +404 -365
  91. package/sdk/dist/generated/dvn.js +55 -53
  92. package/sdk/dist/generated/dvn_fee_lib.d.ts +224 -268
  93. package/sdk/dist/generated/dvn_fee_lib.js +22 -53
  94. package/sdk/dist/generated/endpoint.d.ts +12 -4
  95. package/sdk/dist/generated/endpoint.js +8 -6
  96. package/sdk/dist/generated/executor.d.ts +370 -326
  97. package/sdk/dist/generated/executor.js +47 -44
  98. package/sdk/dist/generated/executor_fee_lib.d.ts +258 -302
  99. package/sdk/dist/generated/executor_fee_lib.js +21 -52
  100. package/sdk/dist/generated/executor_helper.d.ts +26 -190
  101. package/sdk/dist/generated/executor_helper.js +22 -27
  102. package/sdk/dist/generated/layerzero_view.d.ts +1271 -0
  103. package/sdk/dist/generated/layerzero_view.js +294 -0
  104. package/sdk/dist/generated/oft.d.ts +49 -40
  105. package/sdk/dist/generated/oft.js +25 -23
  106. package/sdk/dist/generated/price_feed.d.ts +225 -269
  107. package/sdk/dist/generated/price_feed.js +22 -53
  108. package/sdk/dist/generated/sml.d.ts +12 -4
  109. package/sdk/dist/generated/sml.js +8 -6
  110. package/sdk/dist/generated/treasury.d.ts +12 -4
  111. package/sdk/dist/generated/treasury.js +8 -6
  112. package/sdk/dist/generated/uln302.d.ts +12 -4
  113. package/sdk/dist/generated/uln302.js +10 -8
  114. package/sdk/dist/generated/upgrader.d.ts +189 -18
  115. package/sdk/dist/generated/upgrader.js +84 -4
  116. package/sdk/dist/index.d.ts +1 -0
  117. package/sdk/dist/index.js +2 -0
  118. package/sdk/package.json +1 -1
  119. package/sdk/src/index.ts +3 -0
  120. package/sdk/test/oft-sml.test.ts +4 -4
  121. package/sdk/test/upgrader.test.ts +2 -3
  122. package/tools/ts-bindings-gen/src/main.rs +2 -1
  123. /package/contracts/workers/{worker/src/interfaces → fee-lib-interfaces/src}/dvn_fee_lib.rs +0 -0
  124. /package/contracts/workers/{worker/src/interfaces → fee-lib-interfaces/src}/executor_fee_lib.rs +0 -0
  125. /package/contracts/workers/{worker/src/interfaces → fee-lib-interfaces/src}/price_feed.rs +0 -0
@@ -2,45 +2,25 @@
2
2
 
3
3
  //! # Upgrader Contract
4
4
  //!
5
- //! A stateless utility contract for performing upgrade and migrate operations on upgradeable contracts.
6
- //!
7
- //! This contract provides a convenient way to upgrade other contracts, especially useful for
8
- //! performing upgrade+migrate atomically in a single transaction.
5
+ //! A stateless utility contract for performing atomic upgrade and migrate operations
6
+ //! on contracts implementing the [`Upgradeable`](utils::upgradeable::Upgradeable) trait.
9
7
  //!
10
8
  //! ## Security Model
11
9
  //!
12
- //! The Upgrader is a permissionless utility - anyone can call it, but security is enforced
13
- //! by the target contract's authorization checks. When you call `upgrader.upgrade()`, the target
14
- //! contract's `#[only_auth]` guard ensures only the target's authorizer can successfully upgrade it.
10
+ //! The Upgrader is permissionless - anyone can call it, but security is enforced by the
11
+ //! target contract's authorization checks. The target contract's `#[only_auth]` guard
12
+ //! ensures only its authorizer can successfully upgrade it.
15
13
  //!
16
14
  //! ## Usage
17
15
  //!
18
- //! Deploy this contract once, then anyone can use it to upgrade contracts they own.
19
- //!
20
16
  //! ```ignore
21
- //! // Deploy upgrader (no initialization needed)
22
- //! let upgrader_id = env.register(Upgrader, ());
23
17
  //! let upgrader = UpgraderClient::new(&env, &upgrader_id);
24
- //!
25
- //! // Upgrade a contract (you must be the target contract's owner)
26
- //! upgrader.upgrade(&target_contract, &new_wasm_hash);
27
- //!
28
- //! // Or upgrade and migrate in one transaction
29
- //! let migration_data = vec![&env, val1, val2];
30
- //! upgrader.upgrade_and_migrate(&target_contract, &new_wasm_hash, migration_data);
18
+ //! let migration_data = my_data.to_xdr(&env);
19
+ //! upgrader.upgrade_and_migrate(&target_contract, &new_wasm_hash, &migration_data);
31
20
  //! ```
32
21
 
33
- use soroban_sdk::{contract, contractclient, contractimpl, symbol_short, Address, BytesN, Env, Symbol, Vec};
34
-
35
- /// Symbol for the migrate function call
36
- pub const MIGRATE: Symbol = symbol_short!("migrate");
37
-
38
- /// Trait representing an upgradeable contract's interface
39
- #[contractclient(name = "UpgradeableContractClient")]
40
- pub trait UpgradeableContract {
41
- /// Upgrades the contract to new WASM bytecode
42
- fn upgrade(env: &Env, new_wasm_hash: BytesN<32>);
43
- }
22
+ use soroban_sdk::{contract, contractimpl, xdr::ToXdr, Address, Bytes, BytesN, Env};
23
+ use utils::upgradeable::UpgradeableClient;
44
24
 
45
25
  /// Upgrader contract for managing upgrades of other contracts.
46
26
  ///
@@ -51,46 +31,39 @@ pub struct Upgrader;
51
31
 
52
32
  #[contractimpl]
53
33
  impl Upgrader {
54
- /// Upgrade a target contract and run its migration in a single transaction
34
+ /// Upgrades a target contract without custom migration data.
35
+ ///
36
+ /// This is a convenience wrapper that calls `upgrade_and_migrate` with empty migration data.
37
+ ///
38
+ /// # Arguments
39
+ /// * `contract_address` - The address of the contract to upgrade
40
+ /// * `wasm_hash` - The hash of the new WASM bytecode
41
+ pub fn upgrade(env: &Env, contract_address: &Address, wasm_hash: &BytesN<32>) {
42
+ Self::upgrade_and_migrate(env, contract_address, wasm_hash, &().to_xdr(env));
43
+ }
44
+
45
+ /// Upgrades a target contract and runs its migration in a single transaction.
55
46
  ///
56
47
  /// The caller must be authorized as the authorizer of the target contract.
57
48
  /// This is enforced by the target contract's `#[only_auth]` check.
58
49
  ///
59
- /// This is useful for atomic upgrades where you want to ensure the migration
60
- /// happens immediately after the upgrade, or the entire operation fails.
61
- ///
62
50
  /// # Arguments
63
51
  /// * `contract_address` - The address of the contract to upgrade
64
52
  /// * `wasm_hash` - The hash of the new WASM bytecode
65
- /// * `migration_data` - A vector of values to pass to the migrate function.
66
- /// The types of these values depend on the target contract's MigrationData type.
53
+ /// * `migration_data` - XDR-encoded bytes to pass to the migrate function.
54
+ /// Use `value.to_xdr(&env)` to encode the target contract's MigrationData type.
67
55
  ///
68
56
  /// # Example
69
57
  /// ```ignore
70
- /// // For a contract with MigrationData = (u32, bool)
71
- /// let migration_data = vec![
72
- /// &env,
73
- /// 42u32.into_val(&env),
74
- /// true.into_val(&env),
75
- /// ];
76
- /// upgrader.upgrade_and_migrate(&contract_addr, &wasm_hash, migration_data);
58
+ /// let migration_data = my_data.to_xdr(&env);
59
+ /// upgrader.upgrade_and_migrate(&contract_addr, &wasm_hash, &migration_data);
77
60
  /// ```
78
- pub fn upgrade_and_migrate(
79
- env: &Env,
80
- contract_address: &Address,
81
- wasm_hash: BytesN<32>,
82
- migration_data: Vec<soroban_sdk::Val>,
83
- ) {
84
- let contract_client = UpgradeableContractClient::new(env, contract_address);
85
-
86
- // First upgrade the contract
87
- contract_client.upgrade(&wasm_hash);
88
-
89
- // Then call migrate with the provided data
90
- // We use invoke_contract because the migration data type is unknown to this contract
91
- env.invoke_contract::<()>(contract_address, &MIGRATE, migration_data);
61
+ pub fn upgrade_and_migrate(env: &Env, contract_address: &Address, wasm_hash: &BytesN<32>, migration_data: &Bytes) {
62
+ let client = UpgradeableClient::new(env, contract_address);
63
+ client.upgrade(wasm_hash);
64
+ client.migrate(migration_data);
92
65
  }
93
66
  }
94
67
 
95
68
  #[cfg(test)]
96
- mod tests;
69
+ mod tests;
@@ -1,6 +1,6 @@
1
1
  extern crate std;
2
2
 
3
- use soroban_sdk::{contractclient, testutils::Address as _, Address, BytesN, Env, TryIntoVal};
3
+ use soroban_sdk::{contractclient, testutils::Address as _, xdr::ToXdr, Address, BytesN, Env};
4
4
 
5
5
  use crate::{Upgrader, UpgraderClient};
6
6
 
@@ -17,16 +17,20 @@ trait TestUpgradeableContract2 {
17
17
  }
18
18
 
19
19
  mod contract_v1 {
20
- // #[contract]
21
- // #[upgradeable]
22
- // #[ownable]
23
- // pub struct TestUpgradeableContract;
20
+ //#![no_std]
24
21
 
25
- // impl UpgradeableInternal for TestUpgradeableContract {
26
- // type MigrationData = ();
22
+ // use soroban_sdk::{contractimpl, Env, Symbol, Address, contractclient};
23
+ // use utils::{ upgradeable::UpgradeableInternal};
24
+ // use common_macros::lz_contract;
27
25
 
28
- // fn _migrate(env: &Env, _migration_data: &Self::MigrationData) {
29
- // env.storage().instance().set(&Symbol::new(env, "counter"), &2);
26
+ // #[lz_contract(upgradeable)]
27
+ // pub struct DummyContract;
28
+
29
+ // impl UpgradeableInternal for DummyContract {
30
+ // type MigrationData = u32;
31
+
32
+ // fn __migrate(env: &Env, migration_data: &Self::MigrationData) {
33
+ // env.storage().instance().set(&Symbol::new(env, "counter2"), migration_data);
30
34
  // }
31
35
  // }
32
36
 
@@ -35,34 +39,37 @@ mod contract_v1 {
35
39
  // fn counter(env: &Env) -> u32;
36
40
  // }
37
41
 
38
- // #[contract_impl]
39
- // impl TestUpgradeable for TestUpgradeableContract {
42
+ // #[contractimpl]
43
+ // impl TestUpgradeable for DummyContract {
40
44
  // fn counter(env: &Env) -> u32 {
41
45
  // env.storage().instance().get(&Symbol::new(env, "counter")).unwrap_or(0)
42
46
  // }
43
47
  // }
44
48
 
45
- // #[contract_impl]
46
- // impl TestUpgradeableContract {
49
+ // #[contractimpl]
50
+ // impl DummyContract {
47
51
  // pub fn __constructor(env: &Env, owner: &Address) {
48
52
  // Self::init_owner(env, owner);
49
53
  // env.storage().instance().set(&Symbol::new(env, "counter"), &1_u32);
50
54
  // }
51
55
  // }
52
- use super::MigrationData;
53
56
  soroban_sdk::contractimport!(file = "./src/tests/test_data/test_upgradeable_contract1.wasm");
54
57
  }
55
58
  mod contract_v2 {
56
- // #[contract]
57
- // #[upgradeable]
58
- // #[ownable]
59
- // pub struct TestUpgradeableContract;
59
+ //#![no_std]
60
+
61
+ // use soroban_sdk::{contractimpl, Env, Symbol, Address, contractclient};
62
+ // use utils::{ upgradeable::UpgradeableInternal};
63
+ // use common_macros::lz_contract;
64
+
65
+ // #[lz_contract(upgradeable)]
66
+ // pub struct DummyContract;
60
67
 
61
- // impl UpgradeableInternal for TestUpgradeableContract {
62
- // type MigrationData = ();
68
+ // impl UpgradeableInternal for DummyContract {
69
+ // type MigrationData = u32;
63
70
 
64
- // fn _migrate(env: &Env, _migration_data: &Self::MigrationData) {
65
- // env.storage().instance().set(&Symbol::new(env, "counter2"), &2_u32);
71
+ // fn __migrate(env: &Env, migration_data: &Self::MigrationData) {
72
+ // env.storage().instance().set(&Symbol::new(env, "counter2"), migration_data);
66
73
  // }
67
74
  // }
68
75
 
@@ -72,8 +79,8 @@ mod contract_v2 {
72
79
  // fn counter2(env: &Env) -> u32;
73
80
  // }
74
81
 
75
- // #[contract_impl]
76
- // impl TestUpgradeable for TestUpgradeableContract {
82
+ // #[contractimpl]
83
+ // impl TestUpgradeable for DummyContract {
77
84
  // fn counter(env: &Env) -> u32 {
78
85
  // env.storage().instance().get(&Symbol::new(env, "counter")).unwrap_or(0)
79
86
  // }
@@ -82,7 +89,14 @@ mod contract_v2 {
82
89
  // env.storage().instance().get(&Symbol::new(env, "counter2")).unwrap_or(0)
83
90
  // }
84
91
  // }
85
- use super::MigrationData;
92
+
93
+ // #[contractimpl]
94
+ // impl DummyContract {
95
+ // pub fn __constructor(env: &Env, owner: &Address) {
96
+ // Self::init_owner(env, owner);
97
+ // env.storage().instance().set(&Symbol::new(env, "counter"), &1_u32);
98
+ // }
99
+ // }
86
100
  soroban_sdk::contractimport!(file = "./src/tests/test_data/test_upgradeable_contract2.wasm");
87
101
  }
88
102
 
@@ -90,9 +104,6 @@ fn install_new_wasm(e: &Env) -> BytesN<32> {
90
104
  e.deployer().upload_contract_wasm(contract_v2::WASM)
91
105
  }
92
106
 
93
- #[allow(dead_code)]
94
- type MigrationData = ();
95
-
96
107
  #[test]
97
108
  fn test_upgrade_with_upgrader() {
98
109
  let e = Env::default();
@@ -107,14 +118,12 @@ fn test_upgrade_with_upgrader() {
107
118
  let upgrader_client = UpgraderClient::new(&e, &upgrader);
108
119
 
109
120
  let new_wasm_hash = install_new_wasm(&e);
110
-
111
- upgrader_client.upgrade_and_migrate(
112
- &contract_id,
113
- &new_wasm_hash,
114
- &soroban_sdk::vec![&e, ().try_into_val(&e).unwrap()],
115
- );
121
+ let counter_value = 2_u32;
122
+ // Encode migration data as XDR bytes
123
+ let migration_data = counter_value.to_xdr(&e);
124
+ upgrader_client.upgrade_and_migrate(&contract_id, &new_wasm_hash, &migration_data);
116
125
 
117
126
  let client_v2 = TestUpgradeableContractClient2::new(&e, &contract_id);
118
127
 
119
- assert_eq!(client_v2.counter2(), 2);
128
+ assert_eq!(client_v2.counter2(), counter_value);
120
129
  }
@@ -92,6 +92,7 @@ impl<'a> BufferReader<'a> {
92
92
  value
93
93
  }
94
94
 
95
+ /// Reads all bytes from current position to the end of the buffer.
95
96
  pub fn read_bytes_until_end(&mut self) -> Bytes {
96
97
  self.read_bytes(self.remaining_len())
97
98
  }
@@ -44,7 +44,9 @@ pub enum BytesExtError {
44
44
  /// UpgradeableError: 1050-1059
45
45
  #[contract_error]
46
46
  pub enum UpgradeableError {
47
- MigrationNotAllowed = 1050,
47
+ InvalidMigrationData = 1050,
48
+ MigrationNotAllowed,
49
+ UpgradesFrozen,
48
50
  }
49
51
 
50
52
  /// MultisigError: 1060-1069