@medialane/sdk 0.64.0 → 0.65.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/index.cjs +63 -59
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +64 -60
- package/dist/index.js.map +1 -1
- package/dist/starknet/index.cjs +185 -183
- package/dist/starknet/index.cjs.map +1 -1
- package/dist/starknet/index.js +186 -184
- package/dist/starknet/index.js.map +1 -1
- package/package.json +4 -2
package/dist/starknet/index.cjs
CHANGED
|
@@ -855,6 +855,172 @@ var ApiClient = class {
|
|
|
855
855
|
}
|
|
856
856
|
};
|
|
857
857
|
|
|
858
|
+
// src/constants.ts
|
|
859
|
+
var SN = getCoordinates("STARKNET");
|
|
860
|
+
SN.marketplace721;
|
|
861
|
+
SN.marketplace721ClassHash;
|
|
862
|
+
SN.marketplace721StartBlock;
|
|
863
|
+
SN.marketplace1155;
|
|
864
|
+
SN.marketplace1155ClassHash;
|
|
865
|
+
SN.marketplace1155StartBlock;
|
|
866
|
+
SN.collection721;
|
|
867
|
+
SN.collection721StartBlock;
|
|
868
|
+
SN.ipNftClassHash;
|
|
869
|
+
SN.ipCollectionClassHash;
|
|
870
|
+
SN.collection1155;
|
|
871
|
+
SN.collection1155FactoryClassHash;
|
|
872
|
+
SN.collection1155ClassHash;
|
|
873
|
+
SN.collection1155StartBlock;
|
|
874
|
+
SN.popFactory;
|
|
875
|
+
SN.popCollectionClassHash;
|
|
876
|
+
SN.dropFactory;
|
|
877
|
+
SN.dropCollectionClassHash;
|
|
878
|
+
SN.nftComments;
|
|
879
|
+
SN.ipTicketsFactory;
|
|
880
|
+
SN.ipTicketCollectionClassHash;
|
|
881
|
+
SN.ipClubRegistry;
|
|
882
|
+
SN.ipClubNftClassHash;
|
|
883
|
+
SN.ipClubFactory;
|
|
884
|
+
SN.ipClubCollectionClassHash;
|
|
885
|
+
SN.ipSponsorship;
|
|
886
|
+
SN.ipSponsorshipLicense;
|
|
887
|
+
SN.creatorCoinFactory;
|
|
888
|
+
SN.creatorCoinEkuboLauncher;
|
|
889
|
+
SN.creatorCoinClassHash;
|
|
890
|
+
SN.creatorCoinFactoryClassHash;
|
|
891
|
+
SN.creatorCoinStartBlock;
|
|
892
|
+
SN.ekuboCore;
|
|
893
|
+
var SUPPORTED_TOKENS = [
|
|
894
|
+
{
|
|
895
|
+
// Circle-native USDC on Starknet (canonical)
|
|
896
|
+
symbol: "USDC",
|
|
897
|
+
address: "0x033068f6539f8e6e6b131e6b2b814e6c34a5224bc66947c47dab9dfee93b35fb",
|
|
898
|
+
decimals: 6,
|
|
899
|
+
listable: true
|
|
900
|
+
},
|
|
901
|
+
{
|
|
902
|
+
symbol: "USDT",
|
|
903
|
+
address: "0x068f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8",
|
|
904
|
+
decimals: 6,
|
|
905
|
+
listable: true
|
|
906
|
+
},
|
|
907
|
+
{
|
|
908
|
+
symbol: "ETH",
|
|
909
|
+
address: "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
|
|
910
|
+
decimals: 18,
|
|
911
|
+
listable: true
|
|
912
|
+
},
|
|
913
|
+
{
|
|
914
|
+
symbol: "STRK",
|
|
915
|
+
address: "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
|
|
916
|
+
decimals: 18,
|
|
917
|
+
listable: true
|
|
918
|
+
},
|
|
919
|
+
{
|
|
920
|
+
symbol: "WBTC",
|
|
921
|
+
address: "0x03fe2b97c1fd336e750087d68b9b867997fd64a2661ff3ca5a7c771641e8e7ac",
|
|
922
|
+
decimals: 8,
|
|
923
|
+
listable: true
|
|
924
|
+
}
|
|
925
|
+
];
|
|
926
|
+
|
|
927
|
+
// src/starknet/marketplace/errors.ts
|
|
928
|
+
var MedialaneError = class extends Error {
|
|
929
|
+
constructor(message, code = "UNKNOWN", cause) {
|
|
930
|
+
super(message);
|
|
931
|
+
this.code = code;
|
|
932
|
+
this.cause = cause;
|
|
933
|
+
this.name = "MedialaneError";
|
|
934
|
+
}
|
|
935
|
+
};
|
|
936
|
+
|
|
937
|
+
// src/utils/rpc.ts
|
|
938
|
+
var PUBLIC_RPC_FALLBACKS = [
|
|
939
|
+
"https://rpc.starknet.lava.build"
|
|
940
|
+
];
|
|
941
|
+
var TRANSIENT_BODY_RE = /"code"\s*:\s*-32001|"code"\s*:\s*-32603|unable to complete|rate.?limit|too many|throttl|exceed.*quota|temporarily unavailable|service unavailable|overload|gateway.*time|upstream.*time|backend.*error/i;
|
|
942
|
+
function isTransientRpcError(input) {
|
|
943
|
+
const { status, body } = input;
|
|
944
|
+
if (typeof status === "number" && (status === 429 || status >= 500)) return true;
|
|
945
|
+
if (body == null) return false;
|
|
946
|
+
if (typeof body === "object") {
|
|
947
|
+
const err = body.error;
|
|
948
|
+
if (!err || typeof err !== "object") return false;
|
|
949
|
+
const code = err.code;
|
|
950
|
+
if (typeof code === "number") {
|
|
951
|
+
if (code === 429) return true;
|
|
952
|
+
if (code >= -32099 && code <= -32e3) return true;
|
|
953
|
+
if (code === -32603) return true;
|
|
954
|
+
}
|
|
955
|
+
const message = err.message;
|
|
956
|
+
return typeof message === "string" ? TRANSIENT_BODY_RE.test(message) : false;
|
|
957
|
+
}
|
|
958
|
+
return TRANSIENT_BODY_RE.test(String(body));
|
|
959
|
+
}
|
|
960
|
+
function createFailoverFetch(urls, options = {}) {
|
|
961
|
+
const endpoints = urls.filter((u) => Boolean(u));
|
|
962
|
+
if (endpoints.length === 0) {
|
|
963
|
+
throw new Error("createFailoverFetch: at least one RPC URL is required");
|
|
964
|
+
}
|
|
965
|
+
const doFetch = options.baseFetch ?? fetch;
|
|
966
|
+
const failover = async (_input, init) => {
|
|
967
|
+
let lastError;
|
|
968
|
+
for (let i = 0; i < endpoints.length; i++) {
|
|
969
|
+
const url = endpoints[i];
|
|
970
|
+
const isLast = i === endpoints.length - 1;
|
|
971
|
+
try {
|
|
972
|
+
const res = await doFetch(url, init);
|
|
973
|
+
const text = await res.text();
|
|
974
|
+
const rebuilt = () => new Response(text, { status: res.status, statusText: res.statusText, headers: res.headers });
|
|
975
|
+
if (isLast || !isTransientRpcError({ status: res.status, body: text })) {
|
|
976
|
+
return rebuilt();
|
|
977
|
+
}
|
|
978
|
+
options.onFailover?.({ url, status: res.status });
|
|
979
|
+
} catch (err) {
|
|
980
|
+
lastError = err;
|
|
981
|
+
if (isLast) throw err;
|
|
982
|
+
options.onFailover?.({ url, error: err });
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
throw lastError ?? new Error("createFailoverFetch: all endpoints failed");
|
|
986
|
+
};
|
|
987
|
+
return failover;
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
// src/starknet/marketplace/utils.ts
|
|
991
|
+
var START_TIME_BUFFER_SECS = 30;
|
|
992
|
+
function newContract(abi, address, providerOrAccount) {
|
|
993
|
+
const C = starknet.Contract;
|
|
994
|
+
return C.length === 1 ? new starknet.Contract({ abi, address, providerOrAccount }) : new starknet.Contract(
|
|
995
|
+
abi,
|
|
996
|
+
address,
|
|
997
|
+
providerOrAccount
|
|
998
|
+
);
|
|
999
|
+
}
|
|
1000
|
+
function getChainId(config) {
|
|
1001
|
+
if (config.chain !== "STARKNET") {
|
|
1002
|
+
throw new Error(`SNIP-12 signing is Starknet-only; got chain "${config.chain}"`);
|
|
1003
|
+
}
|
|
1004
|
+
return starknet.constants.StarknetChainId.SN_MAIN;
|
|
1005
|
+
}
|
|
1006
|
+
function resolveToken(currency) {
|
|
1007
|
+
const token = SUPPORTED_TOKENS.find(
|
|
1008
|
+
(t) => t.symbol === currency.toUpperCase() || t.address.toLowerCase() === currency.toLowerCase()
|
|
1009
|
+
);
|
|
1010
|
+
if (!token) throw new MedialaneError(`Unsupported currency: ${currency}`, "INVALID_PARAMS");
|
|
1011
|
+
return token;
|
|
1012
|
+
}
|
|
1013
|
+
var _providerCache = /* @__PURE__ */ new WeakMap();
|
|
1014
|
+
function getProvider(config) {
|
|
1015
|
+
let p = _providerCache.get(config);
|
|
1016
|
+
if (!p) {
|
|
1017
|
+
const urls = Array.from(/* @__PURE__ */ new Set([config.rpcUrl, ...PUBLIC_RPC_FALLBACKS]));
|
|
1018
|
+
p = new starknet.RpcProvider({ nodeUrl: urls[0], baseFetch: createFailoverFetch(urls) });
|
|
1019
|
+
_providerCache.set(config, p);
|
|
1020
|
+
}
|
|
1021
|
+
return p;
|
|
1022
|
+
}
|
|
1023
|
+
|
|
858
1024
|
// src/starknet/abis/ipMarketplace.ts
|
|
859
1025
|
var IPMarketplaceABI = [
|
|
860
1026
|
{
|
|
@@ -10890,7 +11056,7 @@ var PopService = class {
|
|
|
10890
11056
|
this.factoryAddress = getStarknetCoordinates(config.chain).popFactory;
|
|
10891
11057
|
}
|
|
10892
11058
|
_collection(address, account) {
|
|
10893
|
-
return
|
|
11059
|
+
return newContract(POPCollectionABI, normalizeAddress("STARKNET", address), account);
|
|
10894
11060
|
}
|
|
10895
11061
|
async claim(account, collectionAddress) {
|
|
10896
11062
|
const call = this._collection(collectionAddress, account).populate("claim", []);
|
|
@@ -10939,7 +11105,7 @@ var PopService = class {
|
|
|
10939
11105
|
return { txHash: res.transaction_hash };
|
|
10940
11106
|
}
|
|
10941
11107
|
async createCollection(account, params) {
|
|
10942
|
-
const factory =
|
|
11108
|
+
const factory = newContract(POPFactoryABI, this.factoryAddress, account);
|
|
10943
11109
|
const call = factory.populate("create_collection", [
|
|
10944
11110
|
params.name,
|
|
10945
11111
|
params.symbol,
|
|
@@ -10981,7 +11147,7 @@ var DropService = class {
|
|
|
10981
11147
|
this.config = config;
|
|
10982
11148
|
}
|
|
10983
11149
|
_collection(address, account) {
|
|
10984
|
-
return
|
|
11150
|
+
return newContract(DropCollectionABI, normalizeAddress("STARKNET", address), account);
|
|
10985
11151
|
}
|
|
10986
11152
|
async claim(account, collectionAddress, quantity = 1) {
|
|
10987
11153
|
const collection = this._collection(collectionAddress, account);
|
|
@@ -11045,7 +11211,7 @@ var DropService = class {
|
|
|
11045
11211
|
return { txHash: res.transaction_hash };
|
|
11046
11212
|
}
|
|
11047
11213
|
async createDrop(account, params) {
|
|
11048
|
-
const factory =
|
|
11214
|
+
const factory = newContract(DropFactoryABI, this.factoryAddress, account);
|
|
11049
11215
|
const call = factory.populate("create_drop", [
|
|
11050
11216
|
params.name,
|
|
11051
11217
|
params.symbol,
|
|
@@ -11057,19 +11223,21 @@ var DropService = class {
|
|
|
11057
11223
|
return { txHash: res.transaction_hash };
|
|
11058
11224
|
}
|
|
11059
11225
|
};
|
|
11226
|
+
|
|
11227
|
+
// src/starknet/services/erc1155collection.ts
|
|
11060
11228
|
var ERC1155CollectionService = class {
|
|
11061
11229
|
constructor(config) {
|
|
11062
11230
|
this.factoryAddress = config.collection1155Contract ?? getStarknetCoordinates(config.chain).collection1155;
|
|
11063
11231
|
}
|
|
11064
11232
|
_factory(account) {
|
|
11065
|
-
return
|
|
11233
|
+
return newContract(
|
|
11066
11234
|
IPCollection1155FactoryABI,
|
|
11067
11235
|
normalizeAddress("STARKNET", this.factoryAddress),
|
|
11068
11236
|
account
|
|
11069
11237
|
);
|
|
11070
11238
|
}
|
|
11071
11239
|
_collection(address, account) {
|
|
11072
|
-
return
|
|
11240
|
+
return newContract(
|
|
11073
11241
|
IPCollection1155ABI,
|
|
11074
11242
|
normalizeAddress("STARKNET", address),
|
|
11075
11243
|
account
|
|
@@ -11178,75 +11346,6 @@ var ERC1155CollectionService = class {
|
|
|
11178
11346
|
}
|
|
11179
11347
|
};
|
|
11180
11348
|
|
|
11181
|
-
// src/constants.ts
|
|
11182
|
-
var SN = getCoordinates("STARKNET");
|
|
11183
|
-
SN.marketplace721;
|
|
11184
|
-
SN.marketplace721ClassHash;
|
|
11185
|
-
SN.marketplace721StartBlock;
|
|
11186
|
-
SN.marketplace1155;
|
|
11187
|
-
SN.marketplace1155ClassHash;
|
|
11188
|
-
SN.marketplace1155StartBlock;
|
|
11189
|
-
SN.collection721;
|
|
11190
|
-
SN.collection721StartBlock;
|
|
11191
|
-
SN.ipNftClassHash;
|
|
11192
|
-
SN.ipCollectionClassHash;
|
|
11193
|
-
SN.collection1155;
|
|
11194
|
-
SN.collection1155FactoryClassHash;
|
|
11195
|
-
SN.collection1155ClassHash;
|
|
11196
|
-
SN.collection1155StartBlock;
|
|
11197
|
-
SN.popFactory;
|
|
11198
|
-
SN.popCollectionClassHash;
|
|
11199
|
-
SN.dropFactory;
|
|
11200
|
-
SN.dropCollectionClassHash;
|
|
11201
|
-
SN.nftComments;
|
|
11202
|
-
SN.ipTicketsFactory;
|
|
11203
|
-
SN.ipTicketCollectionClassHash;
|
|
11204
|
-
SN.ipClubRegistry;
|
|
11205
|
-
SN.ipClubNftClassHash;
|
|
11206
|
-
SN.ipClubFactory;
|
|
11207
|
-
SN.ipClubCollectionClassHash;
|
|
11208
|
-
SN.ipSponsorship;
|
|
11209
|
-
SN.ipSponsorshipLicense;
|
|
11210
|
-
SN.creatorCoinFactory;
|
|
11211
|
-
SN.creatorCoinEkuboLauncher;
|
|
11212
|
-
SN.creatorCoinClassHash;
|
|
11213
|
-
SN.creatorCoinFactoryClassHash;
|
|
11214
|
-
SN.creatorCoinStartBlock;
|
|
11215
|
-
SN.ekuboCore;
|
|
11216
|
-
var SUPPORTED_TOKENS = [
|
|
11217
|
-
{
|
|
11218
|
-
// Circle-native USDC on Starknet (canonical)
|
|
11219
|
-
symbol: "USDC",
|
|
11220
|
-
address: "0x033068f6539f8e6e6b131e6b2b814e6c34a5224bc66947c47dab9dfee93b35fb",
|
|
11221
|
-
decimals: 6,
|
|
11222
|
-
listable: true
|
|
11223
|
-
},
|
|
11224
|
-
{
|
|
11225
|
-
symbol: "USDT",
|
|
11226
|
-
address: "0x068f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8",
|
|
11227
|
-
decimals: 6,
|
|
11228
|
-
listable: true
|
|
11229
|
-
},
|
|
11230
|
-
{
|
|
11231
|
-
symbol: "ETH",
|
|
11232
|
-
address: "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
|
|
11233
|
-
decimals: 18,
|
|
11234
|
-
listable: true
|
|
11235
|
-
},
|
|
11236
|
-
{
|
|
11237
|
-
symbol: "STRK",
|
|
11238
|
-
address: "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
|
|
11239
|
-
decimals: 18,
|
|
11240
|
-
listable: true
|
|
11241
|
-
},
|
|
11242
|
-
{
|
|
11243
|
-
symbol: "WBTC",
|
|
11244
|
-
address: "0x03fe2b97c1fd336e750087d68b9b867997fd64a2661ff3ca5a7c771641e8e7ac",
|
|
11245
|
-
decimals: 8,
|
|
11246
|
-
listable: true
|
|
11247
|
-
}
|
|
11248
|
-
];
|
|
11249
|
-
|
|
11250
11349
|
// src/utils/token.ts
|
|
11251
11350
|
function getTokenByAddress(address) {
|
|
11252
11351
|
const lower = address.toLowerCase();
|
|
@@ -11291,7 +11390,7 @@ async function getCreatorCoinPrice(coinAddress, provider) {
|
|
|
11291
11390
|
var _factoryContract = null;
|
|
11292
11391
|
function factoryContract() {
|
|
11293
11392
|
if (!_factoryContract) {
|
|
11294
|
-
_factoryContract =
|
|
11393
|
+
_factoryContract = newContract(
|
|
11295
11394
|
CreatorCoinFactoryABI,
|
|
11296
11395
|
getStarknetCoordinates("STARKNET").creatorCoinFactory
|
|
11297
11396
|
);
|
|
@@ -11361,7 +11460,7 @@ var CreatorCoinService = class {
|
|
|
11361
11460
|
this.config = config;
|
|
11362
11461
|
}
|
|
11363
11462
|
_factory(account) {
|
|
11364
|
-
return
|
|
11463
|
+
return newContract(CreatorCoinFactoryABI, this.factoryAddress, account);
|
|
11365
11464
|
}
|
|
11366
11465
|
/** Deploy a fixed-supply CreatorCoin (full supply minted to the Factory). */
|
|
11367
11466
|
async createCreatorCoin(account, params) {
|
|
@@ -11396,14 +11495,14 @@ var TicketService = class {
|
|
|
11396
11495
|
_factory(account, factoryAddress) {
|
|
11397
11496
|
const address = factoryAddress ?? this.factoryAddress;
|
|
11398
11497
|
if (!address) throw new Error("IP-Tickets factory address not configured for this chain");
|
|
11399
|
-
return
|
|
11498
|
+
return newContract(IPTicketCollectionFactoryABI, normalizeAddress("STARKNET", address), account);
|
|
11400
11499
|
}
|
|
11401
11500
|
_collection(address, account) {
|
|
11402
|
-
return
|
|
11501
|
+
return newContract(IPTicketCollectionABI, normalizeAddress("STARKNET", address), account);
|
|
11403
11502
|
}
|
|
11404
11503
|
_collectionRead(address) {
|
|
11405
11504
|
const provider = new starknet.RpcProvider({ nodeUrl: this.config.rpcUrl });
|
|
11406
|
-
return
|
|
11505
|
+
return newContract(IPTicketCollectionABI, normalizeAddress("STARKNET", address), provider);
|
|
11407
11506
|
}
|
|
11408
11507
|
/** Deploys a new IPTicketCollection via the factory. Caller becomes owner. */
|
|
11409
11508
|
async deployCollection(account, params) {
|
|
@@ -11478,15 +11577,15 @@ var ClubService = class {
|
|
|
11478
11577
|
_registry(account, registryAddress) {
|
|
11479
11578
|
const address = registryAddress ?? this.registryAddress;
|
|
11480
11579
|
if (!address) throw new Error("IP-Club registry address not configured for this chain");
|
|
11481
|
-
return
|
|
11580
|
+
return newContract(IPClubABI, normalizeAddress("STARKNET", address), account);
|
|
11482
11581
|
}
|
|
11483
11582
|
_factory(account, factoryAddress) {
|
|
11484
11583
|
const address = factoryAddress ?? this.factoryAddress;
|
|
11485
11584
|
if (!address) throw new Error("IP-Club factory address not configured for this chain");
|
|
11486
|
-
return
|
|
11585
|
+
return newContract(IPClubFactoryABI, normalizeAddress("STARKNET", address), account);
|
|
11487
11586
|
}
|
|
11488
11587
|
_collection(account, collectionAddress) {
|
|
11489
|
-
return
|
|
11588
|
+
return newContract(IPClubCollectionABI, normalizeAddress("STARKNET", collectionAddress), account);
|
|
11490
11589
|
}
|
|
11491
11590
|
/** Deploy a new per-creator membership ERC-721 collection via the factory. */
|
|
11492
11591
|
async deployClub(account, params) {
|
|
@@ -11598,7 +11697,7 @@ var SponsorshipService = class {
|
|
|
11598
11697
|
if (!resolved) {
|
|
11599
11698
|
throw new Error("IP-Sponsorship address not configured for this chain");
|
|
11600
11699
|
}
|
|
11601
|
-
return
|
|
11700
|
+
return newContract(IPSponsorshipABI, normalizeAddress("STARKNET", resolved), account);
|
|
11602
11701
|
}
|
|
11603
11702
|
/** The offer author must currently own (nftContract, tokenId) — enforced on-chain at create and accept. */
|
|
11604
11703
|
async createOffer(account, params) {
|
|
@@ -11667,7 +11766,7 @@ var SponsorshipService = class {
|
|
|
11667
11766
|
starknet.cairo.uint256(params.offerId),
|
|
11668
11767
|
params.sponsor
|
|
11669
11768
|
]);
|
|
11670
|
-
const receipt =
|
|
11769
|
+
const receipt = newContract(IPGenesisABI, normalizeAddress("STARKNET", receiptAddress), account);
|
|
11671
11770
|
const mintCall = receipt.populate("mint_item", [params.sponsor, params.licenseTermsUri]);
|
|
11672
11771
|
const res = await account.execute([acceptCall, mintCall]);
|
|
11673
11772
|
return { txHash: res.transaction_hash };
|
|
@@ -11687,7 +11786,7 @@ var SponsorshipService = class {
|
|
|
11687
11786
|
];
|
|
11688
11787
|
const receiptAddress = params.licenseReceiptAddress ?? this.licenseReceiptAddress;
|
|
11689
11788
|
if (receiptAddress && params.receiptTokenId != null) {
|
|
11690
|
-
const receipt =
|
|
11789
|
+
const receipt = newContract(IPGenesisABI, normalizeAddress("STARKNET", receiptAddress), account);
|
|
11691
11790
|
calls.push(receipt.populate("transfer_from", [account.address, params.to, starknet.cairo.uint256(params.receiptTokenId)]));
|
|
11692
11791
|
}
|
|
11693
11792
|
const res = await account.execute(calls);
|
|
@@ -11742,103 +11841,6 @@ var MedialaneClient = class {
|
|
|
11742
11841
|
}
|
|
11743
11842
|
};
|
|
11744
11843
|
|
|
11745
|
-
// src/starknet/marketplace/errors.ts
|
|
11746
|
-
var MedialaneError = class extends Error {
|
|
11747
|
-
constructor(message, code = "UNKNOWN", cause) {
|
|
11748
|
-
super(message);
|
|
11749
|
-
this.code = code;
|
|
11750
|
-
this.cause = cause;
|
|
11751
|
-
this.name = "MedialaneError";
|
|
11752
|
-
}
|
|
11753
|
-
};
|
|
11754
|
-
|
|
11755
|
-
// src/utils/rpc.ts
|
|
11756
|
-
var PUBLIC_RPC_FALLBACKS = [
|
|
11757
|
-
"https://rpc.starknet.lava.build"
|
|
11758
|
-
];
|
|
11759
|
-
var TRANSIENT_BODY_RE = /"code"\s*:\s*-32001|"code"\s*:\s*-32603|unable to complete|rate.?limit|too many|throttl|exceed.*quota|temporarily unavailable|service unavailable|overload|gateway.*time|upstream.*time|backend.*error/i;
|
|
11760
|
-
function isTransientRpcError(input) {
|
|
11761
|
-
const { status, body } = input;
|
|
11762
|
-
if (typeof status === "number" && (status === 429 || status >= 500)) return true;
|
|
11763
|
-
if (body == null) return false;
|
|
11764
|
-
if (typeof body === "object") {
|
|
11765
|
-
const err = body.error;
|
|
11766
|
-
if (!err || typeof err !== "object") return false;
|
|
11767
|
-
const code = err.code;
|
|
11768
|
-
if (typeof code === "number") {
|
|
11769
|
-
if (code === 429) return true;
|
|
11770
|
-
if (code >= -32099 && code <= -32e3) return true;
|
|
11771
|
-
if (code === -32603) return true;
|
|
11772
|
-
}
|
|
11773
|
-
const message = err.message;
|
|
11774
|
-
return typeof message === "string" ? TRANSIENT_BODY_RE.test(message) : false;
|
|
11775
|
-
}
|
|
11776
|
-
return TRANSIENT_BODY_RE.test(String(body));
|
|
11777
|
-
}
|
|
11778
|
-
function createFailoverFetch(urls, options = {}) {
|
|
11779
|
-
const endpoints = urls.filter((u) => Boolean(u));
|
|
11780
|
-
if (endpoints.length === 0) {
|
|
11781
|
-
throw new Error("createFailoverFetch: at least one RPC URL is required");
|
|
11782
|
-
}
|
|
11783
|
-
const doFetch = options.baseFetch ?? fetch;
|
|
11784
|
-
const failover = async (_input, init) => {
|
|
11785
|
-
let lastError;
|
|
11786
|
-
for (let i = 0; i < endpoints.length; i++) {
|
|
11787
|
-
const url = endpoints[i];
|
|
11788
|
-
const isLast = i === endpoints.length - 1;
|
|
11789
|
-
try {
|
|
11790
|
-
const res = await doFetch(url, init);
|
|
11791
|
-
const text = await res.text();
|
|
11792
|
-
const rebuilt = () => new Response(text, { status: res.status, statusText: res.statusText, headers: res.headers });
|
|
11793
|
-
if (isLast || !isTransientRpcError({ status: res.status, body: text })) {
|
|
11794
|
-
return rebuilt();
|
|
11795
|
-
}
|
|
11796
|
-
options.onFailover?.({ url, status: res.status });
|
|
11797
|
-
} catch (err) {
|
|
11798
|
-
lastError = err;
|
|
11799
|
-
if (isLast) throw err;
|
|
11800
|
-
options.onFailover?.({ url, error: err });
|
|
11801
|
-
}
|
|
11802
|
-
}
|
|
11803
|
-
throw lastError ?? new Error("createFailoverFetch: all endpoints failed");
|
|
11804
|
-
};
|
|
11805
|
-
return failover;
|
|
11806
|
-
}
|
|
11807
|
-
|
|
11808
|
-
// src/starknet/marketplace/utils.ts
|
|
11809
|
-
var START_TIME_BUFFER_SECS = 30;
|
|
11810
|
-
function newContract(abi, address, providerOrAccount) {
|
|
11811
|
-
const C = starknet.Contract;
|
|
11812
|
-
return C.length === 1 ? new starknet.Contract({ abi, address, providerOrAccount }) : new starknet.Contract(
|
|
11813
|
-
abi,
|
|
11814
|
-
address,
|
|
11815
|
-
providerOrAccount
|
|
11816
|
-
);
|
|
11817
|
-
}
|
|
11818
|
-
function getChainId(config) {
|
|
11819
|
-
if (config.chain !== "STARKNET") {
|
|
11820
|
-
throw new Error(`SNIP-12 signing is Starknet-only; got chain "${config.chain}"`);
|
|
11821
|
-
}
|
|
11822
|
-
return starknet.constants.StarknetChainId.SN_MAIN;
|
|
11823
|
-
}
|
|
11824
|
-
function resolveToken(currency) {
|
|
11825
|
-
const token = SUPPORTED_TOKENS.find(
|
|
11826
|
-
(t) => t.symbol === currency.toUpperCase() || t.address.toLowerCase() === currency.toLowerCase()
|
|
11827
|
-
);
|
|
11828
|
-
if (!token) throw new MedialaneError(`Unsupported currency: ${currency}`, "INVALID_PARAMS");
|
|
11829
|
-
return token;
|
|
11830
|
-
}
|
|
11831
|
-
var _providerCache = /* @__PURE__ */ new WeakMap();
|
|
11832
|
-
function getProvider(config) {
|
|
11833
|
-
let p = _providerCache.get(config);
|
|
11834
|
-
if (!p) {
|
|
11835
|
-
const urls = Array.from(/* @__PURE__ */ new Set([config.rpcUrl, ...PUBLIC_RPC_FALLBACKS]));
|
|
11836
|
-
p = new starknet.RpcProvider({ nodeUrl: urls[0], baseFetch: createFailoverFetch(urls) });
|
|
11837
|
-
_providerCache.set(config, p);
|
|
11838
|
-
}
|
|
11839
|
-
return p;
|
|
11840
|
-
}
|
|
11841
|
-
|
|
11842
11844
|
// src/starknet/marketplace/orders.ts
|
|
11843
11845
|
var _contractCache = /* @__PURE__ */ new WeakMap();
|
|
11844
11846
|
function makeContract(config) {
|