@0xslots/sdk 0.11.1 → 0.13.0

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.
@@ -1,7 +1,7 @@
1
1
  import gql from 'graphql-tag';
2
- import { metadataModuleAbi, getSlotsHubAddress, slotAbi, slotFactoryAbi } from '@0xslots/contracts';
2
+ import { metadataModuleAbi, feedRouterAddress, feedModuleAbi, slotAbi, feedRouterAbi, getSlotsHubAddress, slotFactoryAbi } from '@0xslots/contracts';
3
+ import { erc20Abi, encodeFunctionData } from 'viem';
3
4
  import { gql as gql$1, GraphQLClient } from 'graphql-request';
4
- import { encodeFunctionData, erc20Abi } from 'viem';
5
5
 
6
6
  // src/errors.ts
7
7
  var SlotsError = class extends Error {
@@ -740,12 +740,13 @@ var GetModulesDocument = gql`
740
740
  }
741
741
  `;
742
742
  var GetMetadataSlotsDocument = gql`
743
- query GetMetadataSlots($first: Int = 100, $skip: Int = 0, $orderBy: MetadataSlot_orderBy = updatedAt, $orderDirection: OrderDirection = desc) {
743
+ query GetMetadataSlots($first: Int = 100, $skip: Int = 0, $orderBy: MetadataSlot_orderBy = updatedAt, $orderDirection: OrderDirection = desc, $where: MetadataSlot_filter) {
744
744
  metadataSlots(
745
745
  first: $first
746
746
  skip: $skip
747
747
  orderBy: $orderBy
748
748
  orderDirection: $orderDirection
749
+ where: $where
749
750
  ) {
750
751
  ...MetadataSlotFields
751
752
  }
@@ -771,12 +772,13 @@ var GetMetadataSlotsByRecipientDocument = gql`
771
772
  }
772
773
  ${MetadataSlotFieldsFragmentDoc}`;
773
774
  var GetMetadataUpdatedEventsDocument = gql`
