bobcat-interfaces 0.8.7

bobcat-sdk utilities for generating signautres on Arbitrum Stylus.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
use bobcat_maths::U;

use bobcat_cd::{leftpad_addr, leftpad_bool, rightpad_b8};

use crate::selectors;

use array_concat::concat_arrays;

type Address = [u8; 20];

selectors! {
    SEL_ORACLE = b"oracle()",
    SEL_MINT = b"mint8A059B6E(bytes8,uint256,address,address)",
    SEL_BURN = b"burn854CC96E(bytes8,uint256,bool,uint256,address,address)",
    SEL_QUOTE = b"quoteC0E17FC7(bytes8,uint256)",
    SEL_ESTIMATE_BURN = b"estimateBurnE9B09A17(bytes8,uint256)",
    SEL_CLAIM_ALL_FEES = b"claimAllFees332D7968(address)",
    SEL_ADD_LIQUIDITY = b"addLiquidityB9DDA952(uint256,address,uint256,uint256)",
    SEL_REMOVE_LIQUIDITY = b"removeLiquidity3C857A15(uint256,address)",
    SEL_PRICE = b"priceA827ED27(bytes8)",
    SEL_DECIDE = b"decide(bytes8)",
    SEL_PAYOFF = b"payoffCB6F2565(bytes8,uint256,address)",
    SEL_DETAILS = b"details(bytes8)",
    SEL_IS_DPM = b"isDpm()",
    SEL_IS_DPPM = b"isDppm()",
    SEL_GLOBAL_SHARES = b"globalShares()",
    SEL_INVESTED = b"invested()",
    SEL_TIME_ENDING = b"timeEnding()",
    SEL_TIME_START = b"timeStart()",
    SEL_SHARE_ADDR = b"shareAddr(bytes8)",
    SEL_FEES = b"fees62DAA154()",
    SEL_USER_LIQUIDITY_SHARES = b"userLiquidityShares(address)",
    SEL_OUTCOME_LIST = b"outcomeList()"
}

pub const fn make_fn_mint(
    outcome: [u8; 8],
    value: U,
    referrer: Address,
    recipient: Address,
) -> [u8; 4 + 32 * 4] {
    concat_arrays!(
        SEL_MINT,
        rightpad_b8(outcome),
        value.0,
        leftpad_addr(referrer),
        leftpad_addr(recipient)
    )
}

pub const fn make_fn_burn(
    outcome: [u8; 8],
    amount: U,
    should_estimate_shares: bool,
    min_shares: U,
    referrer: Address,
    recipient: Address,
) -> [u8; 4 + 32 * 6] {
    concat_arrays!(
        SEL_BURN,
        rightpad_b8(outcome),
        amount.0,
        leftpad_bool(should_estimate_shares),
        min_shares.0,
        leftpad_addr(referrer),
        leftpad_addr(recipient)
    )
}

pub const fn make_fn_quote(outcome: [u8; 8], fusdc_value: U) -> [u8; 4 + 32 * 2] {
    concat_arrays!(SEL_QUOTE, rightpad_b8(outcome), fusdc_value.0)
}

pub const fn make_fn_estimate_burn(outcome: [u8; 8], share_amount: U) -> [u8; 4 + 32 * 2] {
    concat_arrays!(SEL_ESTIMATE_BURN, rightpad_b8(outcome), share_amount.0)
}

pub const fn make_fn_claim_all_fees(recipient: Address) -> [u8; 4 + 32] {
    concat_arrays!(SEL_CLAIM_ALL_FEES, leftpad_addr(recipient))
}

pub const fn make_fn_add_liquidity(
    liquidity: U,
    recipient: Address,
    min_shares: U,
    max_shares: U,
) -> [u8; 4 + 32 * 4] {
    concat_arrays!(
        SEL_ADD_LIQUIDITY,
        liquidity.0,
        leftpad_addr(recipient),
        min_shares.0,
        max_shares.0
    )
}

