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

Function encode_trade

crates/simulator/src/encoding.rs:153–174  ·  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

151
152/// Creates the data which the smart contract's `decodeTrade` expects.
153pub fn encode_trade(
154 order: &OrderData,
155 signature: &Signature,
156 owner: Address,
157 sell_token_index: usize,
158 buy_token_index: usize,
159 executed_amount: U256,
160) -> EncodedTrade {
161 (
162 U256::from(sell_token_index),
163 U256::from(buy_token_index),
164 order.receiver.unwrap_or(Address::ZERO),
165 order.sell_amount,
166 order.buy_amount,
167 order.valid_to,
168 B256::new(order.app_data.0),
169 order.fee_amount,
170 order_flags(order, signature),
171 executed_amount,
172 Bytes::from(signature.encode_for_settlement(owner)),
173 )
174}
175
176fn order_flags(order: &OrderData, signature: &Signature) -> U256 {
177 let mut result = 0u8;

Callers 2

encodeMethod · 0.85

Calls 3

order_flagsFunction · 0.85
encode_for_settlementMethod · 0.80
newFunction · 0.50

Tested by

no test coverage detected