@medialane/sdk 0.59.0 → 0.61.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/evm/index.d.cts +1 -1
- package/dist/evm/index.d.ts +1 -1
- package/dist/{index-D-sFKbtL.d.ts → index-DfgwOqxs.d.ts} +25 -14
- package/dist/{index-DjraRZJ1.d.cts → index-Dgw8Wl8U.d.cts} +25 -14
- package/dist/index.cjs +414 -324
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +415 -325
- package/dist/index.js.map +1 -1
- package/dist/solana/index.d.cts +1 -1
- package/dist/solana/index.d.ts +1 -1
- package/dist/starknet/index.cjs +433 -351
- package/dist/starknet/index.cjs.map +1 -1
- package/dist/starknet/index.d.cts +3 -3
- package/dist/starknet/index.d.ts +3 -3
- package/dist/starknet/index.js +434 -352
- package/dist/starknet/index.js.map +1 -1
- package/dist/stellar/index.d.cts +1 -1
- package/dist/stellar/index.d.ts +1 -1
- package/dist/{types-V6imkXvR.d.cts → types-Bx3ax9lW.d.cts} +20 -3
- package/dist/{types-V6imkXvR.d.ts → types-Bx3ax9lW.d.ts} +20 -3
- package/package.json +3 -3
package/dist/starknet/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { hash, num, cairo, Contract, uint256, RpcProvider, CairoOption, CairoOptionVariant, ec, encode, TypedDataRevision,
|
|
2
|
+
import { hash, num, cairo, Contract, uint256, RpcProvider, CairoOption, CairoOptionVariant, ec, encode, TypedDataRevision, constants, shortString } from 'starknet';
|
|
3
3
|
import { keccak_256 } from '@noble/hashes/sha3.js';
|
|
4
4
|
import { base32, base58 } from '@scure/base';
|
|
5
5
|
|
|
@@ -10486,39 +10486,12 @@ var SUPPORTED_TOKENS = [
|
|
|
10486
10486
|
];
|
|
10487
10487
|
var DEFAULT_CURRENCY = "USDC";
|
|
10488
10488
|
|
|
10489
|
-
// src/utils/bigint.ts
|
|
10490
|
-
function stringifyBigInts(obj) {
|
|
10491
|
-
if (typeof obj === "bigint") {
|
|
10492
|
-
return obj.toString();
|
|
10493
|
-
}
|
|
10494
|
-
if (Array.isArray(obj)) {
|
|
10495
|
-
return obj.map(stringifyBigInts);
|
|
10496
|
-
}
|
|
10497
|
-
if (obj !== null && typeof obj === "object") {
|
|
10498
|
-
return Object.fromEntries(
|
|
10499
|
-
Object.entries(obj).map(([key, value]) => [
|
|
10500
|
-
key,
|
|
10501
|
-
stringifyBigInts(value)
|
|
10502
|
-
])
|
|
10503
|
-
);
|
|
10504
|
-
}
|
|
10505
|
-
return obj;
|
|
10506
|
-
}
|
|
10507
|
-
|
|
10508
10489
|
// src/utils/token.ts
|
|
10509
10490
|
function parseAmount(human, decimals) {
|
|
10510
10491
|
const [whole, frac = ""] = human.split(".");
|
|
10511
10492
|
const fracPadded = frac.padEnd(decimals, "0").slice(0, decimals);
|
|
10512
10493
|
return (BigInt(whole) * BigInt(10) ** BigInt(decimals) + BigInt(fracPadded)).toString();
|
|
10513
10494
|
}
|
|
10514
|
-
function formatAmount(raw, decimals) {
|
|
10515
|
-
const value = BigInt(raw);
|
|
10516
|
-
const factor = BigInt(Math.pow(10, decimals));
|
|
10517
|
-
const whole = value / factor;
|
|
10518
|
-
const remainder = value % factor;
|
|
10519
|
-
const fractional = remainder.toString().padStart(decimals, "0");
|
|
10520
|
-
return `${whole}.${fractional}`;
|
|
10521
|
-
}
|
|
10522
10495
|
function getTokenByAddress(address) {
|
|
10523
10496
|
const lower = address.toLowerCase();
|
|
10524
10497
|
return SUPPORTED_TOKENS.find((t) => t.address.toLowerCase() === lower);
|
|
@@ -10547,6 +10520,25 @@ function buildFeeCall(p, cfg) {
|
|
|
10547
10520
|
};
|
|
10548
10521
|
}
|
|
10549
10522
|
|
|
10523
|
+
// src/utils/bigint.ts
|
|
10524
|
+
function stringifyBigInts(obj) {
|
|
10525
|
+
if (typeof obj === "bigint") {
|
|
10526
|
+
return obj.toString();
|
|
10527
|
+
}
|
|
10528
|
+
if (Array.isArray(obj)) {
|
|
10529
|
+
return obj.map(stringifyBigInts);
|
|
10530
|
+
}
|
|
10531
|
+
if (obj !== null && typeof obj === "object") {
|
|
10532
|
+
return Object.fromEntries(
|
|
10533
|
+
Object.entries(obj).map(([key, value]) => [
|
|
10534
|
+
key,
|
|
10535
|
+
stringifyBigInts(value)
|
|
10536
|
+
])
|
|
10537
|
+
);
|
|
10538
|
+
}
|
|
10539
|
+
return obj;
|
|
10540
|
+
}
|
|
10541
|
+
|
|
10550
10542
|
// src/utils/rpc.ts
|
|
10551
10543
|
var PUBLIC_RPC_FALLBACKS = [
|
|
10552
10544
|
"https://rpc.starknet.lava.build"
|
|
@@ -10627,6 +10619,14 @@ function toSignatureArray(sig) {
|
|
|
10627
10619
|
const s = sig;
|
|
10628
10620
|
return [s.r.toString(), s.s.toString()];
|
|
10629
10621
|
}
|
|
10622
|
+
function newContract(abi, address, providerOrAccount) {
|
|
10623
|
+
const C = Contract;
|
|
10624
|
+
return C.length === 1 ? new Contract({ abi, address, providerOrAccount }) : new Contract(
|
|
10625
|
+
abi,
|
|
10626
|
+
address,
|
|
10627
|
+
providerOrAccount
|
|
10628
|
+
);
|
|
10629
|
+
}
|
|
10630
10630
|
function getChainId(config) {
|
|
10631
10631
|
if (config.chain !== "STARKNET") {
|
|
10632
10632
|
throw new Error(`SNIP-12 signing is Starknet-only; got chain "${config.chain}"`);
|
|
@@ -10651,17 +10651,101 @@ function getProvider(config) {
|
|
|
10651
10651
|
return p;
|
|
10652
10652
|
}
|
|
10653
10653
|
|
|
10654
|
+
// src/starknet/marketplace/build.ts
|
|
10655
|
+
function contractFor(cfg) {
|
|
10656
|
+
return newContract(IPMarketplaceABI, cfg.marketplaceContract, getProvider(cfg));
|
|
10657
|
+
}
|
|
10658
|
+
function buildListingOrder(i, cfg) {
|
|
10659
|
+
const orderParams = {
|
|
10660
|
+
offerer: i.offerer,
|
|
10661
|
+
marketplace: cfg.marketplaceContract,
|
|
10662
|
+
offer: { item_type: "ERC721", token: i.nftContract, identifier_or_criteria: i.tokenId, amount: "1" },
|
|
10663
|
+
consideration: {
|
|
10664
|
+
item_type: "ERC20",
|
|
10665
|
+
token: i.paymentTokenAddress,
|
|
10666
|
+
identifier_or_criteria: "0",
|
|
10667
|
+
amount: i.priceWei,
|
|
10668
|
+
recipient: i.offerer
|
|
10669
|
+
},
|
|
10670
|
+
royalty_max_bps: i.royaltyMaxBps,
|
|
10671
|
+
start_time: String(i.startTime),
|
|
10672
|
+
end_time: String(i.endTime),
|
|
10673
|
+
salt: i.salt,
|
|
10674
|
+
counter: i.counter
|
|
10675
|
+
};
|
|
10676
|
+
const typedData = stringifyBigInts(buildOrderTypedData(orderParams, getChainId(cfg)));
|
|
10677
|
+
return { orderParams, typedData };
|
|
10678
|
+
}
|
|
10679
|
+
function buildOfferOrder(i, cfg) {
|
|
10680
|
+
const orderParams = {
|
|
10681
|
+
offerer: i.offerer,
|
|
10682
|
+
marketplace: cfg.marketplaceContract,
|
|
10683
|
+
offer: { item_type: "ERC20", token: i.paymentTokenAddress, identifier_or_criteria: "0", amount: i.priceWei },
|
|
10684
|
+
consideration: {
|
|
10685
|
+
item_type: "ERC721",
|
|
10686
|
+
token: i.nftContract,
|
|
10687
|
+
identifier_or_criteria: i.tokenId,
|
|
10688
|
+
amount: "1",
|
|
10689
|
+
recipient: i.offerer
|
|
10690
|
+
},
|
|
10691
|
+
royalty_max_bps: i.royaltyMaxBps,
|
|
10692
|
+
start_time: String(i.startTime),
|
|
10693
|
+
end_time: String(i.endTime),
|
|
10694
|
+
salt: i.salt,
|
|
10695
|
+
counter: i.counter
|
|
10696
|
+
};
|
|
10697
|
+
const typedData = stringifyBigInts(buildOrderTypedData(orderParams, getChainId(cfg)));
|
|
10698
|
+
return { orderParams, typedData };
|
|
10699
|
+
}
|
|
10700
|
+
function registerPayload(orderParams, signature) {
|
|
10701
|
+
return stringifyBigInts({
|
|
10702
|
+
parameters: {
|
|
10703
|
+
...orderParams,
|
|
10704
|
+
offer: { ...orderParams.offer, item_type: shortString.encodeShortString(orderParams.offer.item_type) },
|
|
10705
|
+
consideration: {
|
|
10706
|
+
...orderParams.consideration,
|
|
10707
|
+
item_type: shortString.encodeShortString(orderParams.consideration.item_type)
|
|
10708
|
+
}
|
|
10709
|
+
},
|
|
10710
|
+
signature
|
|
10711
|
+
});
|
|
10712
|
+
}
|
|
10713
|
+
function buildRegisterCalls(a, cfg) {
|
|
10714
|
+
const registerCall = contractFor(cfg).populate("register_order", [registerPayload(a.orderParams, a.signature)]);
|
|
10715
|
+
return a.approvalNeeded ? [a.approve, registerCall] : [registerCall];
|
|
10716
|
+
}
|
|
10717
|
+
function buildFulfillCalls(a, cfg) {
|
|
10718
|
+
const u = cairo.uint256(a.totalPrice);
|
|
10719
|
+
const approve = {
|
|
10720
|
+
contractAddress: a.paymentToken,
|
|
10721
|
+
entrypoint: "approve",
|
|
10722
|
+
calldata: [cfg.marketplaceContract, u.low.toString(), u.high.toString()]
|
|
10723
|
+
};
|
|
10724
|
+
const fulfill = contractFor(cfg).populate("fulfill_order", [a.orderHash]);
|
|
10725
|
+
const fee = buildFeeCall(
|
|
10726
|
+
{ surface: "marketplace", token: a.paymentToken, grossAmount: BigInt(a.totalPrice) },
|
|
10727
|
+
cfg.feeConfig
|
|
10728
|
+
);
|
|
10729
|
+
return fee ? [approve, fulfill, fee] : [approve, fulfill];
|
|
10730
|
+
}
|
|
10731
|
+
function buildCancelCalls(a, cfg) {
|
|
10732
|
+
const cancelRequest = stringifyBigInts({
|
|
10733
|
+
cancelation: { order_hash: a.orderHash, offerer: a.offerer },
|
|
10734
|
+
signature: a.signature
|
|
10735
|
+
});
|
|
10736
|
+
return [contractFor(cfg).populate("cancel_order", [cancelRequest])];
|
|
10737
|
+
}
|
|
10738
|
+
function buildCancelTypedData(orderHash, offerer, cfg) {
|
|
10739
|
+
return stringifyBigInts(buildCancellationTypedData({ order_hash: orderHash, offerer }, getChainId(cfg)));
|
|
10740
|
+
}
|
|
10741
|
+
|
|
10654
10742
|
// src/starknet/marketplace/orders.ts
|
|
10655
10743
|
var _contractCache = /* @__PURE__ */ new WeakMap();
|
|
10656
10744
|
function makeContract(config) {
|
|
10657
10745
|
const cached = _contractCache.get(config);
|
|
10658
10746
|
const provider = getProvider(config);
|
|
10659
10747
|
if (cached) return { ...cached, provider };
|
|
10660
|
-
const contract =
|
|
10661
|
-
IPMarketplaceABI,
|
|
10662
|
-
config.marketplaceContract,
|
|
10663
|
-
provider
|
|
10664
|
-
);
|
|
10748
|
+
const contract = newContract(IPMarketplaceABI, config.marketplaceContract, provider);
|
|
10665
10749
|
_contractCache.set(config, { contract });
|
|
10666
10750
|
return { contract, provider };
|
|
10667
10751
|
}
|
|
@@ -10675,46 +10759,22 @@ async function createListing(account, params, config) {
|
|
|
10675
10759
|
const endTime = now + durationSeconds;
|
|
10676
10760
|
const counter = (await contract.get_counter(account.address)).toString();
|
|
10677
10761
|
const royaltyMaxBps = await resolveRoyaltyMaxBps(provider, nftContract, tokenId, params.royaltyMaxBps);
|
|
10678
|
-
const orderParams =
|
|
10679
|
-
|
|
10680
|
-
|
|
10681
|
-
|
|
10682
|
-
|
|
10683
|
-
|
|
10684
|
-
|
|
10685
|
-
|
|
10686
|
-
|
|
10687
|
-
|
|
10688
|
-
|
|
10689
|
-
|
|
10690
|
-
identifier_or_criteria: "0",
|
|
10691
|
-
amount: priceWei,
|
|
10692
|
-
recipient: account.address
|
|
10693
|
-
},
|
|
10694
|
-
royalty_max_bps: royaltyMaxBps,
|
|
10695
|
-
start_time: startTime.toString(),
|
|
10696
|
-
end_time: endTime.toString(),
|
|
10697
|
-
salt: generateSalt(),
|
|
10698
|
-
counter
|
|
10699
|
-
};
|
|
10700
|
-
const chainId = getChainId(config);
|
|
10701
|
-
const typedData = stringifyBigInts(buildOrderTypedData(orderParams, chainId));
|
|
10702
|
-
const signature = await account.signMessage(typedData);
|
|
10703
|
-
const signatureArray = toSignatureArray(signature);
|
|
10704
|
-
const registerPayload = stringifyBigInts({
|
|
10705
|
-
parameters: {
|
|
10706
|
-
...orderParams,
|
|
10707
|
-
offer: {
|
|
10708
|
-
...orderParams.offer,
|
|
10709
|
-
item_type: shortString.encodeShortString(orderParams.offer.item_type)
|
|
10710
|
-
},
|
|
10711
|
-
consideration: {
|
|
10712
|
-
...orderParams.consideration,
|
|
10713
|
-
item_type: shortString.encodeShortString(orderParams.consideration.item_type)
|
|
10714
|
-
}
|
|
10762
|
+
const { orderParams, typedData } = buildListingOrder(
|
|
10763
|
+
{
|
|
10764
|
+
offerer: account.address,
|
|
10765
|
+
nftContract,
|
|
10766
|
+
tokenId,
|
|
10767
|
+
priceWei,
|
|
10768
|
+
paymentTokenAddress: token.address,
|
|
10769
|
+
royaltyMaxBps,
|
|
10770
|
+
startTime,
|
|
10771
|
+
endTime,
|
|
10772
|
+
salt: generateSalt(),
|
|
10773
|
+
counter
|
|
10715
10774
|
},
|
|
10716
|
-
|
|
10717
|
-
|
|
10775
|
+
config
|
|
10776
|
+
);
|
|
10777
|
+
const signatureArray = toSignatureArray(await account.signMessage(typedData));
|
|
10718
10778
|
const tokenIdUint256 = cairo.uint256(tokenId);
|
|
10719
10779
|
let isAlreadyApproved = false;
|
|
10720
10780
|
try {
|
|
@@ -10726,19 +10786,19 @@ async function createListing(account, params, config) {
|
|
|
10726
10786
|
isAlreadyApproved = BigInt(result[0]).toString() === BigInt(config.marketplaceContract).toString();
|
|
10727
10787
|
} catch {
|
|
10728
10788
|
}
|
|
10729
|
-
const
|
|
10730
|
-
|
|
10731
|
-
|
|
10732
|
-
|
|
10733
|
-
|
|
10734
|
-
|
|
10735
|
-
|
|
10736
|
-
|
|
10737
|
-
|
|
10738
|
-
|
|
10739
|
-
},
|
|
10740
|
-
|
|
10741
|
-
|
|
10789
|
+
const approve = {
|
|
10790
|
+
contractAddress: nftContract,
|
|
10791
|
+
entrypoint: "approve",
|
|
10792
|
+
calldata: [
|
|
10793
|
+
config.marketplaceContract,
|
|
10794
|
+
tokenIdUint256.low.toString(),
|
|
10795
|
+
tokenIdUint256.high.toString()
|
|
10796
|
+
]
|
|
10797
|
+
};
|
|
10798
|
+
const calls = buildRegisterCalls(
|
|
10799
|
+
{ orderParams, signature: signatureArray, approvalNeeded: !isAlreadyApproved, approve },
|
|
10800
|
+
config
|
|
10801
|
+
);
|
|
10742
10802
|
try {
|
|
10743
10803
|
const tx = await account.execute(calls);
|
|
10744
10804
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
@@ -10757,46 +10817,22 @@ async function makeOffer(account, params, config) {
|
|
|
10757
10817
|
const endTime = now + durationSeconds;
|
|
10758
10818
|
const counter = (await contract.get_counter(account.address)).toString();
|
|
10759
10819
|
const royaltyMaxBps = await resolveRoyaltyMaxBps(provider, nftContract, tokenId, params.royaltyMaxBps);
|
|
10760
|
-
const orderParams =
|
|
10761
|
-
|
|
10762
|
-
|
|
10763
|
-
|
|
10764
|
-
|
|
10765
|
-
|
|
10766
|
-
|
|
10767
|
-
|
|
10768
|
-
|
|
10769
|
-
|
|
10770
|
-
|
|
10771
|
-
|
|
10772
|
-
identifier_or_criteria: tokenId,
|
|
10773
|
-
amount: "1",
|
|
10774
|
-
recipient: account.address
|
|
10775
|
-
},
|
|
10776
|
-
royalty_max_bps: royaltyMaxBps,
|
|
10777
|
-
start_time: startTime.toString(),
|
|
10778
|
-
end_time: endTime.toString(),
|
|
10779
|
-
salt: generateSalt(),
|
|
10780
|
-
counter
|
|
10781
|
-
};
|
|
10782
|
-
const chainId = getChainId(config);
|
|
10783
|
-
const typedData = stringifyBigInts(buildOrderTypedData(orderParams, chainId));
|
|
10784
|
-
const signature = await account.signMessage(typedData);
|
|
10785
|
-
const signatureArray = toSignatureArray(signature);
|
|
10786
|
-
const registerPayload = stringifyBigInts({
|
|
10787
|
-
parameters: {
|
|
10788
|
-
...orderParams,
|
|
10789
|
-
offer: {
|
|
10790
|
-
...orderParams.offer,
|
|
10791
|
-
item_type: shortString.encodeShortString(orderParams.offer.item_type)
|
|
10792
|
-
},
|
|
10793
|
-
consideration: {
|
|
10794
|
-
...orderParams.consideration,
|
|
10795
|
-
item_type: shortString.encodeShortString(orderParams.consideration.item_type)
|
|
10796
|
-
}
|
|
10820
|
+
const { orderParams, typedData } = buildOfferOrder(
|
|
10821
|
+
{
|
|
10822
|
+
offerer: account.address,
|
|
10823
|
+
nftContract,
|
|
10824
|
+
tokenId,
|
|
10825
|
+
priceWei,
|
|
10826
|
+
paymentTokenAddress: token.address,
|
|
10827
|
+
royaltyMaxBps,
|
|
10828
|
+
startTime,
|
|
10829
|
+
endTime,
|
|
10830
|
+
salt: generateSalt(),
|
|
10831
|
+
counter
|
|
10797
10832
|
},
|
|
10798
|
-
|
|
10799
|
-
|
|
10833
|
+
config
|
|
10834
|
+
);
|
|
10835
|
+
const signatureArray = toSignatureArray(await account.signMessage(typedData));
|
|
10800
10836
|
const amountUint256 = cairo.uint256(priceWei);
|
|
10801
10837
|
const approveCall = {
|
|
10802
10838
|
contractAddress: token.address,
|
|
@@ -10807,9 +10843,12 @@ async function makeOffer(account, params, config) {
|
|
|
10807
10843
|
amountUint256.high.toString()
|
|
10808
10844
|
]
|
|
10809
10845
|
};
|
|
10810
|
-
const
|
|
10846
|
+
const calls = buildRegisterCalls(
|
|
10847
|
+
{ orderParams, signature: signatureArray, approvalNeeded: true, approve: approveCall },
|
|
10848
|
+
config
|
|
10849
|
+
);
|
|
10811
10850
|
try {
|
|
10812
|
-
const tx = await account.execute(
|
|
10851
|
+
const tx = await account.execute(calls);
|
|
10813
10852
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
10814
10853
|
return { txHash: tx.transaction_hash };
|
|
10815
10854
|
} catch (err) {
|
|
@@ -10818,23 +10857,8 @@ async function makeOffer(account, params, config) {
|
|
|
10818
10857
|
}
|
|
10819
10858
|
async function fulfillOrder(account, params, config) {
|
|
10820
10859
|
const { orderHash, paymentToken, totalPrice } = params;
|
|
10821
|
-
const {
|
|
10822
|
-
const
|
|
10823
|
-
const approveCall = {
|
|
10824
|
-
contractAddress: paymentToken,
|
|
10825
|
-
entrypoint: "approve",
|
|
10826
|
-
calldata: [
|
|
10827
|
-
config.marketplaceContract,
|
|
10828
|
-
totalPriceU256.low.toString(),
|
|
10829
|
-
totalPriceU256.high.toString()
|
|
10830
|
-
]
|
|
10831
|
-
};
|
|
10832
|
-
const fulfillCall = contract.populate("fulfill_order", [orderHash]);
|
|
10833
|
-
const feeCall = buildFeeCall(
|
|
10834
|
-
{ surface: "marketplace", token: paymentToken, grossAmount: BigInt(totalPrice) },
|
|
10835
|
-
config.feeConfig
|
|
10836
|
-
);
|
|
10837
|
-
const calls = feeCall ? [approveCall, fulfillCall, feeCall] : [approveCall, fulfillCall];
|
|
10860
|
+
const { provider } = makeContract(config);
|
|
10861
|
+
const calls = buildFulfillCalls({ orderHash, paymentToken, totalPrice }, config);
|
|
10838
10862
|
try {
|
|
10839
10863
|
const tx = await account.execute(calls);
|
|
10840
10864
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
@@ -10845,24 +10869,12 @@ async function fulfillOrder(account, params, config) {
|
|
|
10845
10869
|
}
|
|
10846
10870
|
async function cancelOrder(account, params, config) {
|
|
10847
10871
|
const { orderHash } = params;
|
|
10848
|
-
const {
|
|
10849
|
-
const
|
|
10850
|
-
const
|
|
10851
|
-
|
|
10852
|
-
offerer: account.address
|
|
10853
|
-
};
|
|
10854
|
-
const typedData = stringifyBigInts(
|
|
10855
|
-
buildCancellationTypedData(cancelParams, chainId)
|
|
10856
|
-
);
|
|
10857
|
-
const signature = await account.signMessage(typedData);
|
|
10858
|
-
const signatureArray = toSignatureArray(signature);
|
|
10859
|
-
const cancelRequest = stringifyBigInts({
|
|
10860
|
-
cancelation: cancelParams,
|
|
10861
|
-
signature: signatureArray
|
|
10862
|
-
});
|
|
10863
|
-
const call = contract.populate("cancel_order", [cancelRequest]);
|
|
10872
|
+
const { provider } = makeContract(config);
|
|
10873
|
+
const typedData = buildCancelTypedData(orderHash, account.address, config);
|
|
10874
|
+
const signatureArray = toSignatureArray(await account.signMessage(typedData));
|
|
10875
|
+
const calls = buildCancelCalls({ orderHash, offerer: account.address, signature: signatureArray }, config);
|
|
10864
10876
|
try {
|
|
10865
|
-
const tx = await account.execute(
|
|
10877
|
+
const tx = await account.execute(calls);
|
|
10866
10878
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
10867
10879
|
return { txHash: tx.transaction_hash };
|
|
10868
10880
|
} catch (err) {
|
|
@@ -11009,16 +11021,106 @@ var MarketplaceModule = class {
|
|
|
11009
11021
|
return buildCancellationTypedData(params, chainId);
|
|
11010
11022
|
}
|
|
11011
11023
|
};
|
|
11024
|
+
function contractFor2(cfg) {
|
|
11025
|
+
return newContract(Medialane1155ABI, cfg.marketplace1155Contract, getProvider(cfg));
|
|
11026
|
+
}
|
|
11027
|
+
function buildListing1155Order(i, cfg) {
|
|
11028
|
+
const orderParams = {
|
|
11029
|
+
offerer: i.offerer,
|
|
11030
|
+
marketplace: cfg.marketplace1155Contract,
|
|
11031
|
+
offer: { item_type: "ERC1155", token: i.nftContract, identifier_or_criteria: i.tokenId, amount: i.quantity },
|
|
11032
|
+
consideration: {
|
|
11033
|
+
item_type: "ERC20",
|
|
11034
|
+
token: i.paymentTokenAddress,
|
|
11035
|
+
identifier_or_criteria: "0",
|
|
11036
|
+
amount: i.priceWeiPerUnit,
|
|
11037
|
+
recipient: i.offerer
|
|
11038
|
+
},
|
|
11039
|
+
royalty_max_bps: i.royaltyMaxBps,
|
|
11040
|
+
start_time: String(i.startTime),
|
|
11041
|
+
end_time: String(i.endTime),
|
|
11042
|
+
salt: i.salt,
|
|
11043
|
+
counter: i.counter
|
|
11044
|
+
};
|
|
11045
|
+
const typedData = stringifyBigInts(
|
|
11046
|
+
build1155OrderTypedData(orderParams, getChainId(cfg))
|
|
11047
|
+
);
|
|
11048
|
+
return { orderParams, typedData };
|
|
11049
|
+
}
|
|
11050
|
+
function buildOffer1155Order(i, cfg) {
|
|
11051
|
+
const orderParams = {
|
|
11052
|
+
offerer: i.offerer,
|
|
11053
|
+
marketplace: cfg.marketplace1155Contract,
|
|
11054
|
+
offer: { item_type: "ERC20", token: i.paymentTokenAddress, identifier_or_criteria: "0", amount: i.priceWeiPerUnit },
|
|
11055
|
+
consideration: {
|
|
11056
|
+
item_type: "ERC1155",
|
|
11057
|
+
token: i.nftContract,
|
|
11058
|
+
identifier_or_criteria: i.tokenId,
|
|
11059
|
+
amount: i.quantity,
|
|
11060
|
+
recipient: i.offerer
|
|
11061
|
+
},
|
|
11062
|
+
royalty_max_bps: i.royaltyMaxBps,
|
|
11063
|
+
start_time: String(i.startTime),
|
|
11064
|
+
end_time: String(i.endTime),
|
|
11065
|
+
salt: i.salt,
|
|
11066
|
+
counter: i.counter
|
|
11067
|
+
};
|
|
11068
|
+
const typedData = stringifyBigInts(
|
|
11069
|
+
build1155OrderTypedData(orderParams, getChainId(cfg))
|
|
11070
|
+
);
|
|
11071
|
+
return { orderParams, typedData };
|
|
11072
|
+
}
|
|
11073
|
+
function registerPayload2(orderParams, signature) {
|
|
11074
|
+
return stringifyBigInts({
|
|
11075
|
+
parameters: {
|
|
11076
|
+
...orderParams,
|
|
11077
|
+
offer: { ...orderParams.offer, item_type: shortString.encodeShortString(orderParams.offer.item_type) },
|
|
11078
|
+
consideration: {
|
|
11079
|
+
...orderParams.consideration,
|
|
11080
|
+
item_type: shortString.encodeShortString(orderParams.consideration.item_type)
|
|
11081
|
+
}
|
|
11082
|
+
},
|
|
11083
|
+
signature
|
|
11084
|
+
});
|
|
11085
|
+
}
|
|
11086
|
+
function buildRegister1155Calls(a, cfg) {
|
|
11087
|
+
const registerCall = contractFor2(cfg).populate("register_order", [registerPayload2(a.orderParams, a.signature)]);
|
|
11088
|
+
return a.approvalNeeded ? [a.approve, registerCall] : [registerCall];
|
|
11089
|
+
}
|
|
11090
|
+
function buildFulfill1155Calls(a, cfg) {
|
|
11091
|
+
const u = cairo.uint256(a.totalPrice);
|
|
11092
|
+
const approve = {
|
|
11093
|
+
contractAddress: a.paymentToken,
|
|
11094
|
+
entrypoint: "approve",
|
|
11095
|
+
calldata: [cfg.marketplace1155Contract, u.low.toString(), u.high.toString()]
|
|
11096
|
+
};
|
|
11097
|
+
const fulfill = contractFor2(cfg).populate("fulfill_order", [a.orderHash, a.quantity]);
|
|
11098
|
+
const fee = buildFeeCall(
|
|
11099
|
+
{ surface: "marketplace", token: a.paymentToken, grossAmount: BigInt(a.totalPrice) },
|
|
11100
|
+
cfg.feeConfig
|
|
11101
|
+
);
|
|
11102
|
+
return fee ? [approve, fulfill, fee] : [approve, fulfill];
|
|
11103
|
+
}
|
|
11104
|
+
function buildCancel1155Calls(a, cfg) {
|
|
11105
|
+
const cancelPayload = stringifyBigInts({
|
|
11106
|
+
cancelation: { order_hash: a.orderHash, offerer: a.offerer },
|
|
11107
|
+
signature: a.signature
|
|
11108
|
+
});
|
|
11109
|
+
return [contractFor2(cfg).populate("cancel_order", [cancelPayload])];
|
|
11110
|
+
}
|
|
11111
|
+
function buildCancel1155TypedData(orderHash, offerer, cfg) {
|
|
11112
|
+
return stringifyBigInts(
|
|
11113
|
+
build1155CancellationTypedData({ order_hash: orderHash, offerer }, getChainId(cfg))
|
|
11114
|
+
);
|
|
11115
|
+
}
|
|
11116
|
+
|
|
11117
|
+
// src/starknet/marketplace1155/orders.ts
|
|
11012
11118
|
var _contractCache2 = /* @__PURE__ */ new WeakMap();
|
|
11013
11119
|
function getContract(config) {
|
|
11014
11120
|
let c = _contractCache2.get(config);
|
|
11015
11121
|
if (!c) {
|
|
11016
11122
|
const provider = getProvider(config);
|
|
11017
|
-
c =
|
|
11018
|
-
Medialane1155ABI,
|
|
11019
|
-
config.marketplace1155Contract,
|
|
11020
|
-
provider
|
|
11021
|
-
);
|
|
11123
|
+
c = newContract(Medialane1155ABI, config.marketplace1155Contract, provider);
|
|
11022
11124
|
_contractCache2.set(config, c);
|
|
11023
11125
|
}
|
|
11024
11126
|
return c;
|
|
@@ -11037,53 +11139,27 @@ async function createListing1155(account, params, config) {
|
|
|
11037
11139
|
const token = resolveToken(currency);
|
|
11038
11140
|
const priceWei = parseAmount(pricePerUnit, token.decimals);
|
|
11039
11141
|
const now = Math.floor(Date.now() / 1e3);
|
|
11142
|
+
const startTime = now + START_TIME_BUFFER_SECS;
|
|
11040
11143
|
const endTime = now + durationSeconds;
|
|
11041
|
-
const chainId = getChainId(config);
|
|
11042
11144
|
const counter = (await contract.get_counter(account.address)).toString();
|
|
11043
11145
|
const royaltyMaxBps = await resolveRoyaltyMaxBps(provider, nftContract, tokenId, params.royaltyMaxBps);
|
|
11044
|
-
const orderParams =
|
|
11045
|
-
|
|
11046
|
-
|
|
11047
|
-
|
|
11048
|
-
|
|
11049
|
-
|
|
11050
|
-
|
|
11051
|
-
|
|
11052
|
-
|
|
11053
|
-
|
|
11054
|
-
|
|
11055
|
-
|
|
11056
|
-
|
|
11057
|
-
identifier_or_criteria: "0",
|
|
11058
|
-
amount: priceWei,
|
|
11059
|
-
// payment leg amount = price PER UNIT
|
|
11060
|
-
recipient: account.address
|
|
11146
|
+
const { orderParams, typedData } = buildListing1155Order(
|
|
11147
|
+
{
|
|
11148
|
+
offerer: account.address,
|
|
11149
|
+
nftContract,
|
|
11150
|
+
tokenId,
|
|
11151
|
+
quantity: amount,
|
|
11152
|
+
priceWeiPerUnit: priceWei,
|
|
11153
|
+
paymentTokenAddress: token.address,
|
|
11154
|
+
royaltyMaxBps,
|
|
11155
|
+
startTime,
|
|
11156
|
+
endTime,
|
|
11157
|
+
salt: generateSalt(),
|
|
11158
|
+
counter
|
|
11061
11159
|
},
|
|
11062
|
-
|
|
11063
|
-
start_time: (now + START_TIME_BUFFER_SECS).toString(),
|
|
11064
|
-
end_time: endTime.toString(),
|
|
11065
|
-
salt: generateSalt(),
|
|
11066
|
-
counter
|
|
11067
|
-
};
|
|
11068
|
-
const typedData = stringifyBigInts(
|
|
11069
|
-
build1155OrderTypedData(orderParams, chainId)
|
|
11160
|
+
config
|
|
11070
11161
|
);
|
|
11071
|
-
const
|
|
11072
|
-
const signatureArray = toSignatureArray(signature);
|
|
11073
|
-
const orderPayload = stringifyBigInts({
|
|
11074
|
-
parameters: {
|
|
11075
|
-
...orderParams,
|
|
11076
|
-
offer: {
|
|
11077
|
-
...orderParams.offer,
|
|
11078
|
-
item_type: shortString.encodeShortString(orderParams.offer.item_type)
|
|
11079
|
-
},
|
|
11080
|
-
consideration: {
|
|
11081
|
-
...orderParams.consideration,
|
|
11082
|
-
item_type: shortString.encodeShortString(orderParams.consideration.item_type)
|
|
11083
|
-
}
|
|
11084
|
-
},
|
|
11085
|
-
signature: signatureArray
|
|
11086
|
-
});
|
|
11162
|
+
const signatureArray = toSignatureArray(await account.signMessage(typedData));
|
|
11087
11163
|
let isApproved = false;
|
|
11088
11164
|
try {
|
|
11089
11165
|
const result = await provider.callContract({
|
|
@@ -11094,15 +11170,15 @@ async function createListing1155(account, params, config) {
|
|
|
11094
11170
|
isApproved = BigInt(result[0]) === 1n;
|
|
11095
11171
|
} catch {
|
|
11096
11172
|
}
|
|
11097
|
-
const
|
|
11098
|
-
|
|
11099
|
-
|
|
11100
|
-
|
|
11101
|
-
|
|
11102
|
-
|
|
11103
|
-
},
|
|
11104
|
-
|
|
11105
|
-
|
|
11173
|
+
const approve = {
|
|
11174
|
+
contractAddress: nftContract,
|
|
11175
|
+
entrypoint: "set_approval_for_all",
|
|
11176
|
+
calldata: [config.marketplace1155Contract, "1"]
|
|
11177
|
+
};
|
|
11178
|
+
const calls = buildRegister1155Calls(
|
|
11179
|
+
{ orderParams, signature: signatureArray, approvalNeeded: !isApproved, approve },
|
|
11180
|
+
config
|
|
11181
|
+
);
|
|
11106
11182
|
try {
|
|
11107
11183
|
const tx = await account.execute(calls);
|
|
11108
11184
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
@@ -11113,21 +11189,10 @@ async function createListing1155(account, params, config) {
|
|
|
11113
11189
|
}
|
|
11114
11190
|
async function fulfillOrder1155(account, params, config) {
|
|
11115
11191
|
const { orderHash, paymentToken, totalPrice, quantity = "1" } = params;
|
|
11116
|
-
const contract = getContract(config);
|
|
11117
11192
|
const provider = getProvider(config);
|
|
11118
|
-
const
|
|
11119
|
-
const approveCall = {
|
|
11120
|
-
contractAddress: paymentToken,
|
|
11121
|
-
entrypoint: "approve",
|
|
11122
|
-
calldata: [
|
|
11123
|
-
config.marketplace1155Contract,
|
|
11124
|
-
totalPriceU256.low.toString(),
|
|
11125
|
-
totalPriceU256.high.toString()
|
|
11126
|
-
]
|
|
11127
|
-
};
|
|
11128
|
-
const fulfillCall = contract.populate("fulfill_order", [orderHash, quantity]);
|
|
11193
|
+
const calls = buildFulfill1155Calls({ orderHash, paymentToken, totalPrice, quantity }, config);
|
|
11129
11194
|
try {
|
|
11130
|
-
const tx = await account.execute(
|
|
11195
|
+
const tx = await account.execute(calls);
|
|
11131
11196
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
11132
11197
|
return { txHash: tx.transaction_hash };
|
|
11133
11198
|
} catch (err) {
|
|
@@ -11136,25 +11201,12 @@ async function fulfillOrder1155(account, params, config) {
|
|
|
11136
11201
|
}
|
|
11137
11202
|
async function cancelOrder1155(account, params, config) {
|
|
11138
11203
|
const { orderHash } = params;
|
|
11139
|
-
const contract = getContract(config);
|
|
11140
11204
|
const provider = getProvider(config);
|
|
11141
|
-
const
|
|
11142
|
-
const
|
|
11143
|
-
|
|
11144
|
-
offerer: account.address
|
|
11145
|
-
};
|
|
11146
|
-
const typedData = stringifyBigInts(
|
|
11147
|
-
build1155CancellationTypedData(cancelParams, chainId)
|
|
11148
|
-
);
|
|
11149
|
-
const signature = await account.signMessage(typedData);
|
|
11150
|
-
const signatureArray = toSignatureArray(signature);
|
|
11151
|
-
const cancelPayload = stringifyBigInts({
|
|
11152
|
-
cancelation: cancelParams,
|
|
11153
|
-
signature: signatureArray
|
|
11154
|
-
});
|
|
11155
|
-
const cancelCall = contract.populate("cancel_order", [cancelPayload]);
|
|
11205
|
+
const typedData = buildCancel1155TypedData(orderHash, account.address, config);
|
|
11206
|
+
const signatureArray = toSignatureArray(await account.signMessage(typedData));
|
|
11207
|
+
const calls = buildCancel1155Calls({ orderHash, offerer: account.address, signature: signatureArray }, config);
|
|
11156
11208
|
try {
|
|
11157
|
-
const tx = await account.execute(
|
|
11209
|
+
const tx = await account.execute(calls);
|
|
11158
11210
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
11159
11211
|
return { txHash: tx.transaction_hash };
|
|
11160
11212
|
} catch (err) {
|
|
@@ -11172,56 +11224,30 @@ async function makeOffer1155(account, params, config) {
|
|
|
11172
11224
|
} = params;
|
|
11173
11225
|
const contract = getContract(config);
|
|
11174
11226
|
const provider = getProvider(config);
|
|
11175
|
-
const chainId = getChainId(config);
|
|
11176
11227
|
const token = resolveToken(currency);
|
|
11177
11228
|
const priceWei = parseAmount(price, token.decimals);
|
|
11178
11229
|
const now = Math.floor(Date.now() / 1e3);
|
|
11230
|
+
const startTime = now + START_TIME_BUFFER_SECS;
|
|
11179
11231
|
const endTime = now + durationSeconds;
|
|
11180
11232
|
const counter = (await contract.get_counter(account.address)).toString();
|
|
11181
11233
|
const royaltyMaxBps = await resolveRoyaltyMaxBps(provider, nftContract, tokenId, params.royaltyMaxBps);
|
|
11182
|
-
const orderParams =
|
|
11183
|
-
|
|
11184
|
-
|
|
11185
|
-
|
|
11186
|
-
|
|
11187
|
-
|
|
11188
|
-
|
|
11189
|
-
|
|
11190
|
-
|
|
11191
|
-
|
|
11192
|
-
|
|
11193
|
-
|
|
11194
|
-
|
|
11195
|
-
identifier_or_criteria: tokenId,
|
|
11196
|
-
amount,
|
|
11197
|
-
// unit quantity
|
|
11198
|
-
recipient: account.address
|
|
11234
|
+
const { orderParams, typedData } = buildOffer1155Order(
|
|
11235
|
+
{
|
|
11236
|
+
offerer: account.address,
|
|
11237
|
+
nftContract,
|
|
11238
|
+
tokenId,
|
|
11239
|
+
quantity: amount,
|
|
11240
|
+
priceWeiPerUnit: priceWei,
|
|
11241
|
+
paymentTokenAddress: token.address,
|
|
11242
|
+
royaltyMaxBps,
|
|
11243
|
+
startTime,
|
|
11244
|
+
endTime,
|
|
11245
|
+
salt: generateSalt(),
|
|
11246
|
+
counter
|
|
11199
11247
|
},
|
|
11200
|
-
|
|
11201
|
-
start_time: (now + START_TIME_BUFFER_SECS).toString(),
|
|
11202
|
-
end_time: endTime.toString(),
|
|
11203
|
-
salt: generateSalt(),
|
|
11204
|
-
counter
|
|
11205
|
-
};
|
|
11206
|
-
const typedData = stringifyBigInts(
|
|
11207
|
-
build1155OrderTypedData(orderParams, chainId)
|
|
11248
|
+
config
|
|
11208
11249
|
);
|
|
11209
|
-
const
|
|
11210
|
-
const signatureArray = toSignatureArray(signature);
|
|
11211
|
-
const registerPayload = stringifyBigInts({
|
|
11212
|
-
parameters: {
|
|
11213
|
-
...orderParams,
|
|
11214
|
-
offer: {
|
|
11215
|
-
...orderParams.offer,
|
|
11216
|
-
item_type: shortString.encodeShortString(orderParams.offer.item_type)
|
|
11217
|
-
},
|
|
11218
|
-
consideration: {
|
|
11219
|
-
...orderParams.consideration,
|
|
11220
|
-
item_type: shortString.encodeShortString(orderParams.consideration.item_type)
|
|
11221
|
-
}
|
|
11222
|
-
},
|
|
11223
|
-
signature: signatureArray
|
|
11224
|
-
});
|
|
11250
|
+
const signatureArray = toSignatureArray(await account.signMessage(typedData));
|
|
11225
11251
|
const totalWei = BigInt(priceWei) * BigInt(amount);
|
|
11226
11252
|
const amountU256 = cairo.uint256(totalWei.toString());
|
|
11227
11253
|
const approveCall = {
|
|
@@ -11233,9 +11259,12 @@ async function makeOffer1155(account, params, config) {
|
|
|
11233
11259
|
amountU256.high.toString()
|
|
11234
11260
|
]
|
|
11235
11261
|
};
|
|
11236
|
-
const
|
|
11262
|
+
const calls = buildRegister1155Calls(
|
|
11263
|
+
{ orderParams, signature: signatureArray, approvalNeeded: true, approve: approveCall },
|
|
11264
|
+
config
|
|
11265
|
+
);
|
|
11237
11266
|
try {
|
|
11238
|
-
const tx = await account.execute(
|
|
11267
|
+
const tx = await account.execute(calls);
|
|
11239
11268
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
11240
11269
|
return { txHash: tx.transaction_hash };
|
|
11241
11270
|
} catch (err) {
|
|
@@ -12835,94 +12864,147 @@ var StarknetVenue = class {
|
|
|
12835
12864
|
constructor(deps) {
|
|
12836
12865
|
this.deps = deps;
|
|
12837
12866
|
this.chain = "STARKNET";
|
|
12838
|
-
this.m721 = new MarketplaceModule(deps.config);
|
|
12839
|
-
this.m1155 = new Medialane1155Module(deps.config);
|
|
12840
12867
|
}
|
|
12841
|
-
incrementCounter(signer) {
|
|
12842
|
-
return
|
|
12868
|
+
async incrementCounter(signer) {
|
|
12869
|
+
return signer.execute([
|
|
12870
|
+
{ contractAddress: this.deps.config.marketplaceContract, entrypoint: "increment_counter", calldata: [] }
|
|
12871
|
+
]);
|
|
12843
12872
|
}
|
|
12844
12873
|
getOrderDetails(orderRef) {
|
|
12845
|
-
return this.
|
|
12874
|
+
return getOrderDetails(orderRef, this.deps.config);
|
|
12846
12875
|
}
|
|
12847
|
-
getCounter(address) {
|
|
12848
|
-
return this.
|
|
12876
|
+
async getCounter(address) {
|
|
12877
|
+
return this.readCounter(this.deps.config.marketplaceContract, address);
|
|
12849
12878
|
}
|
|
12850
12879
|
async fulfillOrder(signer, orderRef, opts) {
|
|
12851
12880
|
const o = await this.deps.resolveOrder(orderRef);
|
|
12852
12881
|
const quantity = opts?.quantity ?? "1";
|
|
12853
12882
|
const totalPrice = (BigInt(o.unitPrice) * BigInt(quantity)).toString();
|
|
12854
|
-
|
|
12855
|
-
|
|
12856
|
-
orderHash: orderRef,
|
|
12857
|
-
paymentToken: o.paymentToken,
|
|
12858
|
-
totalPrice,
|
|
12859
|
-
quantity
|
|
12860
|
-
});
|
|
12861
|
-
}
|
|
12862
|
-
return this.m721.fulfillOrder(signer, {
|
|
12863
|
-
orderHash: orderRef,
|
|
12864
|
-
paymentToken: o.paymentToken,
|
|
12865
|
-
totalPrice
|
|
12866
|
-
});
|
|
12883
|
+
const calls = o.standard === "ERC1155" ? buildFulfill1155Calls({ orderHash: orderRef, paymentToken: o.paymentToken, totalPrice, quantity }, this.deps.config) : buildFulfillCalls({ orderHash: orderRef, paymentToken: o.paymentToken, totalPrice }, this.deps.config);
|
|
12884
|
+
return signer.execute(calls);
|
|
12867
12885
|
}
|
|
12868
12886
|
async cancelOrder(signer, orderRef) {
|
|
12869
12887
|
const o = await this.deps.resolveOrder(orderRef);
|
|
12870
|
-
|
|
12871
|
-
|
|
12872
|
-
}
|
|
12873
|
-
return
|
|
12888
|
+
const typedData = o.standard === "ERC1155" ? buildCancel1155TypedData(orderRef, signer.address, this.deps.config) : buildCancelTypedData(orderRef, signer.address, this.deps.config);
|
|
12889
|
+
const signature = await signer.signTypedData(typedData);
|
|
12890
|
+
const calls = o.standard === "ERC1155" ? buildCancel1155Calls({ orderHash: orderRef, offerer: signer.address, signature }, this.deps.config) : buildCancelCalls({ orderHash: orderRef, offerer: signer.address, signature }, this.deps.config);
|
|
12891
|
+
return signer.execute(calls);
|
|
12874
12892
|
}
|
|
12875
12893
|
async registerOrder(signer, p) {
|
|
12876
12894
|
const standard = await this.deps.resolveStandard(p.asset.contract);
|
|
12877
|
-
const
|
|
12878
|
-
const humanPrice = formatAmount(p.amount, token.decimals);
|
|
12879
|
-
const durationSeconds = this.durationSeconds(p.endTime);
|
|
12895
|
+
const paymentTokenAddress = resolveToken(p.paymentToken).address;
|
|
12880
12896
|
const royaltyMaxBps = String(p.royaltyMaxBps);
|
|
12897
|
+
const startTime = Math.floor(Date.now() / 1e3) + START_TIME_BUFFER_SECS;
|
|
12898
|
+
const endTime = p.endTime && p.endTime > 0 ? p.endTime : startTime + NO_EXPIRY_SECONDS;
|
|
12881
12899
|
const quantity = p.quantity ?? "1";
|
|
12882
|
-
|
|
12900
|
+
const marketplace = standard === "ERC1155" ? this.deps.config.marketplace1155Contract : this.deps.config.marketplaceContract;
|
|
12901
|
+
const counter = String(await this.readCounter(marketplace, signer.address));
|
|
12902
|
+
let typedData;
|
|
12903
|
+
let buildCalls;
|
|
12883
12904
|
if (standard === "ERC1155") {
|
|
12884
|
-
|
|
12885
|
-
|
|
12905
|
+
const built = (p.side === "listing" ? buildListing1155Order : buildOffer1155Order)(
|
|
12906
|
+
{
|
|
12907
|
+
offerer: signer.address,
|
|
12886
12908
|
nftContract: p.asset.contract,
|
|
12887
12909
|
tokenId: p.asset.tokenId,
|
|
12888
|
-
|
|
12889
|
-
|
|
12890
|
-
|
|
12891
|
-
|
|
12892
|
-
|
|
12893
|
-
|
|
12894
|
-
|
|
12895
|
-
|
|
12896
|
-
|
|
12897
|
-
|
|
12910
|
+
quantity,
|
|
12911
|
+
priceWeiPerUnit: p.amount,
|
|
12912
|
+
paymentTokenAddress,
|
|
12913
|
+
royaltyMaxBps,
|
|
12914
|
+
startTime,
|
|
12915
|
+
endTime,
|
|
12916
|
+
salt: p.salt,
|
|
12917
|
+
counter
|
|
12918
|
+
},
|
|
12919
|
+
this.deps.config
|
|
12920
|
+
);
|
|
12921
|
+
typedData = built.typedData;
|
|
12922
|
+
const approval = p.side === "listing" ? await this.approval1155ForListing(signer.address, p.asset.contract) : this.approvalForErc20(paymentTokenAddress, (BigInt(p.amount) * BigInt(quantity)).toString(), marketplace);
|
|
12923
|
+
buildCalls = (sig) => buildRegister1155Calls({ orderParams: built.orderParams, signature: sig, ...approval }, this.deps.config);
|
|
12924
|
+
} else {
|
|
12925
|
+
const built = (p.side === "listing" ? buildListingOrder : buildOfferOrder)(
|
|
12926
|
+
{
|
|
12927
|
+
offerer: signer.address,
|
|
12898
12928
|
nftContract: p.asset.contract,
|
|
12899
12929
|
tokenId: p.asset.tokenId,
|
|
12900
|
-
|
|
12901
|
-
|
|
12902
|
-
|
|
12903
|
-
|
|
12904
|
-
|
|
12905
|
-
|
|
12906
|
-
|
|
12907
|
-
|
|
12908
|
-
|
|
12909
|
-
|
|
12910
|
-
|
|
12911
|
-
|
|
12912
|
-
|
|
12913
|
-
currency: p.paymentToken,
|
|
12914
|
-
durationSeconds,
|
|
12915
|
-
royaltyMaxBps
|
|
12916
|
-
};
|
|
12917
|
-
const res = p.side === "listing" ? await this.m721.createListing(signer, params) : await this.m721.makeOffer(signer, params);
|
|
12918
|
-
txHash = res.txHash;
|
|
12930
|
+
priceWei: p.amount,
|
|
12931
|
+
paymentTokenAddress,
|
|
12932
|
+
royaltyMaxBps,
|
|
12933
|
+
startTime,
|
|
12934
|
+
endTime,
|
|
12935
|
+
salt: p.salt,
|
|
12936
|
+
counter
|
|
12937
|
+
},
|
|
12938
|
+
this.deps.config
|
|
12939
|
+
);
|
|
12940
|
+
typedData = built.typedData;
|
|
12941
|
+
const approval = p.side === "listing" ? await this.approval721ForListing(signer.address, p.asset.contract, p.asset.tokenId) : this.approvalForErc20(paymentTokenAddress, p.amount, marketplace);
|
|
12942
|
+
buildCalls = (sig) => buildRegisterCalls({ orderParams: built.orderParams, signature: sig, ...approval }, this.deps.config);
|
|
12919
12943
|
}
|
|
12944
|
+
const signature = await signer.signTypedData(typedData);
|
|
12945
|
+
const { txHash } = await signer.execute(buildCalls(signature));
|
|
12920
12946
|
const orderRef = await this.orderRefFromReceipt(txHash);
|
|
12921
12947
|
return { txHash, orderRef };
|
|
12922
12948
|
}
|
|
12923
|
-
|
|
12924
|
-
|
|
12925
|
-
|
|
12949
|
+
// ─── reads (all on deps.provider) ─────────────────────────────────────────
|
|
12950
|
+
async readCounter(marketplace, address) {
|
|
12951
|
+
const res = await this.deps.provider.callContract({
|
|
12952
|
+
contractAddress: marketplace,
|
|
12953
|
+
entrypoint: "get_counter",
|
|
12954
|
+
calldata: [address]
|
|
12955
|
+
});
|
|
12956
|
+
return BigInt(res[0] ?? "0");
|
|
12957
|
+
}
|
|
12958
|
+
/** 721 listing approval: `get_approved(tokenId) == marketplace` ⇒ no approve. */
|
|
12959
|
+
async approval721ForListing(_owner, nftContract, tokenId) {
|
|
12960
|
+
const id = cairo.uint256(tokenId);
|
|
12961
|
+
const approve = {
|
|
12962
|
+
contractAddress: nftContract,
|
|
12963
|
+
entrypoint: "approve",
|
|
12964
|
+
calldata: [this.deps.config.marketplaceContract, id.low.toString(), id.high.toString()]
|
|
12965
|
+
};
|
|
12966
|
+
let approved = false;
|
|
12967
|
+
try {
|
|
12968
|
+
const res = await this.deps.provider.callContract({
|
|
12969
|
+
contractAddress: nftContract,
|
|
12970
|
+
entrypoint: "get_approved",
|
|
12971
|
+
calldata: [id.low.toString(), id.high.toString()]
|
|
12972
|
+
});
|
|
12973
|
+
approved = BigInt(res[0]).toString() === BigInt(this.deps.config.marketplaceContract).toString();
|
|
12974
|
+
} catch {
|
|
12975
|
+
}
|
|
12976
|
+
return { approvalNeeded: !approved, approve };
|
|
12977
|
+
}
|
|
12978
|
+
/** 1155 listing approval: `is_approved_for_all(owner, marketplace)`. */
|
|
12979
|
+
async approval1155ForListing(owner, nftContract) {
|
|
12980
|
+
const approve = {
|
|
12981
|
+
contractAddress: nftContract,
|
|
12982
|
+
entrypoint: "set_approval_for_all",
|
|
12983
|
+
calldata: [this.deps.config.marketplace1155Contract, "1"]
|
|
12984
|
+
};
|
|
12985
|
+
let approved = false;
|
|
12986
|
+
try {
|
|
12987
|
+
const res = await this.deps.provider.callContract({
|
|
12988
|
+
contractAddress: nftContract,
|
|
12989
|
+
entrypoint: "is_approved_for_all",
|
|
12990
|
+
calldata: [owner, this.deps.config.marketplace1155Contract]
|
|
12991
|
+
});
|
|
12992
|
+
approved = BigInt(res[0]) === 1n;
|
|
12993
|
+
} catch {
|
|
12994
|
+
}
|
|
12995
|
+
return { approvalNeeded: !approved, approve };
|
|
12996
|
+
}
|
|
12997
|
+
/** Offers always approve the ERC-20 spend (no read). */
|
|
12998
|
+
approvalForErc20(token, amountWei, marketplace) {
|
|
12999
|
+
const u = cairo.uint256(amountWei);
|
|
13000
|
+
return {
|
|
13001
|
+
approvalNeeded: true,
|
|
13002
|
+
approve: {
|
|
13003
|
+
contractAddress: token,
|
|
13004
|
+
entrypoint: "approve",
|
|
13005
|
+
calldata: [marketplace, u.low.toString(), u.high.toString()]
|
|
13006
|
+
}
|
|
13007
|
+
};
|
|
12926
13008
|
}
|
|
12927
13009
|
/** The canonical Starknet order id = the contract-emitted `OrderCreated`
|
|
12928
13010
|
* hash (`keys[1]`), which is exactly what the indexer stores. */
|