pub const fn make_fn_remove_liquidity(liquidity: U, recipient: Address) -> [u8; 4 + 32 * 2] {
    concat_arrays!(SEL_REMOVE_LIQUIDITY, liquidity.0, leftpad_addr(recipient))
}

pub const fn make_fn_price(outcome: [u8; 8]) -> [u8; 4 + 32] {
    concat_arrays!(SEL_PRICE, rightpad_b8(outcome))
}

pub const fn make_fn_decide(outcome: [u8; 8]) -> [u8; 4 + 32] {
    concat_arrays!(SEL_DECIDE, rightpad_b8(outcome))
}

pub const fn make_fn_payoff(
    outcome_id: [u8; 8],
    amount: U,
    recipient: Address,
) -> [u8; 4 + 32 * 3] {
    concat_arrays!(
        SEL_PAYOFF,
        rightpad_b8(outcome_id),
        amount.0,
        leftpad_addr(recipient)
    )
}

pub const fn make_fn_details(outcome_id: [u8; 8]) -> [u8; 4 + 32] {
    concat_arrays!(SEL_DETAILS, rightpad_b8(outcome_id))
}

pub const fn make_fn_is_dpm() -> [u8; 4] {
    SEL_IS_DPM
}

pub const fn make_fn_is_dppm() -> [u8; 4] {
    SEL_IS_DPPM
}

pub const fn make_fn_global_shares() -> [u8; 4] {
    SEL_GLOBAL_SHARES
}

pub const fn make_fn_invested() -> [u8; 4] {
    SEL_INVESTED
}

pub const fn make_fn_time_ending() -> [u8; 4] {
    SEL_TIME_ENDING
}

pub const fn make_fn_time_start() -> [u8; 4] {
    SEL_TIME_START
}

pub const fn make_fn_share_addr(outcome_id: [u8; 8]) -> [u8; 4 + 32] {
    concat_arrays!(SEL_SHARE_ADDR, rightpad_b8(outcome_id))
}

pub const fn make_fn_fees() -> [u8; 4] {
    SEL_FEES
}

pub const fn make_fn_user_liquidity_shares(spender: Address) -> [u8; 4 + 32] {
    concat_arrays!(SEL_USER_LIQUIDITY_SHARES, leftpad_addr(spender))
}

pub const fn make_fn_outcome_list() -> [u8; 4] {
    SEL_OUTCOME_LIST
}

pub const fn make_fn_oracle() -> [u8; 4] {
    SEL_ORACLE
}

#[cfg(all(test, not(target_arch = "wasm32")))]
mod test {
    use super::*;

    use alloy_sol_macro::sol;

    use proptest::prelude::*;

    use alloy_primitives::{Address as AAddress, FixedBytes, U256 as AU};

    use alloy_sol_types::SolCall;

    sol! {
            function oracle() external view returns (address);

            function mint8A059B6E(
                bytes8 outcome,
                uint256 value,
                address referrer,
                address recipient
            ) external returns (uint256);

            function burn854CC96E(
                bytes8 outcome,
                uint256 amount,
                bool shouldEstimateShares,
                uint256 minShares,
                address referrer,
                address recipient
            ) external returns (uint256 burnedShares, uint256 fusdcReturned);

            function quoteC0E17FC7(
                bytes8 outcome,
                uint256 fusdcValue
            ) external returns (uint256 purchased, uint256 fees);

            function estimateBurnE9B09A17(
                bytes8 outcome,
                uint256 shareAmount
            ) external returns (uint256);

            function claimAllFees332D7968(address recipient) external returns (uint256);

            function addLiquidityB9DDA952(
                uint256 liquidity,
                address recipient,
                uint256 minShares,
                uint256 maxShares
            ) external returns (
                uint256 userLiquidity
            );

            function removeLiquidity3C857A15(uint256 liquidity, address recipient) external returns (
                uint256 fusdcAmount,
                uint256 lpFeesEarned
            );

            function priceA827ED27(bytes8 outcome) external returns (uint256);

            function decide(bytes8 outcome) external;

            function payoffCB6F2565(
                bytes8 outcomeId,
                uint256 amount,
                address recipient
            ) external returns (uint256);

            function details(bytes8 outcomeId) external view returns (
                uint256 shares,
                uint256 invested,
                uint256 globalInvested,
                bytes8 winner
            );

            function isDpm() external pure returns (bool);

            function isDppm() external pure returns (bool);

            function globalShares() external view returns (uint256);

            function invested() external view returns (uint256);

            function timeEnding() external view returns (uint64);

            function timeStart() external view returns (uint64);

            function shareAddr(bytes8 outcomeId) external view returns (address);

            struct Fees {
                uint256 feeCreator;
                uint256 feeMinter;
                uint256 feeLp;
                uint256 feeReferrer;
            }

            function version() external pure returns (string memory);

            function fees62DAA154() external view returns (Fees memory);

            function userLiquidityShares(address spender) external view returns (uint256);

            function outcomeList() external view returns (bytes8[] memory outcomes);
    }

