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