774
- query GetMetadataUpdatedEvents($slot: String, $first: Int = 50, $orderBy: MetadataUpdatedEvent_orderBy = timestamp, $orderDirection: OrderDirection = desc) {
775
+ query GetMetadataUpdatedEvents($first: Int = 50, $skip: Int = 0, $orderBy: MetadataUpdatedEvent_orderBy = timestamp, $orderDirection: OrderDirection = desc, $where: MetadataUpdatedEvent_filter) {
775
776
  metadataUpdatedEvents(
776
777
  first: $first
777
- where: {slot: $slot}
778
+ skip: $skip
778
779
  orderBy: $orderBy
779
780
  orderDirection: $orderDirection
781
+ where: $where
780
782
  ) {
781
783
  id
782
784
  slot {
@@ -1045,6 +1047,189 @@ var MetadataModuleClient = class {
1045
1047
  });
1046
1048
  }
1047
1049
  };
1050
+ var EXPECTED_MODULE_NAME2 = "FeedPostModule";
1051
+ var FeedModuleClient = class {
1052
+ constructor(opts) {
1053
+ this.sdk = opts.sdk;
1054
+ this.chainId = opts.chainId;
1055
+ this._publicClient = opts.publicClient;
1056
+ this._walletClient = opts.walletClient;
1057
+ }
1058
+ get wallet() {
1059
+ if (!this._walletClient)
1060
+ throw new SlotsError("feed", "No walletClient provided");
1061
+ return this._walletClient;
1062
+ }
1063
+ get account() {
1064
+ const account = this.wallet.account;
1065
+ if (!account)
1066
+ throw new SlotsError("feed", "WalletClient must have an account");
1067
+ return account.address;
1068
+ }
1069
+ get chain() {
1070
+ const chain = this.wallet.chain;
1071
+ if (!chain)
1072
+ throw new SlotsError("feed", "WalletClient must have a chain");
1073
+ return chain;
1074
+ }
1075
+ get publicClient() {
1076
+ if (!this._publicClient)
1077
+ throw new SlotsError("feed", "No publicClient provided");
1078
+ return this._publicClient;
1079
+ }
1080
+ get routerAddress() {
1081
+ const addr = feedRouterAddress[this.chainId];
1082
+ if (!addr)
1083
+ throw new SlotsError("feed", `No FeedRouter for chain ${this.chainId}`);
1084
+ return addr;
1085
+ }
1086
+ async query(operation, fn) {
1087
+ try {
1088
+ return await fn();
1089
+ } catch (error) {
1090
+ throw new SlotsError(operation, error);
1091
+ }
1092
+ }
1093
+ /**
1094
+ * Verify that a given address is a FeedPostModule by calling `name()` on-chain.
1095
+ */
1096
+ async verifyModule(moduleAddress) {
1097
+ const name = await this.publicClient.readContract({
1098
+ address: moduleAddress,
1099
+ abi: feedModuleAbi,
1100
+ functionName: "name"
1101
+ });
1102
+ if (name !== EXPECTED_MODULE_NAME2) {
1103
+ throw new SlotsError(
1104
+ "feed",
1105
+ `Contract at ${moduleAddress} is not a FeedPostModule (name: "${name}")`
1106
+ );
1107
+ }
1108
+ }
1109
+ // ═══════════════════════════════════════════════════════════════════════════
1110
+ // READ — Subgraph (reuses MetadataSlot entities)
1111
+ // ═══════════════════════════════════════════════════════════════════════════
1112
+ /** Get all slots with metadata, ordered by most recently updated. */
1113
+ getSlots(...args) {
1114
+ return this.query(
1115
+ "feed.getSlots",
1116
+ () => this.sdk.GetMetadataSlots(...args)
1117
+ );
1118
+ }
1119
+ /** Get a single metadata slot by slot address. */
1120
+ getSlot(...args) {
1121
+ return this.query(
1122
+ "feed.getSlot",
1123
+ () => this.sdk.GetMetadataSlot(...args)
1124
+ );
1125
+ }
1126
+ /** Get metadata update history for a slot. */
1127
+ getUpdateHistory(...args) {
1128
+ return this.query(
1129
+ "feed.getUpdateHistory",
1130
+ () => this.sdk.GetMetadataUpdatedEvents(...args)
1131
+ );
1132
+ }
1133
+ // ═══════════════════════════════════════════════════════════════════════════
1134
+ // READ — RPC
1135
+ // ═══════════════════════════════════════════════════════════════════════════
1136
+ /**
1137
+ * Read the current URI for a slot directly from chain.
1138
+ */
1139
+ async getURI(moduleAddress, slot) {
1140
+ return this.query(
1141
+ "feed.getURI",
1142
+ () => this.publicClient.readContract({
1143
+ address: moduleAddress,
1144
+ abi: feedModuleAbi,
1145
+ functionName: "tokenURI",
1146
+ args: [slot]
1147
+ })
1148
+ );
1149
+ }
1150
+ // ═══════════════════════════════════════════════════════════════════════════
1151
+ // WRITE — Direct (occupant only)
1152
+ // ═══════════════════════════════════════════════════════════════════════════
1153
+ /**
1154
+ * Update the metadata URI for a slot. Only callable by the current occupant.
1155
+ */
1156
+ async updateMetadata(moduleAddress, slot, uri) {
1157
+ await this.verifyModule(moduleAddress);
1158
+ return this.wallet.writeContract({
1159
+ address: moduleAddress,
1160
+ abi: feedModuleAbi,
1161
+ functionName: "updateMetadata",
1162
+ args: [slot, uri],
1163
+ account: this.account,
1164
+ chain: this.chain
1165
+ });
1166
+ }
1167
+ // ═══════════════════════════════════════════════════════════════════════════
1168
+ // WRITE — Router (atomic buy + post)
1169
+ // ═══════════════════════════════════════════════════════════════════════════
1170
+ /**
1171
+ * Buy a slot and post metadata in one transaction via FeedRouter.
1172
+ * User must approve the router for the slot's currency.
1173
+ * Handles ERC-20 approval automatically.
1174
+ *
1175
+ * @param slot - The slot contract address
1176
+ * @param depositAmount - Amount to deposit for tax escrow
1177
+ * @param selfAssessedPrice - The price you're setting
1178
+ * @param uri - The metadata URI to post
1179
+ * @returns Transaction hash
1180
+ */
1181
+ async buyAndPost(slot, depositAmount, selfAssessedPrice, uri) {
1182
+ const router = this.routerAddress;
1183
+ const [occupant, currentPrice, currency] = await Promise.all([
1184
+ this.publicClient.readContract({
1185
+ address: slot,
1186
+ abi: slotAbi,
1187
+ functionName: "occupant"
1188
+ }),
1189
+ this.publicClient.readContract({
1190
+ address: slot,
1191
+ abi: slotAbi,
1192
+ functionName: "price"
1193
+ }),
1194
+ this.publicClient.readContract({
1195
+ address: slot,
1196
+ abi: slotAbi,
1197
+ functionName: "currency"
1198
+ })
1199
+ ]);
1200
+ const price = occupant !== "0x0000000000000000000000000000000000000000" ? currentPrice : 0n;
1201
+ const total = price + depositAmount;
1202
+ if (total > 0n) {
1203
+ const allowance = await this.publicClient.readContract({
1204
+ address: currency,
1205
+ abi: erc20Abi,
1206
+ functionName: "allowance",
1207
+ args: [this.account, router]
1208
+ });
1209
+ if (allowance < total) {
1210
+ const approveTx = await this.wallet.writeContract({
1211
+ address: currency,
1212
+ abi: erc20Abi,
1213
+ functionName: "approve",
1214
+ args: [router, total],
1215
+ account: this.account,
1216
+ chain: this.chain
1217
+ });
1218
+ await this.publicClient.waitForTransactionReceipt({
1219
+ hash: approveTx
1220
+ });
1221
+ }
1222
+ }
1223
+ return this.wallet.writeContract({
1224
+ address: router,
1225
+ abi: feedRouterAbi,
1226
+ functionName: "buyAndPost",
1227
+ args: [slot, depositAmount, selfAssessedPrice, uri],
1228
+ account: this.account,
1229
+ chain: this.chain
1230
+ });
1231
+ }
1232
+ };
1048
1233
  var META_QUERY = gql$1`
1049
1234
  query GetMeta {
1050
1235
  _meta {
@@ -1085,6 +1270,12 @@ var SlotsClient = class {
1085
1270
  sdk: this.sdk,
1086
1271
  publicClient: config.publicClient,
1087
1272
  walletClient: config.walletClient
1273
+ }),
1274
+ feed: new FeedModuleClient({
1275
+ sdk: this.sdk,
1276
+ chainId: config.chainId,
1277
+ publicClient: config.publicClient,
1278
+ walletClient: config.walletClient
1088
1279
  })
1089
1280
  };
1090
1281
  }
@@ -1609,6 +1800,6 @@ function createSlotsClient(config) {
1609
1800
  return new SlotsClient(config);
1610
1801
  }
1611
1802
 
1612
- export { AccountFieldsFragmentDoc, CurrencyFieldsFragmentDoc, GetAccountDocument, GetAccountsDocument, GetBoughtEventsDocument, GetDepositedEventsDocument, GetFactoryDocument, GetLiquidatedEventsDocument, GetMetadataSlotDocument, GetMetadataSlotsByRecipientDocument, GetMetadataSlotsDocument, GetMetadataUpdatedEventsDocument, GetModulesDocument, GetPriceUpdatedEventsDocument, GetRecentEventsDocument, GetReleasedEventsDocument, GetSettledEventsDocument, GetSlotActivityDocument, GetSlotDeployedEventsDocument, GetSlotDocument, GetSlotsByOccupantDocument, GetSlotsByRecipientDocument, GetSlotsDocument, GetTaxCollectedEventsDocument, GetWithdrawnEventsDocument, MetadataModuleClient, MetadataSlotFieldsFragmentDoc, SUBGRAPH_URLS, SlotFieldsFragmentDoc, SlotsChain, SlotsClient, SlotsError, createSlotsClient, getSdk };
1613
- //# sourceMappingURL=chunk-JPXMWACL.js.map
1614
- //# sourceMappingURL=chunk-JPXMWACL.js.map
1803
+ export { AccountFieldsFragmentDoc, CurrencyFieldsFragmentDoc, FeedModuleClient, GetAccountDocument, GetAccountsDocument, GetBoughtEventsDocument, GetDepositedEventsDocument, GetFactoryDocument, GetLiquidatedEventsDocument, GetMetadataSlotDocument, GetMetadataSlotsByRecipientDocument, GetMetadataSlotsDocument, GetMetadataUpdatedEventsDocument, GetModulesDocument, GetPriceUpdatedEventsDocument, GetRecentEventsDocument, GetReleasedEventsDocument, GetSettledEventsDocument, GetSlotActivityDocument, GetSlotDeployedEventsDocument, GetSlotDocument, GetSlotsByOccupantDocument, GetSlotsByRecipientDocument, GetSlotsDocument, GetTaxCollectedEventsDocument, GetWithdrawnEventsDocument, MetadataModuleClient, MetadataSlotFieldsFragmentDoc, SUBGRAPH_URLS, SlotFieldsFragmentDoc, SlotsChain, SlotsClient, SlotsError, createSlotsClient, getSdk };
1804
+ //# sourceMappingURL=chunk-RKRQIWX7.js.map
1805
+ //# sourceMappingURL=chunk-RKRQIWX7.js.map