@medialane/sdk 0.56.0 → 0.57.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-BcO6oh6E.d.ts → index-Bv81mkG7.d.ts} +25 -14
- package/dist/{index-CcXuxRd-.d.cts → index-q-f4hxV5.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-D3PWgk3x.d.cts → types-DNJNR50M.d.cts} +20 -3
- package/dist/{types-D3PWgk3x.d.ts → types-DNJNR50M.d.ts} +20 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -9764,6 +9764,94 @@ function getProvider(config) {
|
|
|
9764
9764
|
return p;
|
|
9765
9765
|
}
|
|
9766
9766
|
|
|
9767
|
+
// src/starknet/marketplace/build.ts
|
|
9768
|
+
function contractFor(cfg) {
|
|
9769
|
+
return new starknet.Contract(IPMarketplaceABI, cfg.marketplaceContract, getProvider(cfg));
|
|
9770
|
+
}
|
|
9771
|
+
function buildListingOrder(i, cfg) {
|
|
9772
|
+
const orderParams = {
|
|
9773
|
+
offerer: i.offerer,
|
|
9774
|
+
marketplace: cfg.marketplaceContract,
|
|
9775
|
+
offer: { item_type: "ERC721", token: i.nftContract, identifier_or_criteria: i.tokenId, amount: "1" },
|
|
9776
|
+
consideration: {
|
|
9777
|
+
item_type: "ERC20",
|
|
9778
|
+
token: i.paymentTokenAddress,
|
|
9779
|
+
identifier_or_criteria: "0",
|
|
9780
|
+
amount: i.priceWei,
|
|
9781
|
+
recipient: i.offerer
|
|
9782
|
+
},
|
|
9783
|
+
royalty_max_bps: i.royaltyMaxBps,
|
|
9784
|
+
start_time: String(i.startTime),
|
|
9785
|
+
end_time: String(i.endTime),
|
|
9786
|
+
salt: i.salt,
|
|
9787
|
+
counter: i.counter
|
|
9788
|
+
};
|
|
9789
|
+
const typedData = stringifyBigInts(buildOrderTypedData(orderParams, getChainId(cfg)));
|
|
9790
|
+
return { orderParams, typedData };
|
|
9791
|
+
}
|
|
9792
|
+
function buildOfferOrder(i, cfg) {
|
|
9793
|
+
const orderParams = {
|
|
9794
|
+
offerer: i.offerer,
|
|
9795
|
+
marketplace: cfg.marketplaceContract,
|
|
9796
|
+
offer: { item_type: "ERC20", token: i.paymentTokenAddress, identifier_or_criteria: "0", amount: i.priceWei },
|
|
9797
|
+
consideration: {
|
|
9798
|
+
item_type: "ERC721",
|
|
9799
|
+
token: i.nftContract,
|
|
9800
|
+
identifier_or_criteria: i.tokenId,
|
|
9801
|
+
amount: "1",
|
|
9802
|
+
recipient: i.offerer
|
|
9803
|
+
},
|
|
9804
|
+
royalty_max_bps: i.royaltyMaxBps,
|
|
9805
|
+
start_time: String(i.startTime),
|
|
9806
|
+
end_time: String(i.endTime),
|
|
9807
|
+
salt: i.salt,
|
|
9808
|
+
counter: i.counter
|
|
9809
|
+
};
|
|
9810
|
+
const typedData = stringifyBigInts(buildOrderTypedData(orderParams, getChainId(cfg)));
|
|
9811
|
+
return { orderParams, typedData };
|
|
9812
|
+
}
|
|
9813
|
+
function registerPayload(orderParams, signature) {
|
|
9814
|
+
return stringifyBigInts({
|
|
9815
|
+
parameters: {
|
|
9816
|
+
...orderParams,
|
|
9817
|
+
offer: { ...orderParams.offer, item_type: starknet.shortString.encodeShortString(orderParams.offer.item_type) },
|
|
9818
|
+
consideration: {
|
|
9819
|
+
...orderParams.consideration,
|
|
9820
|
+
item_type: starknet.shortString.encodeShortString(orderParams.consideration.item_type)
|
|
9821
|
+
}
|
|
9822
|
+
},
|
|
9823
|
+
signature
|
|
9824
|
+
});
|
|
9825
|
+
}
|
|
9826
|
+
function buildRegisterCalls(a, cfg) {
|
|
9827
|
+
const registerCall = contractFor(cfg).populate("register_order", [registerPayload(a.orderParams, a.signature)]);
|
|
9828
|
+
return a.approvalNeeded ? [a.approve, registerCall] : [registerCall];
|
|
9829
|
+
}
|
|
9830
|
+
function buildFulfillCalls(a, cfg) {
|
|
9831
|
+
const u = starknet.cairo.uint256(a.totalPrice);
|
|
9832
|
+
const approve = {
|
|
9833
|
+
contractAddress: a.paymentToken,
|
|
9834
|
+
entrypoint: "approve",
|
|
9835
|
+
calldata: [cfg.marketplaceContract, u.low.toString(), u.high.toString()]
|
|
9836
|
+
};
|
|
9837
|
+
const fulfill = contractFor(cfg).populate("fulfill_order", [a.orderHash]);
|
|
9838
|
+
const fee = buildFeeCall(
|
|
9839
|
+
{ surface: "marketplace", token: a.paymentToken, grossAmount: BigInt(a.totalPrice) },
|
|
9840
|
+
cfg.feeConfig
|
|
9841
|
+
);
|
|
9842
|
+
return fee ? [approve, fulfill, fee] : [approve, fulfill];
|
|
9843
|
+
}
|
|
9844
|
+
function buildCancelCalls(a, cfg) {
|
|
9845
|
+
const cancelRequest = stringifyBigInts({
|
|
9846
|
+
cancelation: { order_hash: a.orderHash, offerer: a.offerer },
|
|
9847
|
+
signature: a.signature
|
|
9848
|
+
});
|
|
9849
|
+
return [contractFor(cfg).populate("cancel_order", [cancelRequest])];
|
|
9850
|
+
}
|
|
9851
|
+
function buildCancelTypedData(orderHash, offerer, cfg) {
|
|
9852
|
+
return stringifyBigInts(buildCancellationTypedData({ order_hash: orderHash, offerer }, getChainId(cfg)));
|
|
9853
|
+
}
|
|
9854
|
+
|
|
9767
9855
|
// src/starknet/marketplace/orders.ts
|
|
9768
9856
|
var _contractCache = /* @__PURE__ */ new WeakMap();
|
|
9769
9857
|
function makeContract(config) {
|
|
@@ -9788,46 +9876,22 @@ async function createListing(account, params, config) {
|
|
|
9788
9876
|
const endTime = now + durationSeconds;
|
|
9789
9877
|
const counter = (await contract.get_counter(account.address)).toString();
|
|
9790
9878
|
const royaltyMaxBps = await resolveRoyaltyMaxBps(provider, nftContract, tokenId, params.royaltyMaxBps);
|
|
9791
|
-
const orderParams =
|
|
9792
|
-
|
|
9793
|
-
|
|
9794
|
-
|
|
9795
|
-
|
|
9796
|
-
|
|
9797
|
-
|
|
9798
|
-
|
|
9799
|
-
|
|
9800
|
-
|
|
9801
|
-
|
|
9802
|
-
|
|
9803
|
-
identifier_or_criteria: "0",
|
|
9804
|
-
amount: priceWei,
|
|
9805
|
-
recipient: account.address
|
|
9806
|
-
},
|
|
9807
|
-
royalty_max_bps: royaltyMaxBps,
|
|
9808
|
-
start_time: startTime.toString(),
|
|
9809
|
-
end_time: endTime.toString(),
|
|
9810
|
-
salt: generateSalt(),
|
|
9811
|
-
counter
|
|
9812
|
-
};
|
|
9813
|
-
const chainId = getChainId(config);
|
|
9814
|
-
const typedData = stringifyBigInts(buildOrderTypedData(orderParams, chainId));
|
|
9815
|
-
const signature = await account.signMessage(typedData);
|
|
9816
|
-
const signatureArray = toSignatureArray(signature);
|
|
9817
|
-
const registerPayload = stringifyBigInts({
|
|
9818
|
-
parameters: {
|
|
9819
|
-
...orderParams,
|
|
9820
|
-
offer: {
|
|
9821
|
-
...orderParams.offer,
|
|
9822
|
-
item_type: starknet.shortString.encodeShortString(orderParams.offer.item_type)
|
|
9823
|
-
},
|
|
9824
|
-
consideration: {
|
|
9825
|
-
...orderParams.consideration,
|
|
9826
|
-
item_type: starknet.shortString.encodeShortString(orderParams.consideration.item_type)
|
|
9827
|
-
}
|
|
9879
|
+
const { orderParams, typedData } = buildListingOrder(
|
|
9880
|
+
{
|
|
9881
|
+
offerer: account.address,
|
|
9882
|
+
nftContract,
|
|
9883
|
+
tokenId,
|
|
9884
|
+
priceWei,
|
|
9885
|
+
paymentTokenAddress: token.address,
|
|
9886
|
+
royaltyMaxBps,
|
|
9887
|
+
startTime,
|
|
9888
|
+
endTime,
|
|
9889
|
+
salt: generateSalt(),
|
|
9890
|
+
counter
|
|
9828
9891
|
},
|
|
9829
|
-
|
|
9830
|
-
|
|
9892
|
+
config
|
|
9893
|
+
);
|
|
9894
|
+
const signatureArray = toSignatureArray(await account.signMessage(typedData));
|
|
9831
9895
|
const tokenIdUint256 = starknet.cairo.uint256(tokenId);
|
|
9832
9896
|
let isAlreadyApproved = false;
|
|
9833
9897
|
try {
|
|
@@ -9839,19 +9903,19 @@ async function createListing(account, params, config) {
|
|
|
9839
9903
|
isAlreadyApproved = BigInt(result[0]).toString() === BigInt(config.marketplaceContract).toString();
|
|
9840
9904
|
} catch {
|
|
9841
9905
|
}
|
|
9842
|
-
const
|
|
9843
|
-
|
|
9844
|
-
|
|
9845
|
-
|
|
9846
|
-
|
|
9847
|
-
|
|
9848
|
-
|
|
9849
|
-
|
|
9850
|
-
|
|
9851
|
-
|
|
9852
|
-
},
|
|
9853
|
-
|
|
9854
|
-
|
|
9906
|
+
const approve = {
|
|
9907
|
+
contractAddress: nftContract,
|
|
9908
|
+
entrypoint: "approve",
|
|
9909
|
+
calldata: [
|
|
9910
|
+
config.marketplaceContract,
|
|
9911
|
+
tokenIdUint256.low.toString(),
|
|
9912
|
+
tokenIdUint256.high.toString()
|
|
9913
|
+
]
|
|
9914
|
+
};
|
|
9915
|
+
const calls = buildRegisterCalls(
|
|
9916
|
+
{ orderParams, signature: signatureArray, approvalNeeded: !isAlreadyApproved, approve },
|
|
9917
|
+
config
|
|
9918
|
+
);
|
|
9855
9919
|
try {
|
|
9856
9920
|
const tx = await account.execute(calls);
|
|
9857
9921
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
@@ -9870,46 +9934,22 @@ async function makeOffer(account, params, config) {
|
|
|
9870
9934
|
const endTime = now + durationSeconds;
|
|
9871
9935
|
const counter = (await contract.get_counter(account.address)).toString();
|
|
9872
9936
|
const royaltyMaxBps = await resolveRoyaltyMaxBps(provider, nftContract, tokenId, params.royaltyMaxBps);
|
|
9873
|
-
const orderParams =
|
|
9874
|
-
|
|
9875
|
-
|
|
9876
|
-
|
|
9877
|
-
|
|
9878
|
-
|
|
9879
|
-
|
|
9880
|
-
|
|
9881
|
-
|
|
9882
|
-
|
|
9883
|
-
|
|
9884
|
-
|
|
9885
|
-
identifier_or_criteria: tokenId,
|
|
9886
|
-
amount: "1",
|
|
9887
|
-
recipient: account.address
|
|
9888
|
-
},
|
|
9889
|
-
royalty_max_bps: royaltyMaxBps,
|
|
9890
|
-
start_time: startTime.toString(),
|
|
9891
|
-
end_time: endTime.toString(),
|
|
9892
|
-
salt: generateSalt(),
|
|
9893
|
-
counter
|
|
9894
|
-
};
|
|
9895
|
-
const chainId = getChainId(config);
|
|
9896
|
-
const typedData = stringifyBigInts(buildOrderTypedData(orderParams, chainId));
|
|
9897
|
-
const signature = await account.signMessage(typedData);
|
|
9898
|
-
const signatureArray = toSignatureArray(signature);
|
|
9899
|
-
const registerPayload = stringifyBigInts({
|
|
9900
|
-
parameters: {
|
|
9901
|
-
...orderParams,
|
|
9902
|
-
offer: {
|
|
9903
|
-
...orderParams.offer,
|
|
9904
|
-
item_type: starknet.shortString.encodeShortString(orderParams.offer.item_type)
|
|
9905
|
-
},
|
|
9906
|
-
consideration: {
|
|
9907
|
-
...orderParams.consideration,
|
|
9908
|
-
item_type: starknet.shortString.encodeShortString(orderParams.consideration.item_type)
|
|
9909
|
-
}
|
|
9937
|
+
const { orderParams, typedData } = buildOfferOrder(
|
|
9938
|
+
{
|
|
9939
|
+
offerer: account.address,
|
|
9940
|
+
nftContract,
|
|
9941
|
+
tokenId,
|
|
9942
|
+
priceWei,
|
|
9943
|
+
paymentTokenAddress: token.address,
|
|
9944
|
+
royaltyMaxBps,
|
|
9945
|
+
startTime,
|
|
9946
|
+
endTime,
|
|
9947
|
+
salt: generateSalt(),
|
|
9948
|
+
counter
|
|
9910
9949
|
},
|
|
9911
|
-
|
|
9912
|
-
|
|
9950
|
+
config
|
|
9951
|
+
);
|
|
9952
|
+
const signatureArray = toSignatureArray(await account.signMessage(typedData));
|
|
9913
9953
|
const amountUint256 = starknet.cairo.uint256(priceWei);
|
|
9914
9954
|
const approveCall = {
|
|
9915
9955
|
contractAddress: token.address,
|
|
@@ -9920,9 +9960,12 @@ async function makeOffer(account, params, config) {
|
|
|
9920
9960
|
amountUint256.high.toString()
|
|
9921
9961
|
]
|
|
9922
9962
|
};
|
|
9923
|
-
const
|
|
9963
|
+
const calls = buildRegisterCalls(
|
|
9964
|
+
{ orderParams, signature: signatureArray, approvalNeeded: true, approve: approveCall },
|
|
9965
|
+
config
|
|
9966
|
+
);
|
|
9924
9967
|
try {
|
|
9925
|
-
const tx = await account.execute(
|
|
9968
|
+
const tx = await account.execute(calls);
|
|
9926
9969
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
9927
9970
|
return { txHash: tx.transaction_hash };
|
|
9928
9971
|
} catch (err) {
|
|
@@ -9931,23 +9974,8 @@ async function makeOffer(account, params, config) {
|
|
|
9931
9974
|
}
|
|
9932
9975
|
async function fulfillOrder(account, params, config) {
|
|
9933
9976
|
const { orderHash, paymentToken, totalPrice } = params;
|
|
9934
|
-
const {
|
|
9935
|
-
const
|
|
9936
|
-
const approveCall = {
|
|
9937
|
-
contractAddress: paymentToken,
|
|
9938
|
-
entrypoint: "approve",
|
|
9939
|
-
calldata: [
|
|
9940
|
-
config.marketplaceContract,
|
|
9941
|
-
totalPriceU256.low.toString(),
|
|
9942
|
-
totalPriceU256.high.toString()
|
|
9943
|
-
]
|
|
9944
|
-
};
|
|
9945
|
-
const fulfillCall = contract.populate("fulfill_order", [orderHash]);
|
|
9946
|
-
const feeCall = buildFeeCall(
|
|
9947
|
-
{ surface: "marketplace", token: paymentToken, grossAmount: BigInt(totalPrice) },
|
|
9948
|
-
config.feeConfig
|
|
9949
|
-
);
|
|
9950
|
-
const calls = feeCall ? [approveCall, fulfillCall, feeCall] : [approveCall, fulfillCall];
|
|
9977
|
+
const { provider } = makeContract(config);
|
|
9978
|
+
const calls = buildFulfillCalls({ orderHash, paymentToken, totalPrice }, config);
|
|
9951
9979
|
try {
|
|
9952
9980
|
const tx = await account.execute(calls);
|
|
9953
9981
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
@@ -9958,24 +9986,12 @@ async function fulfillOrder(account, params, config) {
|
|
|
9958
9986
|
}
|
|
9959
9987
|
async function cancelOrder(account, params, config) {
|
|
9960
9988
|
const { orderHash } = params;
|
|
9961
|
-
const {
|
|
9962
|
-
const
|
|
9963
|
-
const
|
|
9964
|
-
|
|
9965
|
-
offerer: account.address
|
|
9966
|
-
};
|
|
9967
|
-
const typedData = stringifyBigInts(
|
|
9968
|
-
buildCancellationTypedData(cancelParams, chainId)
|
|
9969
|
-
);
|
|
9970
|
-
const signature = await account.signMessage(typedData);
|
|
9971
|
-
const signatureArray = toSignatureArray(signature);
|
|
9972
|
-
const cancelRequest = stringifyBigInts({
|
|
9973
|
-
cancelation: cancelParams,
|
|
9974
|
-
signature: signatureArray
|
|
9975
|
-
});
|
|
9976
|
-
const call = contract.populate("cancel_order", [cancelRequest]);
|
|
9989
|
+
const { provider } = makeContract(config);
|
|
9990
|
+
const typedData = buildCancelTypedData(orderHash, account.address, config);
|
|
9991
|
+
const signatureArray = toSignatureArray(await account.signMessage(typedData));
|
|
9992
|
+
const calls = buildCancelCalls({ orderHash, offerer: account.address, signature: signatureArray }, config);
|
|
9977
9993
|
try {
|
|
9978
|
-
const tx = await account.execute(
|
|
9994
|
+
const tx = await account.execute(calls);
|
|
9979
9995
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
9980
9996
|
return { txHash: tx.transaction_hash };
|
|
9981
9997
|
} catch (err) {
|
|
@@ -10122,6 +10138,100 @@ var MarketplaceModule = class {
|
|
|
10122
10138
|
return buildCancellationTypedData(params, chainId);
|
|
10123
10139
|
}
|
|
10124
10140
|
};
|
|
10141
|
+
function contractFor2(cfg) {
|
|
10142
|
+
return new starknet.Contract(Medialane1155ABI, cfg.marketplace1155Contract, getProvider(cfg));
|
|
10143
|
+
}
|
|
10144
|
+
function buildListing1155Order(i, cfg) {
|
|
10145
|
+
const orderParams = {
|
|
10146
|
+
offerer: i.offerer,
|
|
10147
|
+
marketplace: cfg.marketplace1155Contract,
|
|
10148
|
+
offer: { item_type: "ERC1155", token: i.nftContract, identifier_or_criteria: i.tokenId, amount: i.quantity },
|
|
10149
|
+
consideration: {
|
|
10150
|
+
item_type: "ERC20",
|
|
10151
|
+
token: i.paymentTokenAddress,
|
|
10152
|
+
identifier_or_criteria: "0",
|
|
10153
|
+
amount: i.priceWeiPerUnit,
|
|
10154
|
+
recipient: i.offerer
|
|
10155
|
+
},
|
|
10156
|
+
royalty_max_bps: i.royaltyMaxBps,
|
|
10157
|
+
start_time: String(i.startTime),
|
|
10158
|
+
end_time: String(i.endTime),
|
|
10159
|
+
salt: i.salt,
|
|
10160
|
+
counter: i.counter
|
|
10161
|
+
};
|
|
10162
|
+
const typedData = stringifyBigInts(
|
|
10163
|
+
build1155OrderTypedData(orderParams, getChainId(cfg))
|
|
10164
|
+
);
|
|
10165
|
+
return { orderParams, typedData };
|
|
10166
|
+
}
|
|
10167
|
+
function buildOffer1155Order(i, cfg) {
|
|
10168
|
+
const orderParams = {
|
|
10169
|
+
offerer: i.offerer,
|
|
10170
|
+
marketplace: cfg.marketplace1155Contract,
|
|
10171
|
+
offer: { item_type: "ERC20", token: i.paymentTokenAddress, identifier_or_criteria: "0", amount: i.priceWeiPerUnit },
|
|
10172
|
+
consideration: {
|
|
10173
|
+
item_type: "ERC1155",
|
|
10174
|
+
token: i.nftContract,
|
|
10175
|
+
identifier_or_criteria: i.tokenId,
|
|
10176
|
+
amount: i.quantity,
|
|
10177
|
+
recipient: i.offerer
|
|
10178
|
+
},
|
|
10179
|
+
royalty_max_bps: i.royaltyMaxBps,
|
|
10180
|
+
start_time: String(i.startTime),
|
|
10181
|
+
end_time: String(i.endTime),
|
|
10182
|
+
salt: i.salt,
|
|
10183
|
+
counter: i.counter
|
|
10184
|
+
};
|
|
10185
|
+
const typedData = stringifyBigInts(
|
|
10186
|
+
build1155OrderTypedData(orderParams, getChainId(cfg))
|
|
10187
|
+
);
|
|
10188
|
+
return { orderParams, typedData };
|
|
10189
|
+
}
|
|
10190
|
+
function registerPayload2(orderParams, signature) {
|
|
10191
|
+
return stringifyBigInts({
|
|
10192
|
+
parameters: {
|
|
10193
|
+
...orderParams,
|
|
10194
|
+
offer: { ...orderParams.offer, item_type: starknet.shortString.encodeShortString(orderParams.offer.item_type) },
|
|
10195
|
+
consideration: {
|
|
10196
|
+
...orderParams.consideration,
|
|
10197
|
+
item_type: starknet.shortString.encodeShortString(orderParams.consideration.item_type)
|
|
10198
|
+
}
|
|
10199
|
+
},
|
|
10200
|
+
signature
|
|
10201
|
+
});
|
|
10202
|
+
}
|
|
10203
|
+
function buildRegister1155Calls(a, cfg) {
|
|
10204
|
+
const registerCall = contractFor2(cfg).populate("register_order", [registerPayload2(a.orderParams, a.signature)]);
|
|
10205
|
+
return a.approvalNeeded ? [a.approve, registerCall] : [registerCall];
|
|
10206
|
+
}
|
|
10207
|
+
function buildFulfill1155Calls(a, cfg) {
|
|
10208
|
+
const u = starknet.cairo.uint256(a.totalPrice);
|
|
10209
|
+
const approve = {
|
|
10210
|
+
contractAddress: a.paymentToken,
|
|
10211
|
+
entrypoint: "approve",
|
|
10212
|
+
calldata: [cfg.marketplace1155Contract, u.low.toString(), u.high.toString()]
|
|
10213
|
+
};
|
|
10214
|
+
const fulfill = contractFor2(cfg).populate("fulfill_order", [a.orderHash, a.quantity]);
|
|
10215
|
+
const fee = buildFeeCall(
|
|
10216
|
+
{ surface: "marketplace", token: a.paymentToken, grossAmount: BigInt(a.totalPrice) },
|
|
10217
|
+
cfg.feeConfig
|
|
10218
|
+
);
|
|
10219
|
+
return fee ? [approve, fulfill, fee] : [approve, fulfill];
|
|
10220
|
+
}
|
|
10221
|
+
function buildCancel1155Calls(a, cfg) {
|
|
10222
|
+
const cancelPayload = stringifyBigInts({
|
|
10223
|
+
cancelation: { order_hash: a.orderHash, offerer: a.offerer },
|
|
10224
|
+
signature: a.signature
|
|
10225
|
+
});
|
|
10226
|
+
return [contractFor2(cfg).populate("cancel_order", [cancelPayload])];
|
|
10227
|
+
}
|
|
10228
|
+
function buildCancel1155TypedData(orderHash, offerer, cfg) {
|
|
10229
|
+
return stringifyBigInts(
|
|
10230
|
+
build1155CancellationTypedData({ order_hash: orderHash, offerer }, getChainId(cfg))
|
|
10231
|
+
);
|
|
10232
|
+
}
|
|
10233
|
+
|
|
10234
|
+
// src/starknet/marketplace1155/orders.ts
|
|
10125
10235
|
var _contractCache2 = /* @__PURE__ */ new WeakMap();
|
|
10126
10236
|
function getContract(config) {
|
|
10127
10237
|
let c = _contractCache2.get(config);
|
|
@@ -10150,53 +10260,27 @@ async function createListing1155(account, params, config) {
|
|
|
10150
10260
|
const token = resolveToken(currency);
|
|
10151
10261
|
const priceWei = parseAmount(pricePerUnit, token.decimals);
|
|
10152
10262
|
const now = Math.floor(Date.now() / 1e3);
|
|
10263
|
+
const startTime = now + START_TIME_BUFFER_SECS;
|
|
10153
10264
|
const endTime = now + durationSeconds;
|
|
10154
|
-
const chainId = getChainId(config);
|
|
10155
10265
|
const counter = (await contract.get_counter(account.address)).toString();
|
|
10156
10266
|
const royaltyMaxBps = await resolveRoyaltyMaxBps(provider, nftContract, tokenId, params.royaltyMaxBps);
|
|
10157
|
-
const orderParams =
|
|
10158
|
-
|
|
10159
|
-
|
|
10160
|
-
|
|
10161
|
-
|
|
10162
|
-
|
|
10163
|
-
|
|
10164
|
-
|
|
10165
|
-
|
|
10166
|
-
|
|
10167
|
-
|
|
10168
|
-
|
|
10169
|
-
|
|
10170
|
-
identifier_or_criteria: "0",
|
|
10171
|
-
amount: priceWei,
|
|
10172
|
-
// payment leg amount = price PER UNIT
|
|
10173
|
-
recipient: account.address
|
|
10267
|
+
const { orderParams, typedData } = buildListing1155Order(
|
|
10268
|
+
{
|
|
10269
|
+
offerer: account.address,
|
|
10270
|
+
nftContract,
|
|
10271
|
+
tokenId,
|
|
10272
|
+
quantity: amount,
|
|
10273
|
+
priceWeiPerUnit: priceWei,
|
|
10274
|
+
paymentTokenAddress: token.address,
|
|
10275
|
+
royaltyMaxBps,
|
|
10276
|
+
startTime,
|
|
10277
|
+
endTime,
|
|
10278
|
+
salt: generateSalt(),
|
|
10279
|
+
counter
|
|
10174
10280
|
},
|
|
10175
|
-
|
|
10176
|
-
start_time: (now + START_TIME_BUFFER_SECS).toString(),
|
|
10177
|
-
end_time: endTime.toString(),
|
|
10178
|
-
salt: generateSalt(),
|
|
10179
|
-
counter
|
|
10180
|
-
};
|
|
10181
|
-
const typedData = stringifyBigInts(
|
|
10182
|
-
build1155OrderTypedData(orderParams, chainId)
|
|
10281
|
+
config
|
|
10183
10282
|
);
|
|
10184
|
-
const
|
|
10185
|
-
const signatureArray = toSignatureArray(signature);
|
|
10186
|
-
const orderPayload = stringifyBigInts({
|
|
10187
|
-
parameters: {
|
|
10188
|
-
...orderParams,
|
|
10189
|
-
offer: {
|
|
10190
|
-
...orderParams.offer,
|
|
10191
|
-
item_type: starknet.shortString.encodeShortString(orderParams.offer.item_type)
|
|
10192
|
-
},
|
|
10193
|
-
consideration: {
|
|
10194
|
-
...orderParams.consideration,
|
|
10195
|
-
item_type: starknet.shortString.encodeShortString(orderParams.consideration.item_type)
|
|
10196
|
-
}
|
|
10197
|
-
},
|
|
10198
|
-
signature: signatureArray
|
|
10199
|
-
});
|
|
10283
|
+
const signatureArray = toSignatureArray(await account.signMessage(typedData));
|
|
10200
10284
|
let isApproved = false;
|
|
10201
10285
|
try {
|
|
10202
10286
|
const result = await provider.callContract({
|
|
@@ -10207,15 +10291,15 @@ async function createListing1155(account, params, config) {
|
|
|
10207
10291
|
isApproved = BigInt(result[0]) === 1n;
|
|
10208
10292
|
} catch {
|
|
10209
10293
|
}
|
|
10210
|
-
const
|
|
10211
|
-
|
|
10212
|
-
|
|
10213
|
-
|
|
10214
|
-
|
|
10215
|
-
|
|
10216
|
-
},
|
|
10217
|
-
|
|
10218
|
-
|
|
10294
|
+
const approve = {
|
|
10295
|
+
contractAddress: nftContract,
|
|
10296
|
+
entrypoint: "set_approval_for_all",
|
|
10297
|
+
calldata: [config.marketplace1155Contract, "1"]
|
|
10298
|
+
};
|
|
10299
|
+
const calls = buildRegister1155Calls(
|
|
10300
|
+
{ orderParams, signature: signatureArray, approvalNeeded: !isApproved, approve },
|
|
10301
|
+
config
|
|
10302
|
+
);
|
|
10219
10303
|
try {
|
|
10220
10304
|
const tx = await account.execute(calls);
|
|
10221
10305
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
@@ -10226,21 +10310,10 @@ async function createListing1155(account, params, config) {
|
|
|
10226
10310
|
}
|
|
10227
10311
|
async function fulfillOrder1155(account, params, config) {
|
|
10228
10312
|
const { orderHash, paymentToken, totalPrice, quantity = "1" } = params;
|
|
10229
|
-
const contract = getContract(config);
|
|
10230
10313
|
const provider = getProvider(config);
|
|
10231
|
-
const
|
|
10232
|
-
const approveCall = {
|
|
10233
|
-
contractAddress: paymentToken,
|
|
10234
|
-
entrypoint: "approve",
|
|
10235
|
-
calldata: [
|
|
10236
|
-
config.marketplace1155Contract,
|
|
10237
|
-
totalPriceU256.low.toString(),
|
|
10238
|
-
totalPriceU256.high.toString()
|
|
10239
|
-
]
|
|
10240
|
-
};
|
|
10241
|
-
const fulfillCall = contract.populate("fulfill_order", [orderHash, quantity]);
|
|
10314
|
+
const calls = buildFulfill1155Calls({ orderHash, paymentToken, totalPrice, quantity }, config);
|
|
10242
10315
|
try {
|
|
10243
|
-
const tx = await account.execute(
|
|
10316
|
+
const tx = await account.execute(calls);
|
|
10244
10317
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
10245
10318
|
return { txHash: tx.transaction_hash };
|
|
10246
10319
|
} catch (err) {
|
|
@@ -10249,25 +10322,12 @@ async function fulfillOrder1155(account, params, config) {
|
|
|
10249
10322
|
}
|
|
10250
10323
|
async function cancelOrder1155(account, params, config) {
|
|
10251
10324
|
const { orderHash } = params;
|
|
10252
|
-
const contract = getContract(config);
|
|
10253
10325
|
const provider = getProvider(config);
|
|
10254
|
-
const
|
|
10255
|
-
const
|
|
10256
|
-
|
|
10257
|
-
offerer: account.address
|
|
10258
|
-
};
|
|
10259
|
-
const typedData = stringifyBigInts(
|
|
10260
|
-
build1155CancellationTypedData(cancelParams, chainId)
|
|
10261
|
-
);
|
|
10262
|
-
const signature = await account.signMessage(typedData);
|
|
10263
|
-
const signatureArray = toSignatureArray(signature);
|
|
10264
|
-
const cancelPayload = stringifyBigInts({
|
|
10265
|
-
cancelation: cancelParams,
|
|
10266
|
-
signature: signatureArray
|
|
10267
|
-
});
|
|
10268
|
-
const cancelCall = contract.populate("cancel_order", [cancelPayload]);
|
|
10326
|
+
const typedData = buildCancel1155TypedData(orderHash, account.address, config);
|
|
10327
|
+
const signatureArray = toSignatureArray(await account.signMessage(typedData));
|
|
10328
|
+
const calls = buildCancel1155Calls({ orderHash, offerer: account.address, signature: signatureArray }, config);
|
|
10269
10329
|
try {
|
|
10270
|
-
const tx = await account.execute(
|
|
10330
|
+
const tx = await account.execute(calls);
|
|
10271
10331
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
10272
10332
|
return { txHash: tx.transaction_hash };
|
|
10273
10333
|
} catch (err) {
|
|
@@ -10285,56 +10345,30 @@ async function makeOffer1155(account, params, config) {
|
|
|
10285
10345
|
} = params;
|
|
10286
10346
|
const contract = getContract(config);
|
|
10287
10347
|
const provider = getProvider(config);
|
|
10288
|
-
const chainId = getChainId(config);
|
|
10289
10348
|
const token = resolveToken(currency);
|
|
10290
10349
|
const priceWei = parseAmount(price, token.decimals);
|
|
10291
10350
|
const now = Math.floor(Date.now() / 1e3);
|
|
10351
|
+
const startTime = now + START_TIME_BUFFER_SECS;
|
|
10292
10352
|
const endTime = now + durationSeconds;
|
|
10293
10353
|
const counter = (await contract.get_counter(account.address)).toString();
|
|
10294
10354
|
const royaltyMaxBps = await resolveRoyaltyMaxBps(provider, nftContract, tokenId, params.royaltyMaxBps);
|
|
10295
|
-
const orderParams =
|
|
10296
|
-
|
|
10297
|
-
|
|
10298
|
-
|
|
10299
|
-
|
|
10300
|
-
|
|
10301
|
-
|
|
10302
|
-
|
|
10303
|
-
|
|
10304
|
-
|
|
10305
|
-
|
|
10306
|
-
|
|
10307
|
-
|
|
10308
|
-
identifier_or_criteria: tokenId,
|
|
10309
|
-
amount,
|
|
10310
|
-
// unit quantity
|
|
10311
|
-
recipient: account.address
|
|
10355
|
+
const { orderParams, typedData } = buildOffer1155Order(
|
|
10356
|
+
{
|
|
10357
|
+
offerer: account.address,
|
|
10358
|
+
nftContract,
|
|
10359
|
+
tokenId,
|
|
10360
|
+
quantity: amount,
|
|
10361
|
+
priceWeiPerUnit: priceWei,
|
|
10362
|
+
paymentTokenAddress: token.address,
|
|
10363
|
+
royaltyMaxBps,
|
|
10364
|
+
startTime,
|
|
10365
|
+
endTime,
|
|
10366
|
+
salt: generateSalt(),
|
|
10367
|
+
counter
|
|
10312
10368
|
},
|
|
10313
|
-
|
|
10314
|
-
start_time: (now + START_TIME_BUFFER_SECS).toString(),
|
|
10315
|
-
end_time: endTime.toString(),
|
|
10316
|
-
salt: generateSalt(),
|
|
10317
|
-
counter
|
|
10318
|
-
};
|
|
10319
|
-
const typedData = stringifyBigInts(
|
|
10320
|
-
build1155OrderTypedData(orderParams, chainId)
|
|
10369
|
+
config
|
|
10321
10370
|
);
|
|
10322
|
-
const
|
|
10323
|
-
const signatureArray = toSignatureArray(signature);
|
|
10324
|
-
const registerPayload = stringifyBigInts({
|
|
10325
|
-
parameters: {
|
|
10326
|
-
...orderParams,
|
|
10327
|
-
offer: {
|
|
10328
|
-
...orderParams.offer,
|
|
10329
|
-
item_type: starknet.shortString.encodeShortString(orderParams.offer.item_type)
|
|
10330
|
-
},
|
|
10331
|
-
consideration: {
|
|
10332
|
-
...orderParams.consideration,
|
|
10333
|
-
item_type: starknet.shortString.encodeShortString(orderParams.consideration.item_type)
|
|
10334
|
-
}
|
|
10335
|
-
},
|
|
10336
|
-
signature: signatureArray
|
|
10337
|
-
});
|
|
10371
|
+
const signatureArray = toSignatureArray(await account.signMessage(typedData));
|
|
10338
10372
|
const totalWei = BigInt(priceWei) * BigInt(amount);
|
|
10339
10373
|
const amountU256 = starknet.cairo.uint256(totalWei.toString());
|
|
10340
10374
|
const approveCall = {
|
|
@@ -10346,9 +10380,12 @@ async function makeOffer1155(account, params, config) {
|
|
|
10346
10380
|
amountU256.high.toString()
|
|
10347
10381
|
]
|
|
10348
10382
|
};
|
|
10349
|
-
const
|
|
10383
|
+
const calls = buildRegister1155Calls(
|
|
10384
|
+
{ orderParams, signature: signatureArray, approvalNeeded: true, approve: approveCall },
|
|
10385
|
+
config
|
|
10386
|
+
);
|
|
10350
10387
|
try {
|
|
10351
|
-
const tx = await account.execute(
|
|
10388
|
+
const tx = await account.execute(calls);
|
|
10352
10389
|
await provider.waitForTransaction(tx.transaction_hash);
|
|
10353
10390
|
return { txHash: tx.transaction_hash };
|
|
10354
10391
|
} catch (err) {
|
|
@@ -11166,94 +11203,147 @@ var StarknetVenue = class {
|
|
|
11166
11203
|
constructor(deps) {
|
|
11167
11204
|
this.deps = deps;
|
|
11168
11205
|
this.chain = "STARKNET";
|
|
11169
|
-
this.m721 = new MarketplaceModule(deps.config);
|
|
11170
|
-
this.m1155 = new Medialane1155Module(deps.config);
|
|
11171
11206
|
}
|
|
11172
|
-
incrementCounter(signer) {
|
|
11173
|
-
return
|
|
11207
|
+
async incrementCounter(signer) {
|
|
11208
|
+
return signer.execute([
|
|
11209
|
+
{ contractAddress: this.deps.config.marketplaceContract, entrypoint: "increment_counter", calldata: [] }
|
|
11210
|
+
]);
|
|
11174
11211
|
}
|
|
11175
11212
|
getOrderDetails(orderRef) {
|
|
11176
|
-
return this.
|
|
11213
|
+
return getOrderDetails(orderRef, this.deps.config);
|
|
11177
11214
|
}
|
|
11178
|
-
getCounter(address) {
|
|
11179
|
-
return this.
|
|
11215
|
+
async getCounter(address) {
|
|
11216
|
+
return this.readCounter(this.deps.config.marketplaceContract, address);
|
|
11180
11217
|
}
|
|
11181
11218
|
async fulfillOrder(signer, orderRef, opts) {
|
|
11182
11219
|
const o = await this.deps.resolveOrder(orderRef);
|
|
11183
11220
|
const quantity = opts?.quantity ?? "1";
|
|
11184
11221
|
const totalPrice = (BigInt(o.unitPrice) * BigInt(quantity)).toString();
|
|
11185
|
-
|
|
11186
|
-
|
|
11187
|
-
orderHash: orderRef,
|
|
11188
|
-
paymentToken: o.paymentToken,
|
|
11189
|
-
totalPrice,
|
|
11190
|
-
quantity
|
|
11191
|
-
});
|
|
11192
|
-
}
|
|
11193
|
-
return this.m721.fulfillOrder(signer, {
|
|
11194
|
-
orderHash: orderRef,
|
|
11195
|
-
paymentToken: o.paymentToken,
|
|
11196
|
-
totalPrice
|
|
11197
|
-
});
|
|
11222
|
+
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);
|
|
11223
|
+
return signer.execute(calls);
|
|
11198
11224
|
}
|
|
11199
11225
|
async cancelOrder(signer, orderRef) {
|
|
11200
11226
|
const o = await this.deps.resolveOrder(orderRef);
|
|
11201
|
-
|
|
11202
|
-
|
|
11203
|
-
}
|
|
11204
|
-
return
|
|
11227
|
+
const typedData = o.standard === "ERC1155" ? buildCancel1155TypedData(orderRef, signer.address, this.deps.config) : buildCancelTypedData(orderRef, signer.address, this.deps.config);
|
|
11228
|
+
const signature = await signer.signTypedData(typedData);
|
|
11229
|
+
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);
|
|
11230
|
+
return signer.execute(calls);
|
|
11205
11231
|
}
|
|
11206
11232
|
async registerOrder(signer, p) {
|
|
11207
11233
|
const standard = await this.deps.resolveStandard(p.asset.contract);
|
|
11208
|
-
const
|
|
11209
|
-
const humanPrice = formatAmount(p.amount, token.decimals);
|
|
11210
|
-
const durationSeconds = this.durationSeconds(p.endTime);
|
|
11234
|
+
const paymentTokenAddress = resolveToken(p.paymentToken).address;
|
|
11211
11235
|
const royaltyMaxBps = String(p.royaltyMaxBps);
|
|
11236
|
+
const startTime = Math.floor(Date.now() / 1e3) + START_TIME_BUFFER_SECS;
|
|
11237
|
+
const endTime = p.endTime && p.endTime > 0 ? p.endTime : startTime + NO_EXPIRY_SECONDS;
|
|
11212
11238
|
const quantity = p.quantity ?? "1";
|
|
11213
|
-
|
|
11239
|
+
const marketplace = standard === "ERC1155" ? this.deps.config.marketplace1155Contract : this.deps.config.marketplaceContract;
|
|
11240
|
+
const counter = String(await this.readCounter(marketplace, signer.address));
|
|
11241
|
+
let typedData;
|
|
11242
|
+
let buildCalls;
|
|
11214
11243
|
if (standard === "ERC1155") {
|
|
11215
|
-
|
|
11216
|
-
|
|
11244
|
+
const built = (p.side === "listing" ? buildListing1155Order : buildOffer1155Order)(
|
|
11245
|
+
{
|
|
11246
|
+
offerer: signer.address,
|
|
11217
11247
|
nftContract: p.asset.contract,
|
|
11218
11248
|
tokenId: p.asset.tokenId,
|
|
11219
|
-
|
|
11220
|
-
|
|
11221
|
-
|
|
11222
|
-
|
|
11223
|
-
|
|
11224
|
-
|
|
11225
|
-
|
|
11226
|
-
|
|
11227
|
-
|
|
11228
|
-
|
|
11249
|
+
quantity,
|
|
11250
|
+
priceWeiPerUnit: p.amount,
|
|
11251
|
+
paymentTokenAddress,
|
|
11252
|
+
royaltyMaxBps,
|
|
11253
|
+
startTime,
|
|
11254
|
+
endTime,
|
|
11255
|
+
salt: p.salt,
|
|
11256
|
+
counter
|
|
11257
|
+
},
|
|
11258
|
+
this.deps.config
|
|
11259
|
+
);
|
|
11260
|
+
typedData = built.typedData;
|
|
11261
|
+
const approval = p.side === "listing" ? await this.approval1155ForListing(signer.address, p.asset.contract) : this.approvalForErc20(paymentTokenAddress, (BigInt(p.amount) * BigInt(quantity)).toString(), marketplace);
|
|
11262
|
+
buildCalls = (sig) => buildRegister1155Calls({ orderParams: built.orderParams, signature: sig, ...approval }, this.deps.config);
|
|
11263
|
+
} else {
|
|
11264
|
+
const built = (p.side === "listing" ? buildListingOrder : buildOfferOrder)(
|
|
11265
|
+
{
|
|
11266
|
+
offerer: signer.address,
|
|
11229
11267
|
nftContract: p.asset.contract,
|
|
11230
11268
|
tokenId: p.asset.tokenId,
|
|
11231
|
-
|
|
11232
|
-
|
|
11233
|
-
|
|
11234
|
-
|
|
11235
|
-
|
|
11236
|
-
|
|
11237
|
-
|
|
11238
|
-
|
|
11239
|
-
|
|
11240
|
-
|
|
11241
|
-
|
|
11242
|
-
|
|
11243
|
-
|
|
11244
|
-
currency: p.paymentToken,
|
|
11245
|
-
durationSeconds,
|
|
11246
|
-
royaltyMaxBps
|
|
11247
|
-
};
|
|
11248
|
-
const res = p.side === "listing" ? await this.m721.createListing(signer, params) : await this.m721.makeOffer(signer, params);
|
|
11249
|
-
txHash = res.txHash;
|
|
11269
|
+
priceWei: p.amount,
|
|
11270
|
+
paymentTokenAddress,
|
|
11271
|
+
royaltyMaxBps,
|
|
11272
|
+
startTime,
|
|
11273
|
+
endTime,
|
|
11274
|
+
salt: p.salt,
|
|
11275
|
+
counter
|
|
11276
|
+
},
|
|
11277
|
+
this.deps.config
|
|
11278
|
+
);
|
|
11279
|
+
typedData = built.typedData;
|
|
11280
|
+
const approval = p.side === "listing" ? await this.approval721ForListing(signer.address, p.asset.contract, p.asset.tokenId) : this.approvalForErc20(paymentTokenAddress, p.amount, marketplace);
|
|
11281
|
+
buildCalls = (sig) => buildRegisterCalls({ orderParams: built.orderParams, signature: sig, ...approval }, this.deps.config);
|
|
11250
11282
|
}
|
|
11283
|
+
const signature = await signer.signTypedData(typedData);
|
|
11284
|
+
const { txHash } = await signer.execute(buildCalls(signature));
|
|
11251
11285
|
const orderRef = await this.orderRefFromReceipt(txHash);
|
|
11252
11286
|
return { txHash, orderRef };
|
|
11253
11287
|
}
|
|
11254
|
-
|
|
11255
|
-
|
|
11256
|
-
|
|
11288
|
+
// ─── reads (all on deps.provider) ─────────────────────────────────────────
|
|
11289
|
+
async readCounter(marketplace, address) {
|
|
11290
|
+
const res = await this.deps.provider.callContract({
|
|
11291
|
+
contractAddress: marketplace,
|
|
11292
|
+
entrypoint: "get_counter",
|
|
11293
|
+
calldata: [address]
|
|
11294
|
+
});
|
|
11295
|
+
return BigInt(res[0] ?? "0");
|
|
11296
|
+
}
|
|
11297
|
+
/** 721 listing approval: `get_approved(tokenId) == marketplace` ⇒ no approve. */
|
|
11298
|
+
async approval721ForListing(_owner, nftContract, tokenId) {
|
|
11299
|
+
const id = starknet.cairo.uint256(tokenId);
|
|
11300
|
+
const approve = {
|
|
11301
|
+
contractAddress: nftContract,
|
|
11302
|
+
entrypoint: "approve",
|
|
11303
|
+
calldata: [this.deps.config.marketplaceContract, id.low.toString(), id.high.toString()]
|
|
11304
|
+
};
|
|
11305
|
+
let approved = false;
|
|
11306
|
+
try {
|
|
11307
|
+
const res = await this.deps.provider.callContract({
|
|
11308
|
+
contractAddress: nftContract,
|
|
11309
|
+
entrypoint: "get_approved",
|
|
11310
|
+
calldata: [id.low.toString(), id.high.toString()]
|
|
11311
|
+
});
|
|
11312
|
+
approved = BigInt(res[0]).toString() === BigInt(this.deps.config.marketplaceContract).toString();
|
|
11313
|
+
} catch {
|
|
11314
|
+
}
|
|
11315
|
+
return { approvalNeeded: !approved, approve };
|
|
11316
|
+
}
|
|
11317
|
+
/** 1155 listing approval: `is_approved_for_all(owner, marketplace)`. */
|
|
11318
|
+
async approval1155ForListing(owner, nftContract) {
|
|
11319
|
+
const approve = {
|
|
11320
|
+
contractAddress: nftContract,
|
|
11321
|
+
entrypoint: "set_approval_for_all",
|
|
11322
|
+
calldata: [this.deps.config.marketplace1155Contract, "1"]
|
|
11323
|
+
};
|
|
11324
|
+
let approved = false;
|
|
11325
|
+
try {
|
|
11326
|
+
const res = await this.deps.provider.callContract({
|
|
11327
|
+
contractAddress: nftContract,
|
|
11328
|
+
entrypoint: "is_approved_for_all",
|
|
11329
|
+
calldata: [owner, this.deps.config.marketplace1155Contract]
|
|
11330
|
+
});
|
|
11331
|
+
approved = BigInt(res[0]) === 1n;
|
|
11332
|
+
} catch {
|
|
11333
|
+
}
|
|
11334
|
+
return { approvalNeeded: !approved, approve };
|
|
11335
|
+
}
|
|
11336
|
+
/** Offers always approve the ERC-20 spend (no read). */
|
|
11337
|
+
approvalForErc20(token, amountWei, marketplace) {
|
|
11338
|
+
const u = starknet.cairo.uint256(amountWei);
|
|
11339
|
+
return {
|
|
11340
|
+
approvalNeeded: true,
|
|
11341
|
+
approve: {
|
|
11342
|
+
contractAddress: token,
|
|
11343
|
+
entrypoint: "approve",
|
|
11344
|
+
calldata: [marketplace, u.low.toString(), u.high.toString()]
|
|
11345
|
+
}
|
|
11346
|
+
};
|
|
11257
11347
|
}
|
|
11258
11348
|
/** The canonical Starknet order id = the contract-emitted `OrderCreated`
|
|
11259
11349
|
* hash (`keys[1]`), which is exactly what the indexer stores. */
|