@provable-games/budokan-sdk 0.1.21 → 0.1.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1125,6 +1125,84 @@ async function viewerPrizes(contract, tournamentId) {
1125
1125
  return result.map(parsePrize);
1126
1126
  }, contract.address);
1127
1127
  }
1128
+ function translateCairoRewardType(rewardType) {
1129
+ if (!rewardType || typeof rewardType !== "object") {
1130
+ throw new Error(`Unexpected RewardType payload: ${JSON.stringify(rewardType)}`);
1131
+ }
1132
+ const rt = rewardType;
1133
+ const outer = typeof rt.activeVariant === "function" ? rt.activeVariant() : null;
1134
+ const innerBag = typeof rt.activeVariant === "function" ? rt.variant : rt;
1135
+ if (outer === "Prize" || innerBag.Prize !== void 0) {
1136
+ const prize = innerBag.Prize;
1137
+ const subVariant = typeof prize?.activeVariant === "function" ? prize.activeVariant() : null;
1138
+ const subBag = typeof prize?.activeVariant === "function" ? prize.variant : prize;
1139
+ if (subVariant === "Single" || subBag?.Single !== void 0) {
1140
+ return {
1141
+ claimKind: "prize_single",
1142
+ prizeId: BigInt(subBag.Single).toString(),
1143
+ payoutIndex: null,
1144
+ position: null,
1145
+ refundTokenId: null
1146
+ };
1147
+ }
1148
+ if (subVariant === "Distributed" || subBag?.Distributed !== void 0) {
1149
+ const distributed = subBag.Distributed;
1150
+ const prizeId = distributed?.["0"] ?? distributed?.[0];
1151
+ const payoutIndex = distributed?.["1"] ?? distributed?.[1];
1152
+ return {
1153
+ claimKind: "prize_distributed",
1154
+ prizeId: BigInt(prizeId).toString(),
1155
+ payoutIndex: Number(payoutIndex),
1156
+ position: null,
1157
+ refundTokenId: null
1158
+ };
1159
+ }
1160
+ }
1161
+ if (outer === "EntryFee" || innerBag.EntryFee !== void 0) {
1162
+ const entryFee = innerBag.EntryFee;
1163
+ const subVariant = typeof entryFee?.activeVariant === "function" ? entryFee.activeVariant() : null;
1164
+ const subBag = typeof entryFee?.activeVariant === "function" ? entryFee.variant : entryFee;
1165
+ if (subVariant === "Position" || subBag?.Position !== void 0) {
1166
+ return {
1167
+ claimKind: "entry_fee_position",
1168
+ prizeId: null,
1169
+ payoutIndex: null,
1170
+ position: Number(subBag.Position),
1171
+ refundTokenId: null
1172
+ };
1173
+ }
1174
+ if (subVariant === "TournamentCreator" || subBag?.TournamentCreator !== void 0) {
1175
+ return {
1176
+ claimKind: "entry_fee_tournament_creator",
1177
+ prizeId: null,
1178
+ payoutIndex: null,
1179
+ position: null,
1180
+ refundTokenId: null
1181
+ };
1182
+ }
1183
+ if (subVariant === "GameCreator" || subBag?.GameCreator !== void 0) {
1184
+ return {
1185
+ claimKind: "entry_fee_game_creator",
1186
+ prizeId: null,
1187
+ payoutIndex: null,
1188
+ position: null,
1189
+ refundTokenId: null
1190
+ };
1191
+ }
1192
+ if (subVariant === "Refund" || subBag?.Refund !== void 0) {
1193
+ return {
1194
+ claimKind: "entry_fee_refund",
1195
+ prizeId: null,
1196
+ payoutIndex: null,
1197
+ position: null,
1198
+ refundTokenId: `0x${BigInt(subBag.Refund).toString(16)}`
1199
+ };
1200
+ }
1201
+ }
1202
+ throw new Error(
1203
+ `Unrecognised on-chain RewardType variant: ${JSON.stringify(rewardType)}`
1204
+ );
1205
+ }
1128
1206
  async function viewerRewardClaims(contract, tournamentId, offset, limit) {
1129
1207
  return wrapRpcCall(async () => {
1130
1208
  const result = await contract.call("tournament_reward_claims", [tournamentId, offset, limit]);
@@ -1132,7 +1210,7 @@ async function viewerRewardClaims(contract, tournamentId, offset, limit) {
1132
1210
  const claims = obj.claims?.map((raw) => {
1133
1211
  const claim = raw;
1134
1212
  return {
1135
- rewardType: claim.reward_type,
1213
+ ...translateCairoRewardType(claim.reward_type),
1136
1214
  claimed: Boolean(claim.claimed)
1137
1215
  };
1138
1216
  }) ?? [];
@@ -4529,8 +4607,7 @@ var BudokanClient = class {
4529
4607
  const result = await viewerRewardClaims(contract, tournamentId, offset, limit);
4530
4608
  const data = result.claims.map((c) => ({
4531
4609
  tournamentId,
4532
- rewardType: c.rewardType,
4533
- claimed: c.claimed
4610
+ ...c
4534
4611
  }));
4535
4612
  return { data, total: result.total, limit, offset };
4536
4613
  };