@@ -6,6 +6,7 @@ import { encodeFunctionData } from "viem";
66import {
77 USDC_E_CONTRACT_ADDRESS ,
88 CTF_CONTRACT_ADDRESS ,
9+ NEG_RISK_ADAPTER_ADDRESS ,
910} from "@/constants/tokens" ;
1011
1112const ctfAbi = [
@@ -23,20 +24,67 @@ const ctfAbi = [
2324 } ,
2425] as const ;
2526
27+ const negRiskAdapterAbi = [
28+ {
29+ inputs : [
30+ { name : "conditionId" , type : "bytes32" } ,
31+ { name : "amounts" , type : "uint256[]" } ,
32+ ] ,
33+ name : "redeemPositions" ,
34+ outputs : [ ] ,
35+ stateMutability : "nonpayable" ,
36+ type : "function" ,
37+ } ,
38+ ] as const ;
39+
2640export interface RedeemParams {
2741 conditionId : string ;
2842 outcomeIndex : number ;
43+ negativeRisk ?: boolean ;
44+ size ?: number ;
2945}
3046
3147export const createRedeemTx = ( params : RedeemParams ) : SafeTransaction => {
32- const { conditionId, outcomeIndex } = params ;
48+ const { conditionId, outcomeIndex, negativeRisk = false , size = 0 } = params ;
49+
50+ if ( negativeRisk ) {
51+ const tokenAmount = BigInt ( Math . floor ( size * 1e6 ) ) ;
52+
53+ const amounts : bigint [ ] = [ BigInt ( 0 ) , BigInt ( 0 ) ] ;
54+ amounts [ outcomeIndex ] = tokenAmount ;
55+
56+ console . log ( "Creating NegRisk redeem tx:" , {
57+ conditionId,
58+ outcomeIndex,
59+ size,
60+ tokenAmount : tokenAmount . toString ( ) ,
61+ amounts : amounts . map ( ( a ) => a . toString ( ) ) ,
62+ } ) ;
63+
64+ const data = encodeFunctionData ( {
65+ abi : negRiskAdapterAbi ,
66+ functionName : "redeemPositions" ,
67+ args : [ conditionId as `0x${string } `, amounts ] ,
68+ } ) ;
69+
70+ return {
71+ to : NEG_RISK_ADAPTER_ADDRESS ,
72+ operation : OperationType . Call ,
73+ data,
74+ value : "0" ,
75+ } ;
76+ }
3377
34- // For simple binary outcomes, parentCollectionId is empty
3578 const parentCollectionId = "0x" + "0" . repeat ( 64 ) ;
3679
37- // indexSets array for the specific outcome
3880 const indexSet = BigInt ( 1 << outcomeIndex ) ;
3981
82+ console . log ( "Creating regular CTF redeem tx:" , {
83+ conditionId,
84+ outcomeIndex,
85+ indexSet : indexSet . toString ( ) ,
86+ } ) ;
87+
4088 const data = encodeFunctionData ( {
4189 abi : ctfAbi ,
4290 functionName : "redeemPositions" ,
0 commit comments