@medialane/sdk 0.59.0 → 0.60.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 +404 -314
- 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 +405 -315
- 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 +423 -341
- 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 +424 -342
- 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 +2 -2
package/dist/index.cjs
CHANGED
|
@@ -11660,6 +11660,94 @@ function getProvider(config) {
|
|
|
11660
11660
|
return p;
|
|
11661
11661
|
}
|
|
11662
11662
|
|
|
11663
|
+
// src/starknet/marketplace/build.ts
|
|
11664
|
+
function contractFor(cfg) {
|
|
11665
|
+
return new starknet.Contract(IPMarketplaceABI, cfg.marketplaceContract, getProvider(cfg));
|
|
11666
|
+
}
|
|
11667
|
+
function buildListingOrder(i, cfg) {
|
|
11668
|
+
const orderParams = {
|
|
11669
|
+
offerer: i.offerer,
|
|
11670
|
+
marketplace: cfg.marketplaceContract,
|
|
11671
|
+
offer: { item_type: "ERC721", token: i.nftContract, identifier_or_criteria: i.tokenId, amount: "1" },
|
|
11672
|
+
consideration: {
|
|
11673
|
+
item_type: "ERC20",
|
|
11674
|
+
token: i.paymentTokenAddress,
|
|
11675
|
+
identifier_or_criteria: "0",
|
|
11676
|
+
amount: i.priceWei,
|
|
11677
|
+
recipient: i.offerer
|
|
11678
|
+
},
|
|
11679
|
+
royalty_max_bps: i.royaltyMaxBps,
|
|
11680
|
+
start_time: String(i.startTime),
|
|
11681
|
+
end_time: String(i.endTime),
|
|
11682
|
+
salt: i.salt,
|
|
11683
|
+
counter: i.counter
|
|
11684
|
+
};
|
|
11685
|
+
const typedData = stringifyBigInts(buildOrderTypedData(orderParams, getChainId(cfg)));
|
|
11686
|
+
return { orderParams, typedData };
|
|
11687
|
+
}
|
|
11688
|
+
function buildOfferOrder(i, cfg) {
|
|
11689
|
+
const orderParams = {
|
|
11690
|
+
offerer: i.offerer,
|
|
11691
|
+
marketplace: cfg.marketplaceContract,
|
|
11692
|
+
offer: { item_type: "ERC20", token: i.paymentTokenAddress, identifier_or_criteria: "0", amount: i.priceWei },
|
|
11693
|
+
consideration: {
|
|
11694
|
+
item_type: "ERC721",
|
|
11695
|
+
token: i.nftContract,
|
|
11696
|
+
identifier_or_criteria: i.tokenId,
|
|
11697
|
+
amount: "1",
|
|
11698
|
+
recipient: i.offerer
|
|
11699
|
+
},
|
|
11700
|
+
royalty_max_bps: i.royaltyMaxBps,
|
|
11701
|
+
start_time: String(i.startTime),
|
|
11702
|
+
end_time: String(i.endTime),
|
|
11703
|
+
salt: i.salt,
|
|
11704
|
+
counter: i.counter
|
|
11705
|
+
};
|
|
11706
|
+
const typedData = stringifyBigInts(buildOrderTypedData(orderParams, getChainId(cfg)));
|
|
11707
|
+
return { orderParams, typedData };
|
|
11708
|
+
}
|
|
11709
|
+
function registerPayload(orderParams, signature) {
|
|
11710
|
+
return stringifyBigInts({
|
|
11711
|
+
parameters: {
|
|
11712
|
+
...orderParams,
|
|
11713
|
+
offer: { ...orderParams.offer, item_type: starknet.shortString.encodeShortString(orderParams.offer.item_type) },
|
|
11714
|
+
consideration: {
|
|
11715
|
+
...orderParams.consideration,
|
|
11716
|
+
item_type: starknet.shortString.encodeShortString(orderParams.consideration.item_type)
|
|
11717
|
+
}
|
|
11718
|
+
},
|
|
11719
|
+
signature
|
|
11720
|
+
});
|
|
11721
|
+
}
|
|
11722
|
+
function buildRegisterCalls(a, cfg) {
|
|
11723
|
+
const registerCall = contractFor(cfg).populate("register_order", [registerPayload(a.orderParams, a.signature)]);
|
|
11724
|
+
return a.approvalNeeded ? [a.approve, registerCall] : [registerCall];
|
|
11725
|
+
}
|
|
11726
|
+
function buildFulfillCalls(a, cfg) {
|
|
11727
|
+
const u = starknet.cairo.uint256(a.totalPrice);
|
|
11728
|
+
const approve = {
|
|
11729
|
+
contractAddress: a.paymentToken,
|
|
11730
|
+
entrypoint: "approve",
|
|
11731
|
+
calldata: [cfg.marketplaceContract, u.low.toString(), u.high.toString()]
|
|
11732
|
+
};
|
|
11733
|
+
const fulfill = contractFor(cfg).populate("fulfill_order", [a.orderHash]);
|
|
11734
|
+
const fee = buildFeeCall(
|
|
11735
|
+
{ surface: "marketplace", token: a.paymentToken, grossAmount: BigInt(a.totalPrice) },
|
|
11736
|
+
cfg.feeConfig
|
|
11737
|
+
);
|
|
11738
|
+
return fee ? [approve, fulfill, fee] : [approve, fulfill];
|
|
11739
|
+
}
|
|
11740
|
+
function buildCancelCalls(a, cfg) {
|
|
11741
|
+
const cancelRequest = stringifyBigInts({
|
|
11742
|
+
cancelation: { order_hash: a.orderHash, offerer: a.offerer },
|
|
11743
|
+
signature: a.signature
|
|
11744
|
+
});
|
|
11745
|
+
return [contractFor(cfg).populate("cancel_order", [cancelRequest])];
|
|
11746
|
+
}
|
|
11747
|
+
function buildCancelTypedData(orderHash, offerer, cfg) {
|
|
11748
|
+
return stringifyBigInts(buildCancellationTypedData({ order_hash: orderHash, offerer }, getChainId(cfg)));
|
|
11749
|
+
}
|
|
11750
|
+
|
|
11663
11751
|
// src/starknet/marketplace/orders.ts
|
|
11664
11752
|
var _contractCache = /* @__PURE__ */ new WeakMap();
|
|
11665
11753
|
function makeContract(config) {
|
|
@@ -11684,46 +11772,22 @@ async function createListing(account, params, config) {
|
|
|
11684
11772
|
const endTime = now + durationSeconds;
|
|
11685
11773
|
const counter = (await contract.get_counter(account.address)).toString();
|
|
11686
11774
|
const royaltyMaxBps = await resolveRoyaltyMaxBps(provider, nftContract, tokenId, params.royaltyMaxBps);
|
|
11687
|
-
const orderParams =
|
|
11688
|
-
|
|
11689
|
-
|
|
11690
|
-
|
|
11691
|
-
|
|
11692
|
-
|
|
11693
|
-
|
|
11694
|
-
|
|
11695
|
-
|
|
11696
|
-
|
|
11697
|
-
|
|
11698
|
-
|
|
11699
|
-
identifier_or_criteria: "0",
|
|
11700
|
-
amount: priceWei,
|
|
11701
|
-
recipient: account.address
|
|
11702
|
-
},
|
|
11703
|
-
royalty_max_bps: royaltyMaxBps,
|
|
11704
|
-
start_time: startTime.toString(),
|
|
11705
|
-
end_time: endTime.toString(),
|
|
11706
|
-
salt: generateSalt(),
|
|
11707
|
-
counter
|
|
11708
|
-
};
|
|
11709
|
-
const chainId = getChainId(config);
|
|
11710
|
-
const typedData = stringifyBigInts(buildOrderTypedData(orderParams, chainId));
|
|
11711
|
-
const signature = await account.signMessage(typedData);
|
|
11712
|
-
const signatureArray = toSignatureArray(signature);
|
|
11713
|
-
const registerPayload = stringifyBigInts({
|
|
11714
|
-
parameters: {
|
|
11715
|
-
...orderParams,
|
|
11716
|
-
offer: {
|
|
11717
|
-
...orderParams.offer,
|
|
11718
|
-
item_type: starknet.shortString.encodeShortString(orderParams.offer.item_type)
|
|
11719
|
-
},
|
|
11720
|
-
consideration: {
|
|
11721
|
-
...orderParams.consideration,
|
|
11722
|
-
item_type: starknet.shortString.encodeShortString(orderParams.consideration.item_type)
|
|
11723
|
-
}
|
|
11775
|
+
const { orderParams, typedData } = buildListingOrder(
|
|
11776
|
+
{
|
|
11777
|
+
offerer: account.address,
|
|
11778
|
+
nftContract,
|
|
11779
|
+
tokenId,
|
|
11780
|
+
priceWei,
|
|
11781
|
+
paymentTokenAddress: token.address,
|
|
11782
|
+
royaltyMaxBps,
|
|
11783
|
+
startTime,
|
|
11784
|
+
endTime,
|
|
11785
|
+
salt: generateSalt(),
|
|
11786
|
+
counter
|
|
11724
11787
|
},
|
|
11725
|
-
|
|
11726
|
-
|
|
11788
|
+
config
|
|
11789
|
+
);
|
|
11790
|
+
const signatureArray = toSignatureArray(await account.signMessage(typedData));
|
|
11727
11791
|
const tokenIdUint256 = starknet.cairo.uint256(tokenId);
|
|
11728
11792
|
let isAlreadyApproved = false;
|
|
11729
11793
|
try {
|
|
@@ -11735,19 +11799,19 @@ async function createListing(account, params, config) {
|
|
|
11735
11799
|
isAlreadyApproved = BigInt(result[0]).toString() === BigInt(config.marketplaceContract).toString();
|
|
11736
11800
|
} catch {
|
|
11737
11801
|
}
|
|
11738
|
-
const
|
|
11739
|
-
|
|
11740
|
-
|
|
11741
|
-
|
|
11742
|
-
|
|
11743
|
-
|
|
11744
|
-
|
|
11745
|
-
|
|
11746
|
-
|
|
11747
|
-
|
|
11748
|
-
},
|
|
11749
|
-
|
|
11750
|
-
|
|
11802
|
+
const approve = {
|
|
11803
|
+
contractAddress: nftContract,
|
|
11804
|
+
entrypoint: "approve",
|
|
11805
|
+
calldata: [
|
|
11806
|
+
config.marketplaceContract,
|
|
11807
|
+
tokenIdUint256.low.toString(),
|
|
11808
|
+
tokenIdUint256.high.toString()
|
|
11809
|
+
]
|
|
11810
|
+
};
|
|
11811
|
+
const calls = buildRegisterCalls(
|
|
11812
|
+
{ orderParams, signature: signatureArray, approvalNeeded: !isAlreadyApproved, approve },
|
|
11813
|
+
config
|
|
11814
|
+
);
|
|
11751
11815
|
try {
|
|
11752
11816
|
const tx = await account.execute(calls);
|
|
11753
11817
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
@@ -11766,46 +11830,22 @@ async function makeOffer(account, params, config) {
|
|
|
11766
11830
|
const endTime = now + durationSeconds;
|
|
11767
11831
|
const counter = (await contract.get_counter(account.address)).toString();
|
|
11768
11832
|
const royaltyMaxBps = await resolveRoyaltyMaxBps(provider, nftContract, tokenId, params.royaltyMaxBps);
|
|
11769
|
-
const orderParams =
|
|
11770
|
-
|
|
11771
|
-
|
|
11772
|
-
|
|
11773
|
-
|
|
11774
|
-
|
|
11775
|
-
|
|
11776
|
-
|
|
11777
|
-
|
|
11778
|
-
|
|
11779
|
-
|
|
11780
|
-
|
|
11781
|
-
identifier_or_criteria: tokenId,
|
|
11782
|
-
amount: "1",
|
|
11783
|
-
recipient: account.address
|
|
11784
|
-
},
|
|
11785
|
-
royalty_max_bps: royaltyMaxBps,
|
|
11786
|
-
start_time: startTime.toString(),
|
|
11787
|
-
end_time: endTime.toString(),
|
|
11788
|
-
salt: generateSalt(),
|
|
11789
|
-
counter
|
|
11790
|
-
};
|
|
11791
|
-
const chainId = getChainId(config);
|
|
11792
|
-
const typedData = stringifyBigInts(buildOrderTypedData(orderParams, chainId));
|
|
11793
|
-
const signature = await account.signMessage(typedData);
|
|
11794
|
-
const signatureArray = toSignatureArray(signature);
|
|
11795
|
-
const registerPayload = stringifyBigInts({
|
|
11796
|
-
parameters: {
|
|
11797
|
-
...orderParams,
|
|
11798
|
-
offer: {
|
|
11799
|
-
...orderParams.offer,
|
|
11800
|
-
item_type: starknet.shortString.encodeShortString(orderParams.offer.item_type)
|
|
11801
|
-
},
|
|
11802
|
-
consideration: {
|
|
11803
|
-
...orderParams.consideration,
|
|
11804
|
-
item_type: starknet.shortString.encodeShortString(orderParams.consideration.item_type)
|
|
11805
|
-
}
|
|
11833
|
+
const { orderParams, typedData } = buildOfferOrder(
|
|
11834
|
+
{
|
|
11835
|
+
offerer: account.address,
|
|
11836
|
+
nftContract,
|
|
11837
|
+
tokenId,
|
|
11838
|
+
priceWei,
|
|
11839
|
+
paymentTokenAddress: token.address,
|
|
11840
|
+
royaltyMaxBps,
|
|
11841
|
+
startTime,
|
|
11842
|
+
endTime,
|
|
11843
|
+
salt: generateSalt(),
|
|
11844
|
+
counter
|
|
11806
11845
|
},
|
|
11807
|
-
|
|
11808
|
-
|
|
11846
|
+
config
|
|
11847
|
+
);
|
|
11848
|
+
const signatureArray = toSignatureArray(await account.signMessage(typedData));
|
|
11809
11849
|
const amountUint256 = starknet.cairo.uint256(priceWei);
|
|
11810
11850
|
const approveCall = {
|
|
11811
11851
|
contractAddress: token.address,
|
|
@@ -11816,9 +11856,12 @@ async function makeOffer(account, params, config) {
|
|
|
11816
11856
|
amountUint256.high.toString()
|
|
11817
11857
|
]
|
|
11818
11858
|
};
|
|
11819
|
-
const
|
|
11859
|
+
const calls = buildRegisterCalls(
|
|
11860
|
+
{ orderParams, signature: signatureArray, approvalNeeded: true, approve: approveCall },
|
|
11861
|
+
config
|
|
11862
|
+
);
|
|
11820
11863
|
try {
|
|
11821
|
-
const tx = await account.execute(
|
|
11864
|
+
const tx = await account.execute(calls);
|
|
11822
11865
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
11823
11866
|
return { txHash: tx.transaction_hash };
|
|
11824
11867
|
} catch (err) {
|
|
@@ -11827,23 +11870,8 @@ async function makeOffer(account, params, config) {
|
|
|
11827
11870
|
}
|
|
11828
11871
|
async function fulfillOrder(account, params, config) {
|
|
11829
11872
|
const { orderHash, paymentToken, totalPrice } = params;
|
|
11830
|
-
const {
|
|
11831
|
-
const
|
|
11832
|
-
const approveCall = {
|
|
11833
|
-
contractAddress: paymentToken,
|
|
11834
|
-
entrypoint: "approve",
|
|
11835
|
-
calldata: [
|
|
11836
|
-
config.marketplaceContract,
|
|
11837
|
-
totalPriceU256.low.toString(),
|
|
11838
|
-
totalPriceU256.high.toString()
|
|
11839
|
-
]
|
|
11840
|
-
};
|
|
11841
|
-
const fulfillCall = contract.populate("fulfill_order", [orderHash]);
|
|
11842
|
-
const feeCall = buildFeeCall(
|
|
11843
|
-
{ surface: "marketplace", token: paymentToken, grossAmount: BigInt(totalPrice) },
|
|
11844
|
-
config.feeConfig
|
|
11845
|
-
);
|
|
11846
|
-
const calls = feeCall ? [approveCall, fulfillCall, feeCall] : [approveCall, fulfillCall];
|
|
11873
|
+
const { provider } = makeContract(config);
|
|
11874
|
+
const calls = buildFulfillCalls({ orderHash, paymentToken, totalPrice }, config);
|
|
11847
11875
|
try {
|
|
11848
11876
|
const tx = await account.execute(calls);
|
|
11849
11877
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
@@ -11854,24 +11882,12 @@ async function fulfillOrder(account, params, config) {
|
|
|
11854
11882
|
}
|
|
11855
11883
|
async function cancelOrder(account, params, config) {
|
|
11856
11884
|
const { orderHash } = params;
|
|
11857
|
-
const {
|
|
11858
|
-
const
|
|
11859
|
-
const
|
|
11860
|
-
|
|
11861
|
-
offerer: account.address
|
|
11862
|
-
};
|
|
11863
|
-
const typedData = stringifyBigInts(
|
|
11864
|
-
buildCancellationTypedData(cancelParams, chainId)
|
|
11865
|
-
);
|
|
11866
|
-
const signature = await account.signMessage(typedData);
|
|
11867
|
-
const signatureArray = toSignatureArray(signature);
|
|
11868
|
-
const cancelRequest = stringifyBigInts({
|
|
11869
|
-
cancelation: cancelParams,
|
|
11870
|
-
signature: signatureArray
|
|
11871
|
-
});
|
|
11872
|
-
const call = contract.populate("cancel_order", [cancelRequest]);
|
|
11885
|
+
const { provider } = makeContract(config);
|
|
11886
|
+
const typedData = buildCancelTypedData(orderHash, account.address, config);
|
|
11887
|
+
const signatureArray = toSignatureArray(await account.signMessage(typedData));
|
|
11888
|
+
const calls = buildCancelCalls({ orderHash, offerer: account.address, signature: signatureArray }, config);
|
|
11873
11889
|
try {
|
|
11874
|
-
const tx = await account.execute(
|
|
11890
|
+
const tx = await account.execute(calls);
|
|
11875
11891
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
11876
11892
|
return { txHash: tx.transaction_hash };
|
|
11877
11893
|
} catch (err) {
|
|
@@ -12018,6 +12034,100 @@ var MarketplaceModule = class {
|
|
|
12018
12034
|
return buildCancellationTypedData(params, chainId);
|
|
12019
12035
|
}
|
|
12020
12036
|
};
|
|
12037
|
+
function contractFor2(cfg) {
|
|
12038
|
+
return new starknet.Contract(Medialane1155ABI, cfg.marketplace1155Contract, getProvider(cfg));
|
|
12039
|
+
}
|
|
12040
|
+
function buildListing1155Order(i, cfg) {
|
|
12041
|
+
const orderParams = {
|
|
12042
|
+
offerer: i.offerer,
|
|
12043
|
+
marketplace: cfg.marketplace1155Contract,
|
|
12044
|
+
offer: { item_type: "ERC1155", token: i.nftContract, identifier_or_criteria: i.tokenId, amount: i.quantity },
|
|
12045
|
+
consideration: {
|
|
12046
|
+
item_type: "ERC20",
|
|
12047
|
+
token: i.paymentTokenAddress,
|
|
12048
|
+
identifier_or_criteria: "0",
|
|
12049
|
+
amount: i.priceWeiPerUnit,
|
|
12050
|
+
recipient: i.offerer
|
|
12051
|
+
},
|
|
12052
|
+
royalty_max_bps: i.royaltyMaxBps,
|
|
12053
|
+
start_time: String(i.startTime),
|
|
12054
|
+
end_time: String(i.endTime),
|
|
12055
|
+
salt: i.salt,
|
|
12056
|
+
counter: i.counter
|
|
12057
|
+
};
|
|
12058
|
+
const typedData = stringifyBigInts(
|
|
12059
|
+
build1155OrderTypedData(orderParams, getChainId(cfg))
|
|
12060
|
+
);
|
|
12061
|
+
return { orderParams, typedData };
|
|
12062
|
+
}
|
|
12063
|
+
function buildOffer1155Order(i, cfg) {
|
|
12064
|
+
const orderParams = {
|
|
12065
|
+
offerer: i.offerer,
|
|
12066
|
+
marketplace: cfg.marketplace1155Contract,
|
|
12067
|
+
offer: { item_type: "ERC20", token: i.paymentTokenAddress, identifier_or_criteria: "0", amount: i.priceWeiPerUnit },
|
|
12068
|
+
consideration: {
|
|
12069
|
+
item_type: "ERC1155",
|
|
12070
|
+
token: i.nftContract,
|
|
12071
|
+
identifier_or_criteria: i.tokenId,
|
|
12072
|
+
amount: i.quantity,
|
|
12073
|
+
recipient: i.offerer
|
|
12074
|
+
},
|
|
12075
|
+
royalty_max_bps: i.royaltyMaxBps,
|
|
12076
|
+
start_time: String(i.startTime),
|
|
12077
|
+
end_time: String(i.endTime),
|
|
12078
|
+
salt: i.salt,
|
|
12079
|
+
counter: i.counter
|
|
12080
|
+
};
|
|
12081
|
+
const typedData = stringifyBigInts(
|
|
12082
|
+
build1155OrderTypedData(orderParams, getChainId(cfg))
|
|
12083
|
+
);
|
|
12084
|
+
return { orderParams, typedData };
|
|
12085
|
+
}
|
|
12086
|
+
function registerPayload2(orderParams, signature) {
|
|
12087
|
+
return stringifyBigInts({
|
|
12088
|
+
parameters: {
|
|
12089
|
+
...orderParams,
|
|
12090
|
+
offer: { ...orderParams.offer, item_type: starknet.shortString.encodeShortString(orderParams.offer.item_type) },
|
|
12091
|
+
consideration: {
|
|
12092
|
+
...orderParams.consideration,
|
|
12093
|
+
item_type: starknet.shortString.encodeShortString(orderParams.consideration.item_type)
|
|
12094
|
+
}
|
|
12095
|
+
},
|
|
12096
|
+
signature
|
|
12097
|
+
});
|
|
12098
|
+
}
|
|
12099
|
+
function buildRegister1155Calls(a, cfg) {
|
|
12100
|
+
const registerCall = contractFor2(cfg).populate("register_order", [registerPayload2(a.orderParams, a.signature)]);
|
|
12101
|
+
return a.approvalNeeded ? [a.approve, registerCall] : [registerCall];
|
|
12102
|
+
}
|
|
12103
|
+
function buildFulfill1155Calls(a, cfg) {
|
|
12104
|
+
const u = starknet.cairo.uint256(a.totalPrice);
|
|
12105
|
+
const approve = {
|
|
12106
|
+
contractAddress: a.paymentToken,
|
|
12107
|
+
entrypoint: "approve",
|
|
12108
|
+
calldata: [cfg.marketplace1155Contract, u.low.toString(), u.high.toString()]
|
|
12109
|
+
};
|
|
12110
|
+
const fulfill = contractFor2(cfg).populate("fulfill_order", [a.orderHash, a.quantity]);
|
|
12111
|
+
const fee = buildFeeCall(
|
|
12112
|
+
{ surface: "marketplace", token: a.paymentToken, grossAmount: BigInt(a.totalPrice) },
|
|
12113
|
+
cfg.feeConfig
|
|
12114
|
+
);
|
|
12115
|
+
return fee ? [approve, fulfill, fee] : [approve, fulfill];
|
|
12116
|
+
}
|
|
12117
|
+
function buildCancel1155Calls(a, cfg) {
|
|
12118
|
+
const cancelPayload = stringifyBigInts({
|
|
12119
|
+
cancelation: { order_hash: a.orderHash, offerer: a.offerer },
|
|
12120
|
+
signature: a.signature
|
|
12121
|
+
});
|
|
12122
|
+
return [contractFor2(cfg).populate("cancel_order", [cancelPayload])];
|
|
12123
|
+
}
|
|
12124
|
+
function buildCancel1155TypedData(orderHash, offerer, cfg) {
|
|
12125
|
+
return stringifyBigInts(
|
|
12126
|
+
build1155CancellationTypedData({ order_hash: orderHash, offerer }, getChainId(cfg))
|
|
12127
|
+
);
|
|
12128
|
+
}
|
|
12129
|
+
|
|
12130
|
+
// src/starknet/marketplace1155/orders.ts
|
|
12021
12131
|
var _contractCache2 = /* @__PURE__ */ new WeakMap();
|
|
12022
12132
|
function getContract(config) {
|
|
12023
12133
|
let c = _contractCache2.get(config);
|
|
@@ -12046,53 +12156,27 @@ async function createListing1155(account, params, config) {
|
|
|
12046
12156
|
const token = resolveToken(currency);
|
|
12047
12157
|
const priceWei = parseAmount(pricePerUnit, token.decimals);
|
|
12048
12158
|
const now = Math.floor(Date.now() / 1e3);
|
|
12159
|
+
const startTime = now + START_TIME_BUFFER_SECS;
|
|
12049
12160
|
const endTime = now + durationSeconds;
|
|
12050
|
-
const chainId = getChainId(config);
|
|
12051
12161
|
const counter = (await contract.get_counter(account.address)).toString();
|
|
12052
12162
|
const royaltyMaxBps = await resolveRoyaltyMaxBps(provider, nftContract, tokenId, params.royaltyMaxBps);
|
|
12053
|
-
const orderParams =
|
|
12054
|
-
|
|
12055
|
-
|
|
12056
|
-
|
|
12057
|
-
|
|
12058
|
-
|
|
12059
|
-
|
|
12060
|
-
|
|
12061
|
-
|
|
12062
|
-
|
|
12063
|
-
|
|
12064
|
-
|
|
12065
|
-
|
|
12066
|
-
identifier_or_criteria: "0",
|
|
12067
|
-
amount: priceWei,
|
|
12068
|
-
// payment leg amount = price PER UNIT
|
|
12069
|
-
recipient: account.address
|
|
12163
|
+
const { orderParams, typedData } = buildListing1155Order(
|
|
12164
|
+
{
|
|
12165
|
+
offerer: account.address,
|
|
12166
|
+
nftContract,
|
|
12167
|
+
tokenId,
|
|
12168
|
+
quantity: amount,
|
|
12169
|
+
priceWeiPerUnit: priceWei,
|
|
12170
|
+
paymentTokenAddress: token.address,
|
|
12171
|
+
royaltyMaxBps,
|
|
12172
|
+
startTime,
|
|
12173
|
+
endTime,
|
|
12174
|
+
salt: generateSalt(),
|
|
12175
|
+
counter
|
|
12070
12176
|
},
|
|
12071
|
-
|
|
12072
|
-
start_time: (now + START_TIME_BUFFER_SECS).toString(),
|
|
12073
|
-
end_time: endTime.toString(),
|
|
12074
|
-
salt: generateSalt(),
|
|
12075
|
-
counter
|
|
12076
|
-
};
|
|
12077
|
-
const typedData = stringifyBigInts(
|
|
12078
|
-
build1155OrderTypedData(orderParams, chainId)
|
|
12177
|
+
config
|
|
12079
12178
|
);
|
|
12080
|
-
const
|
|
12081
|
-
const signatureArray = toSignatureArray(signature);
|
|
12082
|
-
const orderPayload = stringifyBigInts({
|
|
12083
|
-
parameters: {
|
|
12084
|
-
...orderParams,
|
|
12085
|
-
offer: {
|
|
12086
|
-
...orderParams.offer,
|
|
12087
|
-
item_type: starknet.shortString.encodeShortString(orderParams.offer.item_type)
|
|
12088
|
-
},
|
|
12089
|
-
consideration: {
|
|
12090
|
-
...orderParams.consideration,
|
|
12091
|
-
item_type: starknet.shortString.encodeShortString(orderParams.consideration.item_type)
|
|
12092
|
-
}
|
|
12093
|
-
},
|
|
12094
|
-
signature: signatureArray
|
|
12095
|
-
});
|
|
12179
|
+
const signatureArray = toSignatureArray(await account.signMessage(typedData));
|
|
12096
12180
|
let isApproved = false;
|
|
12097
12181
|
try {
|
|
12098
12182
|
const result = await provider.callContract({
|
|
@@ -12103,15 +12187,15 @@ async function createListing1155(account, params, config) {
|
|
|
12103
12187
|
isApproved = BigInt(result[0]) === 1n;
|
|
12104
12188
|
} catch {
|
|
12105
12189
|
}
|
|
12106
|
-
const
|
|
12107
|
-
|
|
12108
|
-
|
|
12109
|
-
|
|
12110
|
-
|
|
12111
|
-
|
|
12112
|
-
},
|
|
12113
|
-
|
|
12114
|
-
|
|
12190
|
+
const approve = {
|
|
12191
|
+
contractAddress: nftContract,
|
|
12192
|
+
entrypoint: "set_approval_for_all",
|
|
12193
|
+
calldata: [config.marketplace1155Contract, "1"]
|
|
12194
|
+
};
|
|
12195
|
+
const calls = buildRegister1155Calls(
|
|
12196
|
+
{ orderParams, signature: signatureArray, approvalNeeded: !isApproved, approve },
|
|
12197
|
+
config
|
|
12198
|
+
);
|
|
12115
12199
|
try {
|
|
12116
12200
|
const tx = await account.execute(calls);
|
|
12117
12201
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
@@ -12122,21 +12206,10 @@ async function createListing1155(account, params, config) {
|
|
|
12122
12206
|
}
|
|
12123
12207
|
async function fulfillOrder1155(account, params, config) {
|
|
12124
12208
|
const { orderHash, paymentToken, totalPrice, quantity = "1" } = params;
|
|
12125
|
-
const contract = getContract(config);
|
|
12126
12209
|
const provider = getProvider(config);
|
|
12127
|
-
const
|
|
12128
|
-
const approveCall = {
|
|
12129
|
-
contractAddress: paymentToken,
|
|
12130
|
-
entrypoint: "approve",
|
|
12131
|
-
calldata: [
|
|
12132
|
-
config.marketplace1155Contract,
|
|
12133
|
-
totalPriceU256.low.toString(),
|
|
12134
|
-
totalPriceU256.high.toString()
|
|
12135
|
-
]
|
|
12136
|
-
};
|
|
12137
|
-
const fulfillCall = contract.populate("fulfill_order", [orderHash, quantity]);
|
|
12210
|
+
const calls = buildFulfill1155Calls({ orderHash, paymentToken, totalPrice, quantity }, config);
|
|
12138
12211
|
try {
|
|
12139
|
-
const tx = await account.execute(
|
|
12212
|
+
const tx = await account.execute(calls);
|
|
12140
12213
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
12141
12214
|
return { txHash: tx.transaction_hash };
|
|
12142
12215
|
} catch (err) {
|
|
@@ -12145,25 +12218,12 @@ async function fulfillOrder1155(account, params, config) {
|
|
|
12145
12218
|
}
|
|
12146
12219
|
async function cancelOrder1155(account, params, config) {
|
|
12147
12220
|
const { orderHash } = params;
|
|
12148
|
-
const contract = getContract(config);
|
|
12149
12221
|
const provider = getProvider(config);
|
|
12150
|
-
const
|
|
12151
|
-
const
|
|
12152
|
-
|
|
12153
|
-
offerer: account.address
|
|
12154
|
-
};
|
|
12155
|
-
const typedData = stringifyBigInts(
|
|
12156
|
-
build1155CancellationTypedData(cancelParams, chainId)
|
|
12157
|
-
);
|
|
12158
|
-
const signature = await account.signMessage(typedData);
|
|
12159
|
-
const signatureArray = toSignatureArray(signature);
|
|
12160
|
-
const cancelPayload = stringifyBigInts({
|
|
12161
|
-
cancelation: cancelParams,
|
|
12162
|
-
signature: signatureArray
|
|
12163
|
-
});
|
|
12164
|
-
const cancelCall = contract.populate("cancel_order", [cancelPayload]);
|
|
12222
|
+
const typedData = buildCancel1155TypedData(orderHash, account.address, config);
|
|
12223
|
+
const signatureArray = toSignatureArray(await account.signMessage(typedData));
|
|
12224
|
+
const calls = buildCancel1155Calls({ orderHash, offerer: account.address, signature: signatureArray }, config);
|
|
12165
12225
|
try {
|
|
12166
|
-
const tx = await account.execute(
|
|
12226
|
+
const tx = await account.execute(calls);
|
|
12167
12227
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
12168
12228
|
return { txHash: tx.transaction_hash };
|
|
12169
12229
|
} catch (err) {
|
|
@@ -12181,56 +12241,30 @@ async function makeOffer1155(account, params, config) {
|
|
|
12181
12241
|
} = params;
|
|
12182
12242
|
const contract = getContract(config);
|
|
12183
12243
|
const provider = getProvider(config);
|
|
12184
|
-
const chainId = getChainId(config);
|
|
12185
12244
|
const token = resolveToken(currency);
|
|
12186
12245
|
const priceWei = parseAmount(price, token.decimals);
|
|
12187
12246
|
const now = Math.floor(Date.now() / 1e3);
|
|
12247
|
+
const startTime = now + START_TIME_BUFFER_SECS;
|
|
12188
12248
|
const endTime = now + durationSeconds;
|
|
12189
12249
|
const counter = (await contract.get_counter(account.address)).toString();
|
|
12190
12250
|
const royaltyMaxBps = await resolveRoyaltyMaxBps(provider, nftContract, tokenId, params.royaltyMaxBps);
|
|
12191
|
-
const orderParams =
|
|
12192
|
-
|
|
12193
|
-
|
|
12194
|
-
|
|
12195
|
-
|
|
12196
|
-
|
|
12197
|
-
|
|
12198
|
-
|
|
12199
|
-
|
|
12200
|
-
|
|
12201
|
-
|
|
12202
|
-
|
|
12203
|
-
|
|
12204
|
-
identifier_or_criteria: tokenId,
|
|
12205
|
-
amount,
|
|
12206
|
-
// unit quantity
|
|
12207
|
-
recipient: account.address
|
|
12251
|
+
const { orderParams, typedData } = buildOffer1155Order(
|
|
12252
|
+
{
|
|
12253
|
+
offerer: account.address,
|
|
12254
|
+
nftContract,
|
|
12255
|
+
tokenId,
|
|
12256
|
+
quantity: amount,
|
|
12257
|
+
priceWeiPerUnit: priceWei,
|
|
12258
|
+
paymentTokenAddress: token.address,
|
|
12259
|
+
royaltyMaxBps,
|
|
12260
|
+
startTime,
|
|
12261
|
+
endTime,
|
|
12262
|
+
salt: generateSalt(),
|
|
12263
|
+
counter
|
|
12208
12264
|
},
|
|
12209
|
-
|
|
12210
|
-
start_time: (now + START_TIME_BUFFER_SECS).toString(),
|
|
12211
|
-
end_time: endTime.toString(),
|
|
12212
|
-
salt: generateSalt(),
|
|
12213
|
-
counter
|
|
12214
|
-
};
|
|
12215
|
-
const typedData = stringifyBigInts(
|
|
12216
|
-
build1155OrderTypedData(orderParams, chainId)
|
|
12265
|
+
config
|
|
12217
12266
|
);
|
|
12218
|
-
const
|
|
12219
|
-
const signatureArray = toSignatureArray(signature);
|
|
12220
|
-
const registerPayload = stringifyBigInts({
|
|
12221
|
-
parameters: {
|
|
12222
|
-
...orderParams,
|
|
12223
|
-
offer: {
|
|
12224
|
-
...orderParams.offer,
|
|
12225
|
-
item_type: starknet.shortString.encodeShortString(orderParams.offer.item_type)
|
|
12226
|
-
},
|
|
12227
|
-
consideration: {
|
|
12228
|
-
...orderParams.consideration,
|
|
12229
|
-
item_type: starknet.shortString.encodeShortString(orderParams.consideration.item_type)
|
|
12230
|
-
}
|
|
12231
|
-
},
|
|
12232
|
-
signature: signatureArray
|
|
12233
|
-
});
|
|
12267
|
+
const signatureArray = toSignatureArray(await account.signMessage(typedData));
|
|
12234
12268
|
const totalWei = BigInt(priceWei) * BigInt(amount);
|
|
12235
12269
|
const amountU256 = starknet.cairo.uint256(totalWei.toString());
|
|
12236
12270
|
const approveCall = {
|
|
@@ -12242,9 +12276,12 @@ async function makeOffer1155(account, params, config) {
|
|
|
12242
12276
|
amountU256.high.toString()
|
|
12243
12277
|
]
|
|
12244
12278
|
};
|
|
12245
|
-
const
|
|
12279
|
+
const calls = buildRegister1155Calls(
|
|
12280
|
+
{ orderParams, signature: signatureArray, approvalNeeded: true, approve: approveCall },
|
|
12281
|
+
config
|
|
12282
|
+
);
|
|
12246
12283
|
try {
|
|
12247
|
-
const tx = await account.execute(
|
|
12284
|
+
const tx = await account.execute(calls);
|
|
12248
12285
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
12249
12286
|
return { txHash: tx.transaction_hash };
|
|
12250
12287
|
} catch (err) {
|
|
@@ -13116,94 +13153,147 @@ var StarknetVenue = class {
|
|
|
13116
13153
|
constructor(deps) {
|
|
13117
13154
|
this.deps = deps;
|
|
13118
13155
|
this.chain = "STARKNET";
|
|
13119
|
-
this.m721 = new MarketplaceModule(deps.config);
|
|
13120
|
-
this.m1155 = new Medialane1155Module(deps.config);
|
|
13121
13156
|
}
|
|
13122
|
-
incrementCounter(signer) {
|
|
13123
|
-
return
|
|
13157
|
+
async incrementCounter(signer) {
|
|
13158
|
+
return signer.execute([
|
|
13159
|
+
{ contractAddress: this.deps.config.marketplaceContract, entrypoint: "increment_counter", calldata: [] }
|
|
13160
|
+
]);
|
|
13124
13161
|
}
|
|
13125
13162
|
getOrderDetails(orderRef) {
|
|
13126
|
-
return this.
|
|
13163
|
+
return getOrderDetails(orderRef, this.deps.config);
|
|
13127
13164
|
}
|
|
13128
|
-
getCounter(address) {
|
|
13129
|
-
return this.
|
|
13165
|
+
async getCounter(address) {
|
|
13166
|
+
return this.readCounter(this.deps.config.marketplaceContract, address);
|
|
13130
13167
|
}
|
|
13131
13168
|
async fulfillOrder(signer, orderRef, opts) {
|
|
13132
13169
|
const o = await this.deps.resolveOrder(orderRef);
|
|
13133
13170
|
const quantity = opts?.quantity ?? "1";
|
|
13134
13171
|
const totalPrice = (BigInt(o.unitPrice) * BigInt(quantity)).toString();
|
|
13135
|
-
|
|
13136
|
-
|
|
13137
|
-
orderHash: orderRef,
|
|
13138
|
-
paymentToken: o.paymentToken,
|
|
13139
|
-
totalPrice,
|
|
13140
|
-
quantity
|
|
13141
|
-
});
|
|
13142
|
-
}
|
|
13143
|
-
return this.m721.fulfillOrder(signer, {
|
|
13144
|
-
orderHash: orderRef,
|
|
13145
|
-
paymentToken: o.paymentToken,
|
|
13146
|
-
totalPrice
|
|
13147
|
-
});
|
|
13172
|
+
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);
|
|
13173
|
+
return signer.execute(calls);
|
|
13148
13174
|
}
|
|
13149
13175
|
async cancelOrder(signer, orderRef) {
|
|
13150
13176
|
const o = await this.deps.resolveOrder(orderRef);
|
|
13151
|
-
|
|
13152
|
-
|
|
13153
|
-
}
|
|
13154
|
-
return
|
|
13177
|
+
const typedData = o.standard === "ERC1155" ? buildCancel1155TypedData(orderRef, signer.address, this.deps.config) : buildCancelTypedData(orderRef, signer.address, this.deps.config);
|
|
13178
|
+
const signature = await signer.signTypedData(typedData);
|
|
13179
|
+
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);
|
|
13180
|
+
return signer.execute(calls);
|
|
13155
13181
|
}
|
|
13156
13182
|
async registerOrder(signer, p) {
|
|
13157
13183
|
const standard = await this.deps.resolveStandard(p.asset.contract);
|
|
13158
|
-
const
|
|
13159
|
-
const humanPrice = formatAmount(p.amount, token.decimals);
|
|
13160
|
-
const durationSeconds = this.durationSeconds(p.endTime);
|
|
13184
|
+
const paymentTokenAddress = resolveToken(p.paymentToken).address;
|
|
13161
13185
|
const royaltyMaxBps = String(p.royaltyMaxBps);
|
|
13186
|
+
const startTime = Math.floor(Date.now() / 1e3) + START_TIME_BUFFER_SECS;
|
|
13187
|
+
const endTime = p.endTime && p.endTime > 0 ? p.endTime : startTime + NO_EXPIRY_SECONDS;
|
|
13162
13188
|
const quantity = p.quantity ?? "1";
|
|
13163
|
-
|
|
13189
|
+
const marketplace = standard === "ERC1155" ? this.deps.config.marketplace1155Contract : this.deps.config.marketplaceContract;
|
|
13190
|
+
const counter = String(await this.readCounter(marketplace, signer.address));
|
|
13191
|
+
let typedData;
|
|
13192
|
+
let buildCalls;
|
|
13164
13193
|
if (standard === "ERC1155") {
|
|
13165
|
-
|
|
13166
|
-
|
|
13194
|
+
const built = (p.side === "listing" ? buildListing1155Order : buildOffer1155Order)(
|
|
13195
|
+
{
|
|
13196
|
+
offerer: signer.address,
|
|
13167
13197
|
nftContract: p.asset.contract,
|
|
13168
13198
|
tokenId: p.asset.tokenId,
|
|
13169
|
-
|
|
13170
|
-
|
|
13171
|
-
|
|
13172
|
-
|
|
13173
|
-
|
|
13174
|
-
|
|
13175
|
-
|
|
13176
|
-
|
|
13177
|
-
|
|
13178
|
-
|
|
13199
|
+
quantity,
|
|
13200
|
+
priceWeiPerUnit: p.amount,
|
|
13201
|
+
paymentTokenAddress,
|
|
13202
|
+
royaltyMaxBps,
|
|
13203
|
+
startTime,
|
|
13204
|
+
endTime,
|
|
13205
|
+
salt: p.salt,
|
|
13206
|
+
counter
|
|
13207
|
+
},
|
|
13208
|
+
this.deps.config
|
|
13209
|
+
);
|
|
13210
|
+
typedData = built.typedData;
|
|
13211
|
+
const approval = p.side === "listing" ? await this.approval1155ForListing(signer.address, p.asset.contract) : this.approvalForErc20(paymentTokenAddress, (BigInt(p.amount) * BigInt(quantity)).toString(), marketplace);
|
|
13212
|
+
buildCalls = (sig) => buildRegister1155Calls({ orderParams: built.orderParams, signature: sig, ...approval }, this.deps.config);
|
|
13213
|
+
} else {
|
|
13214
|
+
const built = (p.side === "listing" ? buildListingOrder : buildOfferOrder)(
|
|
13215
|
+
{
|
|
13216
|
+
offerer: signer.address,
|
|
13179
13217
|
nftContract: p.asset.contract,
|
|
13180
13218
|
tokenId: p.asset.tokenId,
|
|
13181
|
-
|
|
13182
|
-
|
|
13183
|
-
|
|
13184
|
-
|
|
13185
|
-
|
|
13186
|
-
|
|
13187
|
-
|
|
13188
|
-
|
|
13189
|
-
|
|
13190
|
-
|
|
13191
|
-
|
|
13192
|
-
|
|
13193
|
-
|
|
13194
|
-
currency: p.paymentToken,
|
|
13195
|
-
durationSeconds,
|
|
13196
|
-
royaltyMaxBps
|
|
13197
|
-
};
|
|
13198
|
-
const res = p.side === "listing" ? await this.m721.createListing(signer, params) : await this.m721.makeOffer(signer, params);
|
|
13199
|
-
txHash = res.txHash;
|
|
13219
|
+
priceWei: p.amount,
|
|
13220
|
+
paymentTokenAddress,
|
|
13221
|
+
royaltyMaxBps,
|
|
13222
|
+
startTime,
|
|
13223
|
+
endTime,
|
|
13224
|
+
salt: p.salt,
|
|
13225
|
+
counter
|
|
13226
|
+
},
|
|
13227
|
+
this.deps.config
|
|
13228
|
+
);
|
|
13229
|
+
typedData = built.typedData;
|
|
13230
|
+
const approval = p.side === "listing" ? await this.approval721ForListing(signer.address, p.asset.contract, p.asset.tokenId) : this.approvalForErc20(paymentTokenAddress, p.amount, marketplace);
|
|
13231
|
+
buildCalls = (sig) => buildRegisterCalls({ orderParams: built.orderParams, signature: sig, ...approval }, this.deps.config);
|
|
13200
13232
|
}
|
|
13233
|
+
const signature = await signer.signTypedData(typedData);
|
|
13234
|
+
const { txHash } = await signer.execute(buildCalls(signature));
|
|
13201
13235
|
const orderRef = await this.orderRefFromReceipt(txHash);
|
|
13202
13236
|
return { txHash, orderRef };
|
|
13203
13237
|
}
|
|
13204
|
-
|
|
13205
|
-
|
|
13206
|
-
|
|
13238
|
+
// ─── reads (all on deps.provider) ─────────────────────────────────────────
|
|
13239
|
+
async readCounter(marketplace, address) {
|
|
13240
|
+
const res = await this.deps.provider.callContract({
|
|
13241
|
+
contractAddress: marketplace,
|
|
13242
|
+
entrypoint: "get_counter",
|
|
13243
|
+
calldata: [address]
|
|
13244
|
+
});
|
|
13245
|
+
return BigInt(res[0] ?? "0");
|
|
13246
|
+
}
|
|
13247
|
+
/** 721 listing approval: `get_approved(tokenId) == marketplace` ⇒ no approve. */
|
|
13248
|
+
async approval721ForListing(_owner, nftContract, tokenId) {
|
|
13249
|
+
const id = starknet.cairo.uint256(tokenId);
|
|
13250
|
+
const approve = {
|
|
13251
|
+
contractAddress: nftContract,
|
|
13252
|
+
entrypoint: "approve",
|
|
13253
|
+
calldata: [this.deps.config.marketplaceContract, id.low.toString(), id.high.toString()]
|
|
13254
|
+
};
|
|
13255
|
+
let approved = false;
|
|
13256
|
+
try {
|
|
13257
|
+
const res = await this.deps.provider.callContract({
|
|
13258
|
+
contractAddress: nftContract,
|
|
13259
|
+
entrypoint: "get_approved",
|
|
13260
|
+
calldata: [id.low.toString(), id.high.toString()]
|
|
13261
|
+
});
|
|
13262
|
+
approved = BigInt(res[0]).toString() === BigInt(this.deps.config.marketplaceContract).toString();
|
|
13263
|
+
} catch {
|
|
13264
|
+
}
|
|
13265
|
+
return { approvalNeeded: !approved, approve };
|
|
13266
|
+
}
|
|
13267
|
+
/** 1155 listing approval: `is_approved_for_all(owner, marketplace)`. */
|
|
13268
|
+
async approval1155ForListing(owner, nftContract) {
|
|
13269
|
+
const approve = {
|
|
13270
|
+
contractAddress: nftContract,
|
|
13271
|
+
entrypoint: "set_approval_for_all",
|
|
13272
|
+
calldata: [this.deps.config.marketplace1155Contract, "1"]
|
|
13273
|
+
};
|
|
13274
|
+
let approved = false;
|
|
13275
|
+
try {
|
|
13276
|
+
const res = await this.deps.provider.callContract({
|
|
13277
|
+
contractAddress: nftContract,
|
|
13278
|
+
entrypoint: "is_approved_for_all",
|
|
13279
|
+
calldata: [owner, this.deps.config.marketplace1155Contract]
|
|
13280
|
+
});
|
|
13281
|
+
approved = BigInt(res[0]) === 1n;
|
|
13282
|
+
} catch {
|
|
13283
|
+
}
|
|
13284
|
+
return { approvalNeeded: !approved, approve };
|
|
13285
|
+
}
|
|
13286
|
+
/** Offers always approve the ERC-20 spend (no read). */
|
|
13287
|
+
approvalForErc20(token, amountWei, marketplace) {
|
|
13288
|
+
const u = starknet.cairo.uint256(amountWei);
|
|
13289
|
+
return {
|
|
13290
|
+
approvalNeeded: true,
|
|
13291
|
+
approve: {
|
|
13292
|
+
contractAddress: token,
|
|
13293
|
+
entrypoint: "approve",
|
|
13294
|
+
calldata: [marketplace, u.low.toString(), u.high.toString()]
|
|
13295
|
+
}
|
|
13296
|
+
};
|
|
13207
13297
|
}
|
|
13208
13298
|
/** The canonical Starknet order id = the contract-emitted `OrderCreated`
|
|
13209
13299
|
* hash (`keys[1]`), which is exactly what the indexer stores. */
|