Skip to content
This repository was archived by the owner on May 11, 2026. It is now read-only.

Commit 96f1889

Browse files
committed
includes negative risk redemption function
1 parent 10d0a32 commit 96f1889

2 files changed

Lines changed: 53 additions & 3 deletions

File tree

components/Trading/Positions/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ export default function UserPositions() {
109109
await redeemPosition(relayClient, {
110110
conditionId: position.conditionId,
111111
outcomeIndex: position.outcomeIndex,
112+
negativeRisk: position.negativeRisk,
113+
size: position.size,
112114
});
113115

114116
queryClient.invalidateQueries({ queryKey: ["polymarket-positions"] });

utils/redeem.ts

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { encodeFunctionData } from "viem";
66
import {
77
USDC_E_CONTRACT_ADDRESS,
88
CTF_CONTRACT_ADDRESS,
9+
NEG_RISK_ADAPTER_ADDRESS,
910
} from "@/constants/tokens";
1011

1112
const 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+
2640
export interface RedeemParams {
2741
conditionId: string;
2842
outcomeIndex: number;
43+
negativeRisk?: boolean;
44+
size?: number;
2945
}
3046

3147
export 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

Comments
 (0)