@0xslots/sdk 0.10.1 → 0.11.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.
- package/dist/{chunk-VQ5PSOCE.js → chunk-XQG6GMWZ.js} +48 -72
- package/dist/chunk-XQG6GMWZ.js.map +1 -0
- package/dist/{client-BcIWQW9H.d.ts → client-CN0aLhHJ.d.ts} +7 -9
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +3 -19
- package/dist/react.js.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-VQ5PSOCE.js.map +0 -1
|
@@ -908,7 +908,7 @@ function getSdk(client, withWrapper = defaultWrapper) {
|
|
|
908
908
|
}
|
|
909
909
|
};
|
|
910
910
|
}
|
|
911
|
-
var EXPECTED_MODULE_NAME = "
|
|
911
|
+
var EXPECTED_MODULE_NAME = "AdLandModule";
|
|
912
912
|
var MetadataModuleClient = class {
|
|
913
913
|
constructor(opts) {
|
|
914
914
|
this.sdk = opts.sdk;
|
|
@@ -1287,7 +1287,12 @@ var SlotsClient = class {
|
|
|
1287
1287
|
address: this.factory,
|
|
1288
1288
|
abi: slotFactoryAbi,
|
|
1289
1289
|
functionName: "createSlot",
|
|
1290
|
-
args: [
|
|
1290
|
+
args: [
|
|
1291
|
+
params.recipient,
|
|
1292
|
+
params.currency,
|
|
1293
|
+
params.config,
|
|
1294
|
+
params.initParams
|
|
1295
|
+
],
|
|
1291
1296
|
account: this.account,
|
|
1292
1297
|
chain: this.chain
|
|
1293
1298
|
});
|
|
@@ -1325,11 +1330,17 @@ var SlotsClient = class {
|
|
|
1325
1330
|
async buy(params) {
|
|
1326
1331
|
this.assertPositive(params.depositAmount, "depositAmount");
|
|
1327
1332
|
this.assertPositive(params.selfAssessedPrice, "selfAssessedPrice");
|
|
1328
|
-
|
|
1333
|
+
const currentPrice = await this.publicClient.readContract({
|
|
1334
|
+
address: params.slot,
|
|
1335
|
+
abi: slotAbi,
|
|
1336
|
+
functionName: "price"
|
|
1337
|
+
});
|
|
1338
|
+
const approvalAmount = currentPrice + params.depositAmount;
|
|
1339
|
+
return this.withAllowance(params.slot, approvalAmount, {
|
|
1329
1340
|
to: params.slot,
|
|
1330
1341
|
abi: slotAbi,
|
|
1331
1342
|
functionName: "buy",
|
|
1332
|
-
args: [params.depositAmount, params.selfAssessedPrice]
|
|
1343
|
+
args: [params.account, params.depositAmount, params.selfAssessedPrice]
|
|
1333
1344
|
});
|
|
1334
1345
|
}
|
|
1335
1346
|
/**
|
|
@@ -1349,7 +1360,8 @@ var SlotsClient = class {
|
|
|
1349
1360
|
});
|
|
1350
1361
|
}
|
|
1351
1362
|
/**
|
|
1352
|
-
* Top up deposit on a slot
|
|
1363
|
+
* Top up deposit on a slot. Anyone can pay to extend the occupant's deposit.
|
|
1364
|
+
* Handles ERC-20 approval automatically.
|
|
1353
1365
|
* @param slot - The slot contract address.
|
|
1354
1366
|
* @param amount - The amount to deposit (must be > 0).
|
|
1355
1367
|
* @returns Transaction hash.
|
|
@@ -1522,46 +1534,9 @@ var SlotsClient = class {
|
|
|
1522
1534
|
});
|
|
1523
1535
|
}
|
|
1524
1536
|
// ─── Internals ──────────────────────────────────────────────────────────────
|
|
1525
|
-
/** Check if wallet supports atomic batch calls (EIP-5792). */
|
|
1526
|
-
async supportsAtomicBatch() {
|
|
1527
|
-
if (this._atomicSupport !== void 0) return this._atomicSupport;
|
|
1528
|
-
try {
|
|
1529
|
-
const capabilities = await this.wallet.getCapabilities?.();
|
|
1530
|
-
if (!capabilities) {
|
|
1531
|
-
this._atomicSupport = false;
|
|
1532
|
-
return false;
|
|
1533
|
-
}
|
|
1534
|
-
const chainId = this.chain.id;
|
|
1535
|
-
const chainCaps = capabilities[chainId] || capabilities[`0x${chainId.toString(16)}`];
|
|
1536
|
-
const atomic = chainCaps?.atomicBatch ?? chainCaps?.atomic;
|
|
1537
|
-
const status = atomic && typeof atomic === "object" && "status" in atomic ? atomic.status : void 0;
|
|
1538
|
-
this._atomicSupport = status === "supported" || status === "ready";
|
|
1539
|
-
} catch {
|
|
1540
|
-
this._atomicSupport = false;
|
|
1541
|
-
}
|
|
1542
|
-
return this._atomicSupport;
|
|
1543
|
-
}
|
|
1544
|
-
/** Poll EIP-5792 getCallsStatus until the batch settles, then return a tx hash. */
|
|
1545
|
-
async pollBatchReceipt(id) {
|
|
1546
|
-
const MAX_ATTEMPTS = 60;
|
|
1547
|
-
const INTERVAL = 1500;
|
|
1548
|
-
for (let i = 0; i < MAX_ATTEMPTS; i++) {
|
|
1549
|
-
const result = await this.wallet.getCallsStatus({ id });
|
|
1550
|
-
if (result.status === "success") {
|
|
1551
|
-
const receipts = result.receipts ?? [];
|
|
1552
|
-
return receipts[receipts.length - 1]?.transactionHash ?? id;
|
|
1553
|
-
}
|
|
1554
|
-
if (result.status === "failure") {
|
|
1555
|
-
throw new Error("Batch transaction reverted");
|
|
1556
|
-
}
|
|
1557
|
-
await new Promise((r) => setTimeout(r, INTERVAL));
|
|
1558
|
-
}
|
|
1559
|
-
throw new Error("Batch transaction timed out");
|
|
1560
|
-
}
|
|
1561
1537
|
/**
|
|
1562
|
-
*
|
|
1563
|
-
*
|
|
1564
|
-
* Otherwise: chains approve tx (if needed) then action tx.
|
|
1538
|
+
* Approve → confirm on-chain → execute call sequentially.
|
|
1539
|
+
* Skips approval if the existing allowance already covers the amount.
|
|
1565
1540
|
*/
|
|
1566
1541
|
async withAllowance(spender, amount, call) {
|
|
1567
1542
|
const currency = await this.publicClient.readContract({
|
|
@@ -1575,31 +1550,8 @@ var SlotsClient = class {
|
|
|
1575
1550
|
functionName: "allowance",
|
|
1576
1551
|
args: [this.account, spender]
|
|
1577
1552
|
});
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
const approveData = encodeFunctionData({
|
|
1581
|
-
abi: erc20Abi,
|
|
1582
|
-
functionName: "approve",
|
|
1583
|
-
args: [spender, amount]
|
|
1584
|
-
});
|
|
1585
|
-
const actionData = encodeFunctionData({
|
|
1586
|
-
abi: call.abi,
|
|
1587
|
-
functionName: call.functionName,
|
|
1588
|
-
args: call.args
|
|
1589
|
-
});
|
|
1590
|
-
const id = await this.wallet.sendCalls({
|
|
1591
|
-
account: this.account,
|
|
1592
|
-
chain: this.chain,
|
|
1593
|
-
calls: [
|
|
1594
|
-
{ to: currency, data: approveData },
|
|
1595
|
-
{ to: call.to, data: actionData }
|
|
1596
|
-
]
|
|
1597
|
-
});
|
|
1598
|
-
const txHash = await this.pollBatchReceipt(id);
|
|
1599
|
-
return txHash;
|
|
1600
|
-
}
|
|
1601
|
-
if (needsApproval) {
|
|
1602
|
-
const hash = await this.wallet.writeContract({
|
|
1553
|
+
if (allowance < amount) {
|
|
1554
|
+
const approveTx = await this.wallet.writeContract({
|
|
1603
1555
|
address: currency,
|
|
1604
1556
|
abi: erc20Abi,
|
|
1605
1557
|
functionName: "approve",
|
|
@@ -1607,7 +1559,22 @@ var SlotsClient = class {
|
|
|
1607
1559
|
account: this.account,
|
|
1608
1560
|
chain: this.chain
|
|
1609
1561
|
});
|
|
1610
|
-
await this.publicClient.waitForTransactionReceipt({ hash });
|
|
1562
|
+
await this.publicClient.waitForTransactionReceipt({ hash: approveTx });
|
|
1563
|
+
const confirmed = await this.pollUntil(
|
|
1564
|
+
() => this.publicClient.readContract({
|
|
1565
|
+
address: currency,
|
|
1566
|
+
abi: erc20Abi,
|
|
1567
|
+
functionName: "allowance",
|
|
1568
|
+
args: [this.account, spender]
|
|
1569
|
+
}),
|
|
1570
|
+
(value) => value >= amount
|
|
1571
|
+
);
|
|
1572
|
+
if (confirmed < amount) {
|
|
1573
|
+
throw new SlotsError(
|
|
1574
|
+
"withAllowance",
|
|
1575
|
+
"Approval confirmed but on-chain allowance is still insufficient after retries"
|
|
1576
|
+
);
|
|
1577
|
+
}
|
|
1611
1578
|
}
|
|
1612
1579
|
return this.wallet.writeContract({
|
|
1613
1580
|
address: call.to,
|
|
@@ -1618,11 +1585,20 @@ var SlotsClient = class {
|
|
|
1618
1585
|
chain: this.chain
|
|
1619
1586
|
});
|
|
1620
1587
|
}
|
|
1588
|
+
/** Poll `check` every `delayMs` until it returns a truthy value or `maxAttempts` is exhausted. */
|
|
1589
|
+
async pollUntil(check, predicate, { maxAttempts = 10, delayMs = 500 } = {}) {
|
|
1590
|
+
let value = await check();
|
|
1591
|
+
for (let i = 1; i < maxAttempts && !predicate(value); i++) {
|
|
1592
|
+
await new Promise((res) => setTimeout(res, delayMs));
|
|
1593
|
+
value = await check();
|
|
1594
|
+
}
|
|
1595
|
+
return value;
|
|
1596
|
+
}
|
|
1621
1597
|
};
|
|
1622
1598
|
function createSlotsClient(config) {
|
|
1623
1599
|
return new SlotsClient(config);
|
|
1624
1600
|
}
|
|
1625
1601
|
|
|
1626
1602
|
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 };
|
|
1627
|
-
//# sourceMappingURL=chunk-
|
|
1628
|
-
//# sourceMappingURL=chunk-
|
|
1603
|
+
//# sourceMappingURL=chunk-XQG6GMWZ.js.map
|
|
1604
|
+
//# sourceMappingURL=chunk-XQG6GMWZ.js.map
|