@0xslots/sdk 0.10.1 → 0.10.2
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-PZ2PG636.js} +44 -69
- package/dist/chunk-PZ2PG636.js.map +1 -0
- package/dist/{client-BcIWQW9H.d.ts → client-pupk2FMg.d.ts} +4 -8
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +2 -15
- package/dist/react.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-VQ5PSOCE.js.map +0 -1
|
@@ -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,7 +1330,13 @@ 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",
|
|
@@ -1522,46 +1533,9 @@ var SlotsClient = class {
|
|
|
1522
1533
|
});
|
|
1523
1534
|
}
|
|
1524
1535
|
// ─── 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
1536
|
/**
|
|
1562
|
-
*
|
|
1563
|
-
*
|
|
1564
|
-
* Otherwise: chains approve tx (if needed) then action tx.
|
|
1537
|
+
* Approve → confirm on-chain → execute call sequentially.
|
|
1538
|
+
* Skips approval if the existing allowance already covers the amount.
|
|
1565
1539
|
*/
|
|
1566
1540
|
async withAllowance(spender, amount, call) {
|
|
1567
1541
|
const currency = await this.publicClient.readContract({
|
|
@@ -1575,31 +1549,8 @@ var SlotsClient = class {
|
|
|
1575
1549
|
functionName: "allowance",
|
|
1576
1550
|
args: [this.account, spender]
|
|
1577
1551
|
});
|
|
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({
|
|
1552
|
+
if (allowance < amount) {
|
|
1553
|
+
const approveTx = await this.wallet.writeContract({
|
|
1603
1554
|
address: currency,
|
|
1604
1555
|
abi: erc20Abi,
|
|
1605
1556
|
functionName: "approve",
|
|
@@ -1607,7 +1558,22 @@ var SlotsClient = class {
|
|
|
1607
1558
|
account: this.account,
|
|
1608
1559
|
chain: this.chain
|
|
1609
1560
|
});
|
|
1610
|
-
await this.publicClient.waitForTransactionReceipt({ hash });
|
|
1561
|
+
await this.publicClient.waitForTransactionReceipt({ hash: approveTx });
|
|
1562
|
+
const confirmed = await this.pollUntil(
|
|
1563
|
+
() => this.publicClient.readContract({
|
|
1564
|
+
address: currency,
|
|
1565
|
+
abi: erc20Abi,
|
|
1566
|
+
functionName: "allowance",
|
|
1567
|
+
args: [this.account, spender]
|
|
1568
|
+
}),
|
|
1569
|
+
(value) => value >= amount
|
|
1570
|
+
);
|
|
1571
|
+
if (confirmed < amount) {
|
|
1572
|
+
throw new SlotsError(
|
|
1573
|
+
"withAllowance",
|
|
1574
|
+
"Approval confirmed but on-chain allowance is still insufficient after retries"
|
|
1575
|
+
);
|
|
1576
|
+
}
|
|
1611
1577
|
}
|
|
1612
1578
|
return this.wallet.writeContract({
|
|
1613
1579
|
address: call.to,
|
|
@@ -1618,11 +1584,20 @@ var SlotsClient = class {
|
|
|
1618
1584
|
chain: this.chain
|
|
1619
1585
|
});
|
|
1620
1586
|
}
|
|
1587
|
+
/** Poll `check` every `delayMs` until it returns a truthy value or `maxAttempts` is exhausted. */
|
|
1588
|
+
async pollUntil(check, predicate, { maxAttempts = 10, delayMs = 500 } = {}) {
|
|
1589
|
+
let value = await check();
|
|
1590
|
+
for (let i = 1; i < maxAttempts && !predicate(value); i++) {
|
|
1591
|
+
await new Promise((res) => setTimeout(res, delayMs));
|
|
1592
|
+
value = await check();
|
|
1593
|
+
}
|
|
1594
|
+
return value;
|
|
1595
|
+
}
|
|
1621
1596
|
};
|
|
1622
1597
|
function createSlotsClient(config) {
|
|
1623
1598
|
return new SlotsClient(config);
|
|
1624
1599
|
}
|
|
1625
1600
|
|
|
1626
1601
|
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-
|
|
1602
|
+
//# sourceMappingURL=chunk-PZ2PG636.js.map
|
|
1603
|
+
//# sourceMappingURL=chunk-PZ2PG636.js.map
|