    proptest! {
        #[test]
        fn test_mint_encoding(
            outcome in any::<[u8; 8]>(),
            value in any::<U>(),
            referrer in any::<Address>(),
            recipient in any::<Address>()
        ) {
            let v = make_fn_mint(outcome, value, referrer, recipient).to_vec();
            let exp = mint8A059B6ECall {
                outcome: FixedBytes::from(outcome),
                value: AU::from_be_bytes(*value),
                referrer: AAddress::from(referrer),
                recipient: AAddress::from(recipient),
            }.abi_encode();
            assert_eq!(
                exp,
                v,
                "{} != {}",
                const_hex::encode(exp.clone()), const_hex::encode(v.clone())
            );
        }

        #[test]
        fn test_burn_encoding(
            outcome in any::<[u8; 8]>(),
            amount in any::<U>(),
            should_estimate_shares in any::<bool>(),
            min_shares in any::<U>(),
            referrer in any::<Address>(),
            recipient in any::<Address>()
        ) {
            let v = make_fn_burn(
                outcome,
                amount,
                should_estimate_shares,
                min_shares,
                referrer,
                recipient
            ).to_vec();
            let exp = burn854CC96ECall {
                outcome: FixedBytes::from(outcome),
                amount: AU::from_be_bytes(*amount),
                shouldEstimateShares: should_estimate_shares,
                minShares: AU::from_be_bytes(*min_shares),
                referrer: AAddress::from(referrer),
                recipient: AAddress::from(recipient),
            }.abi_encode();
            assert_eq!(exp, v, "{} != {}", const_hex::encode(exp.clone()), const_hex::encode(v.clone()));
        }

        #[test]
        fn test_quote_encoding(
            outcome in any::<[u8; 8]>(),
            fusdc_value in any::<U>()
        ) {
            let v = make_fn_quote(outcome, fusdc_value).to_vec();
            let exp = quoteC0E17FC7Call {
                outcome: FixedBytes::from(outcome),
                fusdcValue: AU::from_be_bytes(*fusdc_value),
            }.abi_encode();
            assert_eq!(exp, v, "{} != {}", const_hex::encode(exp.clone()), const_hex::encode(v.clone()));
        }

        #[test]
        fn test_estimate_burn_encoding(
            outcome in any::<[u8; 8]>(),
            share_amount in any::<U>()
        ) {
            let v = make_fn_estimate_burn(outcome, share_amount).to_vec();
            let exp = estimateBurnE9B09A17Call {
                outcome: FixedBytes::from(outcome),
                shareAmount: AU::from_be_bytes(*share_amount),
            }.abi_encode();
            assert_eq!(exp, v, "{} != {}", const_hex::encode(exp.clone()), const_hex::encode(v.clone()));
        }

        #[test]
        fn test_claim_all_fees_encoding(
            recipient in any::<Address>()
        ) {
            let v = make_fn_claim_all_fees(recipient).to_vec();
            let exp = claimAllFees332D7968Call {
                recipient: AAddress::from(recipient),
            }.abi_encode();
            assert_eq!(exp, v, "{} != {}", const_hex::encode(exp.clone()), const_hex::encode(v.clone()));
        }

        #[test]
        fn test_add_liquidity_encoding(
            liquidity in any::<U>(),
            recipient in any::<Address>(),
            min_shares in any::<U>(),
            max_shares in any::<U>()
        ) {
            let v = make_fn_add_liquidity(liquidity, recipient, min_shares, max_shares).to_vec();
            let exp = addLiquidityB9DDA952Call {
                liquidity: AU::from_be_bytes(*liquidity),
                recipient: AAddress::from(recipient),
                minShares: AU::from_be_bytes(*min_shares),
                maxShares: AU::from_be_bytes(*max_shares),
            }.abi_encode();
            assert_eq!(exp, v, "{} != {}", const_hex::encode(exp.clone()), const_hex::encode(v.clone()));
        }

        #[test]
        fn test_remove_liquidity_encoding(
            liquidity in any::<U>(),
            recipient in any::<Address>()
        ) {
            let v = make_fn_remove_liquidity(liquidity, recipient).to_vec();
            let exp = removeLiquidity3C857A15Call {
                liquidity: AU::from_be_bytes(*liquidity),
                recipient: AAddress::from(recipient),
            }.abi_encode();
            assert_eq!(exp, v, "{} != {}", const_hex::encode(exp.clone()), const_hex::encode(v.clone()));
        }

        #[test]
        fn test_price_encoding(outcome in any::<[u8; 8]>()) {
            let v = make_fn_price(outcome).to_vec();
            let exp = priceA827ED27Call {
                outcome: FixedBytes::from(outcome),
            }.abi_encode();
            assert_eq!(exp, v, "{} != {}", const_hex::encode(exp.clone()), const_hex::encode(v.clone()));
        }

        #[test]
        fn test_decide_encoding(outcome in any::<[u8; 8]>()) {
            let v = make_fn_decide(outcome).to_vec();
            let exp = decideCall {
                outcome: FixedBytes::from(outcome),
            }.abi_encode();
            assert_eq!(exp, v, "{} != {}", const_hex::encode(exp.clone()), const_hex::encode(v.clone()));
        }

        #[test]
        fn test_payoff_encoding(
            outcome_id in any::<[u8; 8]>(),
            amount in any::<U>(),
            recipient in any::<Address>()
        ) {
            let v = make_fn_payoff(outcome_id, amount, recipient).to_vec();
            let exp = payoffCB6F2565Call {
                outcomeId: FixedBytes::from(outcome_id),
                amount: AU::from_be_bytes(*amount),
                recipient: AAddress::from(recipient),
            }.abi_encode();
            assert_eq!(exp, v, "{} != {}", const_hex::encode(exp.clone()), const_hex::encode(v.clone()));
        }

        #[test]
        fn test_details_encoding(
            outcome_id in any::<[u8; 8]>()
        ) {
            let v = make_fn_details(outcome_id).to_vec();
            let exp = detailsCall {
                outcomeId: FixedBytes::from(outcome_id),
            }.abi_encode();
            assert_eq!(exp, v, "{} != {}", const_hex::encode(exp.clone()), const_hex::encode(v.clone()));
        }

        #[test]
        fn test_share_addr_encoding(
            outcome_id in any::<[u8; 8]>()
        ) {
            let v = make_fn_share_addr(outcome_id).to_vec();
            let exp = shareAddrCall {
                outcomeId: FixedBytes::from(outcome_id),
            }.abi_encode();
            assert_eq!(exp, v, "{} != {}", const_hex::encode(exp.clone()), const_hex::encode(v.clone()));
        }

        #[test]
        fn test_user_liquidity_shares_encoding(
            spender in any::<Address>()
        ) {
            let v = make_fn_user_liquidity_shares(spender).to_vec();
            let exp = userLiquiditySharesCall {
                spender: AAddress::from(spender),
            }.abi_encode();
            assert_eq!(exp, v, "{} != {}", const_hex::encode(exp.clone()), const_hex::encode(v.clone()));
        }
    }
}