MCPcopy Create free account
hub / github.com/cowprotocol/services / encode_trade

Function encode_trade

crates/simulator/src/encoding.rs:154–177  ·  view source on GitHub ↗

Creates the data which the smart contract's `decodeTrade` expects.

(
    order: &OrderData,
    signature: &Signature,
    owner: Address,
    sell_token_index: usize,
    buy_token_index: usize,
    executed_amount: U256,
)

Source from the content-addressed store, hash-verified

152
153/// Creates the data which the smart contract's `decodeTrade` expects.
154pub fn encode_trade(
155 order: &OrderData,
156 signature: &Signature,
157 owner: Address,
158 sell_token_index: usize,
159 buy_token_index: usize,
160 executed_amount: U256,
161) -> EncodedTrade {
162 (
163 U256::from(sell_token_index),
164 U256::from(buy_token_index),
165 // Use the actual raw bytes that got signed by the owner intead of the
166 // resolved address to make the signature recovery work in the contract.
167 Address::from(*order.receiver.raw_bytes()),
168 order.sell_amount,
169 order.buy_amount,
170 order.valid_to,
171 B256::new(order.app_data.0),
172 order.fee_amount,
173 order_flags(order, signature),
174 executed_amount,
175 Bytes::from(signature.encode_for_settlement(owner)),
176 )
177}
178
179fn order_flags(order: &OrderData, signature: &Signature) -> U256 {
180 let mut result = 0u8;

Callers 1

Calls 4

order_flagsFunction · 0.85
raw_bytesMethod · 0.80
encode_for_settlementMethod · 0.80
newFunction · 0.50

Tested by

no test coverage detected