Skip to content

Commit

Permalink
chore: upgrade soroban-sdk version and rlp
Browse files Browse the repository at this point in the history
  • Loading branch information
bishalbikram committed Dec 29, 2024
1 parent 646fe69 commit 3ecba4e
Show file tree
Hide file tree
Showing 18 changed files with 278 additions and 979 deletions.
452 changes: 256 additions & 196 deletions contracts/soroban/Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions contracts/soroban/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[workspace]
resolver = "2"
members = [
"contracts/*",
"libs/*"
"contracts/*"
]

[workspace.dependencies]
soroban-sdk = "20.5.0"
soroban-sdk = "21.7.4"
soroban-rlp = { git = "http://github.com/icon-project/xcall-multi", branch = "main" }

[profile.release]
opt-level = "z"
Expand Down
2 changes: 1 addition & 1 deletion contracts/soroban/contracts/intent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ doctest = false

[dependencies]
soroban-sdk = { workspace = true }
soroban-rlp = { path = "../../libs/soroban-rlp" }
soroban-rlp = { workspace = true }

[dev-dependencies]
soroban-sdk = { workspace = true, features = ["testutils"] }
4 changes: 2 additions & 2 deletions contracts/soroban/contracts/intent/src/fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn fill_order(
sender.require_auth();

let order_bytes = order.encode(&env);
let order_hash = env.crypto().keccak256(&order_bytes);
let order_hash = helpers::hash_data(&env, &order_bytes);

if storage::order_finished(&env, &order_hash) {
return Err(ContractError::OrderAlreadyFilled);
Expand Down Expand Up @@ -50,7 +50,7 @@ pub fn fill_order(

pub fn resolve_fill(env: &Env, src_network: String, fill: OrderFill) -> Result<(), ContractError> {
let order = storage::get_order(&env, fill.id())?;
if order.get_hash(&env) != env.crypto().keccak256(&fill.order_bytes()) {
if order.get_hash(&env) != helpers::hash_data(&env, &fill.order_bytes()) {
return Err(ContractError::OrderMismatched);
}

Expand Down
6 changes: 5 additions & 1 deletion contracts/soroban/contracts/intent/src/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use soroban_sdk::{token, Address, Env};
use soroban_sdk::{token, Address, Bytes, BytesN, Env};

use crate::{error::ContractError, storage};

Expand All @@ -20,3 +20,7 @@ pub fn transfer_token(env: &Env, token: &Address, from: &Address, to: &Address,
let token_client = token::Client::new(&env, &token);
token_client.transfer(&from, &to, &(amount as i128));
}

pub fn hash_data(e: &Env, data: &Bytes) -> BytesN<32> {
e.crypto().keccak256(data).to_bytes()
}
8 changes: 4 additions & 4 deletions contracts/soroban/contracts/intent/src/test/cancel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use super::setup::TestContext;
use crate::{
contract::IntentClient,
event::{Message, OrderCancelled},
storage,
helpers, storage,
types::{Cancel, MessageType, OrderFill, OrderMessage},
};

Expand Down Expand Up @@ -125,7 +125,7 @@ fn test_resolve_cancel_in_same_source_and_destination_chain() {

ctx.env.as_contract(&ctx.contract, || {
let order_bytes = order.encode(&ctx.env);
let order_hash = ctx.env.crypto().keccak256(&order_bytes);
let order_hash = helpers::hash_data(&ctx.env, &order_bytes);
let filled_order = storage::order_finished(&ctx.env, &order_hash);
assert_eq!(filled_order, true);
});
Expand Down Expand Up @@ -168,7 +168,7 @@ fn test_resolve_cancel_with_invalid_network_id() {
let receipt = client.get_receipt(&src_network, &conn_sn);
assert_eq!(receipt, true);

let order_hash = ctx.env.crypto().keccak256(&order.encode(&ctx.env));
let order_hash = helpers::hash_data(&ctx.env, &order.encode(&ctx.env));
ctx.env.as_contract(&ctx.contract, || {
let filled_order = storage::order_finished(&ctx.env, &order_hash);
assert_eq!(filled_order, true)
Expand All @@ -182,7 +182,7 @@ fn test_resolve_cancel_for_already_filled_order() {
ctx.init_context(&client);

let order = ctx.get_dummy_swap(ctx.dst_nid.clone());
let order_hash = ctx.env.crypto().keccak256(&order.encode(&ctx.env));
let order_hash = helpers::hash_data(&ctx.env, &order.encode(&ctx.env));
ctx.env.as_contract(&ctx.contract, || {
storage::store_finished_order(&ctx.env, &order_hash);
});
Expand Down
6 changes: 3 additions & 3 deletions contracts/soroban/contracts/intent/src/test/fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use super::setup::TestContext;
use crate::{
contract::IntentClient,
event::{Message, OrderFilled},
storage,
helpers, storage,
types::{MessageType, OrderFill, OrderMessage},
};

Expand All @@ -24,7 +24,7 @@ fn test_fill_for_already_finished_order() {

ctx.env.as_contract(&ctx.contract, || {
let order_bytes = order.encode(&ctx.env);
let order_hash = ctx.env.crypto().keccak256(&order_bytes);
let order_hash = helpers::hash_data(&ctx.env, &order_bytes);
storage::store_finished_order(&ctx.env, &order_hash);
});

Expand Down Expand Up @@ -126,7 +126,7 @@ fn test_fill_order() {
]
);

let order_hash = ctx.env.crypto().keccak256(&order.encode(&ctx.env));
let order_hash = helpers::hash_data(&ctx.env, &order.encode(&ctx.env));
let finished_order = client.get_finished_order(&order_hash);
assert_eq!(finished_order, true);

Expand Down
4 changes: 2 additions & 2 deletions contracts/soroban/contracts/intent/src/test/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn test_swap_order_decode_1() {
900,
Bytes::new(&env),
);
let expected = bytes!(&env, 0xf900a601963078626536343532643464366336316365653937643388457468657265756d87506f6c79676f6e983078336533366564646436356532333932323265376536379c30786432633632313862383735343537613431623666623739363465a43078313433353533343065383537393132313838623766323032643535303232323438378203e89a307839316134373238623531373438346630663631306465376282038480);
let expected = bytes!(&env, 0xf8a601963078626536343532643464366336316365653937643388457468657265756d87506f6c79676f6e983078336533366564646436356532333932323265376536379c30786432633632313862383735343537613431623666623739363465a43078313433353533343065383537393132313838623766323032643535303232323438378203e89a307839316134373238623531373438346630663631306465376282038480);
assert_eq!(swap_order.encode(&env), expected)
}

Expand All @@ -99,6 +99,6 @@ fn test_swap_order_decode_2() {
900 * 10_u128.pow(7),
bytes!(&env, 0x6c449988e2f33302803c93f8287dc1d8cb33848a),
);
let expected = bytes!(&env, 0xf900c701963078626536343532643464366336316365653937643388457468657265756d87506f6c79676f6e983078336533366564646436356532333932323265376536379c30786432633632313862383735343537613431623666623739363465a43078313433353533343065383537393132313838623766323032643535303232323438378c033b2e3c9fd0803ce80000009a3078393161343732386235313734383466306636313064653762850218711a00946c449988e2f33302803c93f8287dc1d8cb33848a);
let expected = bytes!(&env, 0xf8c701963078626536343532643464366336316365653937643388457468657265756d87506f6c79676f6e983078336533366564646436356532333932323265376536379c30786432633632313862383735343537613431623666623739363465a43078313433353533343065383537393132313838623766323032643535303232323438378c033b2e3c9fd0803ce80000009a3078393161343732386235313734383466306636313064653762850218711a00946c449988e2f33302803c93f8287dc1d8cb33848a);
assert_eq!(swap_order.encode(&env), expected)
}
4 changes: 2 additions & 2 deletions contracts/soroban/contracts/intent/src/types/swap_order.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use soroban_sdk::{contracttype, vec, Bytes, BytesN, Env, String, Vec};
use soroban_rlp::{decoder, encoder};
use soroban_sdk::{contracttype, vec, Bytes, BytesN, Env, String, Vec};

#[contracttype]
#[derive(Debug, Clone, PartialEq)]
Expand Down Expand Up @@ -110,7 +110,7 @@ impl SwapOrder {
}

pub fn get_hash(&self, e: &Env) -> BytesN<32> {
e.crypto().keccak256(&self.encode(&e))
e.crypto().keccak256(&self.encode(&e)).to_bytes()
}

pub fn encode(&self, e: &Env) -> Bytes {
Expand Down
12 changes: 0 additions & 12 deletions contracts/soroban/libs/soroban-rlp/Cargo.toml

This file was deleted.

160 changes: 0 additions & 160 deletions contracts/soroban/libs/soroban-rlp/src/decoder.rs

This file was deleted.

Loading

0 comments on commit 3ecba4e

Please sign in to comment.