@medialane/sdk 0.6.6 → 0.6.8

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 CHANGED
@@ -7,11 +7,10 @@ var starknet = require('starknet');
7
7
 
8
8
  // src/constants.ts
9
9
  var MARKETPLACE_CONTRACT_MAINNET = "0x0234f4e8838801ebf01d7f4166d42aed9a55bc67c1301162decf9e2040e05f16";
10
+ var MARKETPLACE_1155_CONTRACT_MAINNET = "0x042005e9b85536072bfa260b95aa6aaef07f48e622031657384d2375195d7123";
10
11
  var COLLECTION_CONTRACT_MAINNET = "0x05c49ee5d3208a2c2e150fdd0c247d1195ed9ab54fa2d5dea7a633f39e4b205b";
11
12
  var DROP_FACTORY_CONTRACT_MAINNET = "0x03587f42e29daee1b193f6cf83bf8627908ed6632d0d83fcb26225c50547d800";
12
13
  var POP_FACTORY_CONTRACT_MAINNET = "0x00b32c34b427d8f346b5843ada6a37bd3368d879fc752cd52b68a87287f60111";
13
- var MARKETPLACE_CONTRACT_SEPOLIA = "";
14
- var COLLECTION_CONTRACT_SEPOLIA = "";
15
14
  var SUPPORTED_TOKENS = [
16
15
  {
17
16
  // Circle-native USDC on Starknet (canonical)
@@ -46,14 +45,134 @@ var SUPPORTED_TOKENS = [
46
45
  }
47
46
  ];
48
47
  var DEFAULT_CURRENCY = "USDC";
49
- var SUPPORTED_NETWORKS = ["mainnet", "sepolia"];
50
- var DEFAULT_RPC_URLS = {
51
- mainnet: "https://rpc.starknet.lava.build",
52
- sepolia: "https://rpc.starknet-sepolia.lava.build"
53
- };
48
+ var SUPPORTED_NETWORKS = ["mainnet"];
49
+ var DEFAULT_RPC_URL = "https://rpc.starknet.lava.build";
54
50
  var POP_COLLECTION_CLASS_HASH_MAINNET = "0x077c421686f10851872561953ea16898d933364b7f8937a5d7e2b1ba0a36263f";
55
51
  var DROP_COLLECTION_CLASS_HASH_MAINNET = "0x00092e72cdb63067521e803aaf7d4101c3e3ce026ae6bc045ec4228027e58282";
56
52
 
53
+ // src/config.ts
54
+ var MedialaneConfigSchema = zod.z.object({
55
+ network: zod.z.enum(SUPPORTED_NETWORKS).default("mainnet"),
56
+ rpcUrl: zod.z.string().url().optional(),
57
+ backendUrl: zod.z.string().url().optional(),
58
+ apiKey: zod.z.string().optional(),
59
+ marketplaceContract: zod.z.string().optional(),
60
+ marketplace1155Contract: zod.z.string().optional(),
61
+ collectionContract: zod.z.string().optional(),
62
+ retryOptions: zod.z.object({
63
+ maxAttempts: zod.z.number().int().min(1).max(10).optional(),
64
+ baseDelayMs: zod.z.number().int().min(0).optional(),
65
+ maxDelayMs: zod.z.number().int().min(0).optional()
66
+ }).optional()
67
+ });
68
+ function resolveConfig(raw) {
69
+ const parsed = MedialaneConfigSchema.parse(raw);
70
+ return {
71
+ network: parsed.network,
72
+ rpcUrl: parsed.rpcUrl ?? DEFAULT_RPC_URL,
73
+ backendUrl: parsed.backendUrl,
74
+ apiKey: parsed.apiKey,
75
+ marketplaceContract: parsed.marketplaceContract ?? MARKETPLACE_CONTRACT_MAINNET,
76
+ marketplace1155Contract: parsed.marketplace1155Contract ?? MARKETPLACE_1155_CONTRACT_MAINNET,
77
+ collectionContract: parsed.collectionContract ?? COLLECTION_CONTRACT_MAINNET,
78
+ retryOptions: parsed.retryOptions
79
+ };
80
+ }
81
+ function buildOrderTypedData(message, chainId) {
82
+ return {
83
+ domain: {
84
+ name: "Medialane",
85
+ version: "1",
86
+ chainId,
87
+ revision: starknet.TypedDataRevision.ACTIVE
88
+ },
89
+ primaryType: "OrderParameters",
90
+ types: {
91
+ StarknetDomain: [
92
+ { name: "name", type: "shortstring" },
93
+ { name: "version", type: "shortstring" },
94
+ { name: "chainId", type: "shortstring" },
95
+ { name: "revision", type: "shortstring" }
96
+ ],
97
+ OrderParameters: [
98
+ { name: "offerer", type: "ContractAddress" },
99
+ { name: "offer", type: "OfferItem" },
100
+ { name: "consideration", type: "ConsiderationItem" },
101
+ { name: "start_time", type: "felt" },
102
+ { name: "end_time", type: "felt" },
103
+ { name: "salt", type: "felt" },
104
+ { name: "nonce", type: "felt" }
105
+ ],
106
+ OfferItem: [
107
+ { name: "item_type", type: "shortstring" },
108
+ { name: "token", type: "ContractAddress" },
109
+ { name: "identifier_or_criteria", type: "felt" },
110
+ { name: "start_amount", type: "felt" },
111
+ { name: "end_amount", type: "felt" }
112
+ ],
113
+ ConsiderationItem: [
114
+ { name: "item_type", type: "shortstring" },
115
+ { name: "token", type: "ContractAddress" },
116
+ { name: "identifier_or_criteria", type: "felt" },
117
+ { name: "start_amount", type: "felt" },
118
+ { name: "end_amount", type: "felt" },
119
+ { name: "recipient", type: "ContractAddress" }
120
+ ]
121
+ },
122
+ message
123
+ };
124
+ }
125
+ function buildFulfillmentTypedData(message, chainId) {
126
+ return {
127
+ domain: {
128
+ name: "Medialane",
129
+ version: "1",
130
+ chainId,
131
+ revision: starknet.TypedDataRevision.ACTIVE
132
+ },
133
+ primaryType: "OrderFulfillment",
134
+ types: {
135
+ StarknetDomain: [
136
+ { name: "name", type: "shortstring" },
137
+ { name: "version", type: "shortstring" },
138
+ { name: "chainId", type: "shortstring" },
139
+ { name: "revision", type: "shortstring" }
140
+ ],
141
+ OrderFulfillment: [
142
+ { name: "order_hash", type: "felt" },
143
+ { name: "fulfiller", type: "ContractAddress" },
144
+ { name: "nonce", type: "felt" }
145
+ ]
146
+ },
147
+ message
148
+ };
149
+ }
150
+ function buildCancellationTypedData(message, chainId) {
151
+ return {
152
+ domain: {
153
+ name: "Medialane",
154
+ version: "1",
155
+ chainId,
156
+ revision: starknet.TypedDataRevision.ACTIVE
157
+ },
158
+ primaryType: "OrderCancellation",
159
+ types: {
160
+ StarknetDomain: [
161
+ { name: "name", type: "shortstring" },
162
+ { name: "version", type: "shortstring" },
163
+ { name: "chainId", type: "shortstring" },
164
+ { name: "revision", type: "shortstring" }
165
+ ],
166
+ OrderCancellation: [
167
+ { name: "order_hash", type: "felt" },
168
+ { name: "offerer", type: "ContractAddress" },
169
+ { name: "nonce", type: "felt" }
170
+ ]
171
+ },
172
+ message
173
+ };
174
+ }
175
+
57
176
  // src/abis.ts
58
177
  var IPMarketplaceABI = [
59
178
  {
@@ -759,147 +878,895 @@ var DropFactoryABI = [
759
878
  state_mutability: "external"
760
879
  }
761
880
  ];
762
-
763
- // src/utils/bigint.ts
764
- function stringifyBigInts(obj) {
765
- if (typeof obj === "bigint") {
766
- return obj.toString();
767
- }
768
- if (Array.isArray(obj)) {
769
- return obj.map(stringifyBigInts);
770
- }
771
- if (obj !== null && typeof obj === "object") {
772
- return Object.fromEntries(
773
- Object.entries(obj).map(([key, value]) => [
774
- key,
775
- stringifyBigInts(value)
776
- ])
777
- );
881
+ var CollectionRegistryABI = [
882
+ {
883
+ type: "struct",
884
+ name: "core::byte_array::ByteArray",
885
+ members: [
886
+ { name: "data", type: "core::array::Array::<core::felt252>" },
887
+ { name: "pending_word", type: "core::felt252" },
888
+ { name: "pending_word_len", type: "core::integer::u32" }
889
+ ]
890
+ },
891
+ {
892
+ type: "struct",
893
+ name: "ip_collection_erc_721::types::Collection",
894
+ members: [
895
+ { name: "name", type: "core::byte_array::ByteArray" },
896
+ { name: "symbol", type: "core::byte_array::ByteArray" },
897
+ { name: "base_uri", type: "core::byte_array::ByteArray" },
898
+ { name: "owner", type: "core::starknet::contract_address::ContractAddress" },
899
+ { name: "ip_nft", type: "core::starknet::contract_address::ContractAddress" },
900
+ { name: "is_active", type: "core::bool" }
901
+ ]
902
+ },
903
+ {
904
+ type: "function",
905
+ name: "list_user_collections",
906
+ inputs: [{ name: "user", type: "core::starknet::contract_address::ContractAddress" }],
907
+ outputs: [{ type: "core::array::Span::<core::integer::u256>" }],
908
+ state_mutability: "view"
909
+ },
910
+ {
911
+ type: "function",
912
+ name: "get_collection",
913
+ inputs: [{ name: "collection_id", type: "core::integer::u256" }],
914
+ outputs: [{ type: "ip_collection_erc_721::types::Collection" }],
915
+ state_mutability: "view"
778
916
  }
779
- return obj;
780
- }
781
- function u256ToBigInt(low, high) {
782
- return BigInt(low) + (BigInt(high) << 128n);
783
- }
784
-
785
- // src/utils/token.ts
786
- function parseAmount(human, decimals) {
787
- const [whole, frac = ""] = human.split(".");
788
- const fracPadded = frac.padEnd(decimals, "0").slice(0, decimals);
789
- return (BigInt(whole) * BigInt(10) ** BigInt(decimals) + BigInt(fracPadded)).toString();
790
- }
791
- function formatAmount(raw, decimals) {
792
- const value = BigInt(raw);
793
- const factor = BigInt(Math.pow(10, decimals));
794
- const whole = value / factor;
795
- const remainder = value % factor;
796
- const fractional = remainder.toString().padStart(decimals, "0");
797
- return `${whole}.${fractional}`;
798
- }
799
- function getTokenByAddress(address) {
800
- const lower = address.toLowerCase();
801
- return SUPPORTED_TOKENS.find((t) => t.address.toLowerCase() === lower);
802
- }
803
- function getTokenBySymbol(symbol) {
804
- const upper = symbol.toUpperCase();
805
- return SUPPORTED_TOKENS.find((t) => t.symbol === upper);
806
- }
807
- function getListableTokens() {
808
- return SUPPORTED_TOKENS.filter((t) => t.listable);
809
- }
810
- function buildOrderTypedData(message, chainId) {
811
- return {
812
- domain: {
813
- name: "Medialane",
814
- version: "1",
815
- chainId,
816
- revision: starknet.TypedDataRevision.ACTIVE
817
- },
818
- primaryType: "OrderParameters",
819
- types: {
820
- StarknetDomain: [
821
- { name: "name", type: "shortstring" },
822
- { name: "version", type: "shortstring" },
823
- { name: "chainId", type: "shortstring" },
824
- { name: "revision", type: "shortstring" }
825
- ],
826
- OrderParameters: [
827
- { name: "offerer", type: "ContractAddress" },
828
- { name: "offer", type: "OfferItem" },
829
- { name: "consideration", type: "ConsiderationItem" },
830
- { name: "start_time", type: "felt" },
831
- { name: "end_time", type: "felt" },
832
- { name: "salt", type: "felt" },
833
- { name: "nonce", type: "felt" }
834
- ],
835
- OfferItem: [
836
- { name: "item_type", type: "shortstring" },
837
- { name: "token", type: "ContractAddress" },
838
- { name: "identifier_or_criteria", type: "felt" },
839
- { name: "start_amount", type: "felt" },
840
- { name: "end_amount", type: "felt" }
841
- ],
842
- ConsiderationItem: [
843
- { name: "item_type", type: "shortstring" },
844
- { name: "token", type: "ContractAddress" },
845
- { name: "identifier_or_criteria", type: "felt" },
846
- { name: "start_amount", type: "felt" },
847
- { name: "end_amount", type: "felt" },
848
- { name: "recipient", type: "ContractAddress" }
849
- ]
850
- },
851
- message
852
- };
853
- }
854
- function buildFulfillmentTypedData(message, chainId) {
855
- return {
856
- domain: {
857
- name: "Medialane",
858
- version: "1",
859
- chainId,
860
- revision: starknet.TypedDataRevision.ACTIVE
861
- },
862
- primaryType: "OrderFulfillment",
863
- types: {
864
- StarknetDomain: [
865
- { name: "name", type: "shortstring" },
866
- { name: "version", type: "shortstring" },
867
- { name: "chainId", type: "shortstring" },
868
- { name: "revision", type: "shortstring" }
869
- ],
870
- OrderFulfillment: [
871
- { name: "order_hash", type: "felt" },
872
- { name: "fulfiller", type: "ContractAddress" },
873
- { name: "nonce", type: "felt" }
874
- ]
875
- },
876
- message
877
- };
917
+ ];
918
+ var Medialane1155ABI = [
919
+ {
920
+ "type": "impl",
921
+ "name": "UpgradeableImpl",
922
+ "interface_name": "openzeppelin_upgrades::interface::IUpgradeable"
923
+ },
924
+ {
925
+ "type": "interface",
926
+ "name": "openzeppelin_upgrades::interface::IUpgradeable",
927
+ "items": [
928
+ {
929
+ "type": "function",
930
+ "name": "upgrade",
931
+ "inputs": [
932
+ {
933
+ "name": "new_class_hash",
934
+ "type": "core::starknet::class_hash::ClassHash"
935
+ }
936
+ ],
937
+ "outputs": [],
938
+ "state_mutability": "external"
939
+ }
940
+ ]
941
+ },
942
+ {
943
+ "type": "impl",
944
+ "name": "Medialane1155Impl",
945
+ "interface_name": "medialane_erc1155::core::interface::IMedialane1155"
946
+ },
947
+ {
948
+ "type": "struct",
949
+ "name": "medialane_erc1155::core::types::OrderParameters",
950
+ "members": [
951
+ {
952
+ "name": "offerer",
953
+ "type": "core::starknet::contract_address::ContractAddress"
954
+ },
955
+ {
956
+ "name": "nft_contract",
957
+ "type": "core::starknet::contract_address::ContractAddress"
958
+ },
959
+ {
960
+ "name": "token_id",
961
+ "type": "core::felt252"
962
+ },
963
+ {
964
+ "name": "amount",
965
+ "type": "core::felt252"
966
+ },
967
+ {
968
+ "name": "payment_token",
969
+ "type": "core::starknet::contract_address::ContractAddress"
970
+ },
971
+ {
972
+ "name": "price_per_unit",
973
+ "type": "core::felt252"
974
+ },
975
+ {
976
+ "name": "start_time",
977
+ "type": "core::felt252"
978
+ },
979
+ {
980
+ "name": "end_time",
981
+ "type": "core::felt252"
982
+ },
983
+ {
984
+ "name": "salt",
985
+ "type": "core::felt252"
986
+ },
987
+ {
988
+ "name": "nonce",
989
+ "type": "core::felt252"
990
+ }
991
+ ]
992
+ },
993
+ {
994
+ "type": "struct",
995
+ "name": "medialane_erc1155::core::types::Order",
996
+ "members": [
997
+ {
998
+ "name": "parameters",
999
+ "type": "medialane_erc1155::core::types::OrderParameters"
1000
+ },
1001
+ {
1002
+ "name": "signature",
1003
+ "type": "core::array::Array::<core::felt252>"
1004
+ }
1005
+ ]
1006
+ },
1007
+ {
1008
+ "type": "struct",
1009
+ "name": "medialane_erc1155::core::types::OrderFulfillment",
1010
+ "members": [
1011
+ {
1012
+ "name": "order_hash",
1013
+ "type": "core::felt252"
1014
+ },
1015
+ {
1016
+ "name": "fulfiller",
1017
+ "type": "core::starknet::contract_address::ContractAddress"
1018
+ },
1019
+ {
1020
+ "name": "nonce",
1021
+ "type": "core::felt252"
1022
+ }
1023
+ ]
1024
+ },
1025
+ {
1026
+ "type": "struct",
1027
+ "name": "medialane_erc1155::core::types::FulfillmentRequest",
1028
+ "members": [
1029
+ {
1030
+ "name": "fulfillment",
1031
+ "type": "medialane_erc1155::core::types::OrderFulfillment"
1032
+ },
1033
+ {
1034
+ "name": "signature",
1035
+ "type": "core::array::Array::<core::felt252>"
1036
+ }
1037
+ ]
1038
+ },
1039
+ {
1040
+ "type": "struct",
1041
+ "name": "medialane_erc1155::core::types::OrderCancellation",
1042
+ "members": [
1043
+ {
1044
+ "name": "order_hash",
1045
+ "type": "core::felt252"
1046
+ },
1047
+ {
1048
+ "name": "offerer",
1049
+ "type": "core::starknet::contract_address::ContractAddress"
1050
+ },
1051
+ {
1052
+ "name": "nonce",
1053
+ "type": "core::felt252"
1054
+ }
1055
+ ]
1056
+ },
1057
+ {
1058
+ "type": "struct",
1059
+ "name": "medialane_erc1155::core::types::CancelRequest",
1060
+ "members": [
1061
+ {
1062
+ "name": "cancelation",
1063
+ "type": "medialane_erc1155::core::types::OrderCancellation"
1064
+ },
1065
+ {
1066
+ "name": "signature",
1067
+ "type": "core::array::Array::<core::felt252>"
1068
+ }
1069
+ ]
1070
+ },
1071
+ {
1072
+ "type": "enum",
1073
+ "name": "medialane_erc1155::core::types::OrderStatus",
1074
+ "variants": [
1075
+ {
1076
+ "name": "None",
1077
+ "type": "()"
1078
+ },
1079
+ {
1080
+ "name": "Created",
1081
+ "type": "()"
1082
+ },
1083
+ {
1084
+ "name": "Filled",
1085
+ "type": "()"
1086
+ },
1087
+ {
1088
+ "name": "Cancelled",
1089
+ "type": "()"
1090
+ }
1091
+ ]
1092
+ },
1093
+ {
1094
+ "type": "enum",
1095
+ "name": "core::option::Option::<core::starknet::contract_address::ContractAddress>",
1096
+ "variants": [
1097
+ {
1098
+ "name": "Some",
1099
+ "type": "core::starknet::contract_address::ContractAddress"
1100
+ },
1101
+ {
1102
+ "name": "None",
1103
+ "type": "()"
1104
+ }
1105
+ ]
1106
+ },
1107
+ {
1108
+ "type": "struct",
1109
+ "name": "medialane_erc1155::core::types::OrderDetails",
1110
+ "members": [
1111
+ {
1112
+ "name": "offerer",
1113
+ "type": "core::starknet::contract_address::ContractAddress"
1114
+ },
1115
+ {
1116
+ "name": "nft_contract",
1117
+ "type": "core::starknet::contract_address::ContractAddress"
1118
+ },
1119
+ {
1120
+ "name": "token_id",
1121
+ "type": "core::felt252"
1122
+ },
1123
+ {
1124
+ "name": "amount",
1125
+ "type": "core::felt252"
1126
+ },
1127
+ {
1128
+ "name": "payment_token",
1129
+ "type": "core::starknet::contract_address::ContractAddress"
1130
+ },
1131
+ {
1132
+ "name": "price_per_unit",
1133
+ "type": "core::felt252"
1134
+ },
1135
+ {
1136
+ "name": "start_time",
1137
+ "type": "core::integer::u64"
1138
+ },
1139
+ {
1140
+ "name": "end_time",
1141
+ "type": "core::integer::u64"
1142
+ },
1143
+ {
1144
+ "name": "order_status",
1145
+ "type": "medialane_erc1155::core::types::OrderStatus"
1146
+ },
1147
+ {
1148
+ "name": "fulfiller",
1149
+ "type": "core::option::Option::<core::starknet::contract_address::ContractAddress>"
1150
+ }
1151
+ ]
1152
+ },
1153
+ {
1154
+ "type": "interface",
1155
+ "name": "medialane_erc1155::core::interface::IMedialane1155",
1156
+ "items": [
1157
+ {
1158
+ "type": "function",
1159
+ "name": "register_order",
1160
+ "inputs": [
1161
+ {
1162
+ "name": "order",
1163
+ "type": "medialane_erc1155::core::types::Order"
1164
+ }
1165
+ ],
1166
+ "outputs": [],
1167
+ "state_mutability": "external"
1168
+ },
1169
+ {
1170
+ "type": "function",
1171
+ "name": "fulfill_order",
1172
+ "inputs": [
1173
+ {
1174
+ "name": "fulfillment_request",
1175
+ "type": "medialane_erc1155::core::types::FulfillmentRequest"
1176
+ }
1177
+ ],
1178
+ "outputs": [],
1179
+ "state_mutability": "external"
1180
+ },
1181
+ {
1182
+ "type": "function",
1183
+ "name": "cancel_order",
1184
+ "inputs": [
1185
+ {
1186
+ "name": "cancel_request",
1187
+ "type": "medialane_erc1155::core::types::CancelRequest"
1188
+ }
1189
+ ],
1190
+ "outputs": [],
1191
+ "state_mutability": "external"
1192
+ },
1193
+ {
1194
+ "type": "function",
1195
+ "name": "get_order_details",
1196
+ "inputs": [
1197
+ {
1198
+ "name": "order_hash",
1199
+ "type": "core::felt252"
1200
+ }
1201
+ ],
1202
+ "outputs": [
1203
+ {
1204
+ "type": "medialane_erc1155::core::types::OrderDetails"
1205
+ }
1206
+ ],
1207
+ "state_mutability": "view"
1208
+ },
1209
+ {
1210
+ "type": "function",
1211
+ "name": "get_order_hash",
1212
+ "inputs": [
1213
+ {
1214
+ "name": "parameters",
1215
+ "type": "medialane_erc1155::core::types::OrderParameters"
1216
+ },
1217
+ {
1218
+ "name": "signer",
1219
+ "type": "core::starknet::contract_address::ContractAddress"
1220
+ }
1221
+ ],
1222
+ "outputs": [
1223
+ {
1224
+ "type": "core::felt252"
1225
+ }
1226
+ ],
1227
+ "state_mutability": "view"
1228
+ },
1229
+ {
1230
+ "type": "function",
1231
+ "name": "get_native_token",
1232
+ "inputs": [],
1233
+ "outputs": [
1234
+ {
1235
+ "type": "core::starknet::contract_address::ContractAddress"
1236
+ }
1237
+ ],
1238
+ "state_mutability": "view"
1239
+ }
1240
+ ]
1241
+ },
1242
+ {
1243
+ "type": "impl",
1244
+ "name": "NoncesImpl",
1245
+ "interface_name": "openzeppelin_utils::cryptography::interface::INonces"
1246
+ },
1247
+ {
1248
+ "type": "interface",
1249
+ "name": "openzeppelin_utils::cryptography::interface::INonces",
1250
+ "items": [
1251
+ {
1252
+ "type": "function",
1253
+ "name": "nonces",
1254
+ "inputs": [
1255
+ {
1256
+ "name": "owner",
1257
+ "type": "core::starknet::contract_address::ContractAddress"
1258
+ }
1259
+ ],
1260
+ "outputs": [
1261
+ {
1262
+ "type": "core::felt252"
1263
+ }
1264
+ ],
1265
+ "state_mutability": "view"
1266
+ }
1267
+ ]
1268
+ },
1269
+ {
1270
+ "type": "impl",
1271
+ "name": "SRC5Impl",
1272
+ "interface_name": "openzeppelin_introspection::interface::ISRC5"
1273
+ },
1274
+ {
1275
+ "type": "enum",
1276
+ "name": "core::bool",
1277
+ "variants": [
1278
+ {
1279
+ "name": "False",
1280
+ "type": "()"
1281
+ },
1282
+ {
1283
+ "name": "True",
1284
+ "type": "()"
1285
+ }
1286
+ ]
1287
+ },
1288
+ {
1289
+ "type": "interface",
1290
+ "name": "openzeppelin_introspection::interface::ISRC5",
1291
+ "items": [
1292
+ {
1293
+ "type": "function",
1294
+ "name": "supports_interface",
1295
+ "inputs": [
1296
+ {
1297
+ "name": "interface_id",
1298
+ "type": "core::felt252"
1299
+ }
1300
+ ],
1301
+ "outputs": [
1302
+ {
1303
+ "type": "core::bool"
1304
+ }
1305
+ ],
1306
+ "state_mutability": "view"
1307
+ }
1308
+ ]
1309
+ },
1310
+ {
1311
+ "type": "impl",
1312
+ "name": "AccessControlImpl",
1313
+ "interface_name": "openzeppelin_access::accesscontrol::interface::IAccessControl"
1314
+ },
1315
+ {
1316
+ "type": "interface",
1317
+ "name": "openzeppelin_access::accesscontrol::interface::IAccessControl",
1318
+ "items": [
1319
+ {
1320
+ "type": "function",
1321
+ "name": "has_role",
1322
+ "inputs": [
1323
+ {
1324
+ "name": "role",
1325
+ "type": "core::felt252"
1326
+ },
1327
+ {
1328
+ "name": "account",
1329
+ "type": "core::starknet::contract_address::ContractAddress"
1330
+ }
1331
+ ],
1332
+ "outputs": [
1333
+ {
1334
+ "type": "core::bool"
1335
+ }
1336
+ ],
1337
+ "state_mutability": "view"
1338
+ },
1339
+ {
1340
+ "type": "function",
1341
+ "name": "get_role_admin",
1342
+ "inputs": [
1343
+ {
1344
+ "name": "role",
1345
+ "type": "core::felt252"
1346
+ }
1347
+ ],
1348
+ "outputs": [
1349
+ {
1350
+ "type": "core::felt252"
1351
+ }
1352
+ ],
1353
+ "state_mutability": "view"
1354
+ },
1355
+ {
1356
+ "type": "function",
1357
+ "name": "grant_role",
1358
+ "inputs": [
1359
+ {
1360
+ "name": "role",
1361
+ "type": "core::felt252"
1362
+ },
1363
+ {
1364
+ "name": "account",
1365
+ "type": "core::starknet::contract_address::ContractAddress"
1366
+ }
1367
+ ],
1368
+ "outputs": [],
1369
+ "state_mutability": "external"
1370
+ },
1371
+ {
1372
+ "type": "function",
1373
+ "name": "revoke_role",
1374
+ "inputs": [
1375
+ {
1376
+ "name": "role",
1377
+ "type": "core::felt252"
1378
+ },
1379
+ {
1380
+ "name": "account",
1381
+ "type": "core::starknet::contract_address::ContractAddress"
1382
+ }
1383
+ ],
1384
+ "outputs": [],
1385
+ "state_mutability": "external"
1386
+ },
1387
+ {
1388
+ "type": "function",
1389
+ "name": "renounce_role",
1390
+ "inputs": [
1391
+ {
1392
+ "name": "role",
1393
+ "type": "core::felt252"
1394
+ },
1395
+ {
1396
+ "name": "account",
1397
+ "type": "core::starknet::contract_address::ContractAddress"
1398
+ }
1399
+ ],
1400
+ "outputs": [],
1401
+ "state_mutability": "external"
1402
+ }
1403
+ ]
1404
+ },
1405
+ {
1406
+ "type": "constructor",
1407
+ "name": "constructor",
1408
+ "inputs": [
1409
+ {
1410
+ "name": "manager",
1411
+ "type": "core::starknet::contract_address::ContractAddress"
1412
+ },
1413
+ {
1414
+ "name": "native_token_address",
1415
+ "type": "core::starknet::contract_address::ContractAddress"
1416
+ }
1417
+ ]
1418
+ },
1419
+ {
1420
+ "type": "event",
1421
+ "name": "medialane_erc1155::core::events::OrderCreated",
1422
+ "kind": "struct",
1423
+ "members": [
1424
+ {
1425
+ "name": "order_hash",
1426
+ "type": "core::felt252",
1427
+ "kind": "key"
1428
+ },
1429
+ {
1430
+ "name": "offerer",
1431
+ "type": "core::starknet::contract_address::ContractAddress",
1432
+ "kind": "key"
1433
+ },
1434
+ {
1435
+ "name": "nft_contract",
1436
+ "type": "core::starknet::contract_address::ContractAddress",
1437
+ "kind": "data"
1438
+ },
1439
+ {
1440
+ "name": "token_id",
1441
+ "type": "core::felt252",
1442
+ "kind": "data"
1443
+ },
1444
+ {
1445
+ "name": "amount",
1446
+ "type": "core::felt252",
1447
+ "kind": "data"
1448
+ },
1449
+ {
1450
+ "name": "price_per_unit",
1451
+ "type": "core::felt252",
1452
+ "kind": "data"
1453
+ },
1454
+ {
1455
+ "name": "payment_token",
1456
+ "type": "core::starknet::contract_address::ContractAddress",
1457
+ "kind": "data"
1458
+ }
1459
+ ]
1460
+ },
1461
+ {
1462
+ "type": "struct",
1463
+ "name": "core::integer::u256",
1464
+ "members": [
1465
+ {
1466
+ "name": "low",
1467
+ "type": "core::integer::u128"
1468
+ },
1469
+ {
1470
+ "name": "high",
1471
+ "type": "core::integer::u128"
1472
+ }
1473
+ ]
1474
+ },
1475
+ {
1476
+ "type": "event",
1477
+ "name": "medialane_erc1155::core::events::OrderFulfilled",
1478
+ "kind": "struct",
1479
+ "members": [
1480
+ {
1481
+ "name": "order_hash",
1482
+ "type": "core::felt252",
1483
+ "kind": "key"
1484
+ },
1485
+ {
1486
+ "name": "offerer",
1487
+ "type": "core::starknet::contract_address::ContractAddress",
1488
+ "kind": "key"
1489
+ },
1490
+ {
1491
+ "name": "fulfiller",
1492
+ "type": "core::starknet::contract_address::ContractAddress",
1493
+ "kind": "key"
1494
+ },
1495
+ {
1496
+ "name": "royalty_receiver",
1497
+ "type": "core::starknet::contract_address::ContractAddress",
1498
+ "kind": "data"
1499
+ },
1500
+ {
1501
+ "name": "royalty_amount",
1502
+ "type": "core::integer::u256",
1503
+ "kind": "data"
1504
+ }
1505
+ ]
1506
+ },
1507
+ {
1508
+ "type": "event",
1509
+ "name": "medialane_erc1155::core::events::OrderCancelled",
1510
+ "kind": "struct",
1511
+ "members": [
1512
+ {
1513
+ "name": "order_hash",
1514
+ "type": "core::felt252",
1515
+ "kind": "key"
1516
+ },
1517
+ {
1518
+ "name": "offerer",
1519
+ "type": "core::starknet::contract_address::ContractAddress",
1520
+ "kind": "key"
1521
+ }
1522
+ ]
1523
+ },
1524
+ {
1525
+ "type": "event",
1526
+ "name": "openzeppelin_utils::cryptography::nonces::NoncesComponent::Event",
1527
+ "kind": "enum",
1528
+ "variants": []
1529
+ },
1530
+ {
1531
+ "type": "event",
1532
+ "name": "openzeppelin_upgrades::upgradeable::UpgradeableComponent::Upgraded",
1533
+ "kind": "struct",
1534
+ "members": [
1535
+ {
1536
+ "name": "class_hash",
1537
+ "type": "core::starknet::class_hash::ClassHash",
1538
+ "kind": "data"
1539
+ }
1540
+ ]
1541
+ },
1542
+ {
1543
+ "type": "event",
1544
+ "name": "openzeppelin_upgrades::upgradeable::UpgradeableComponent::Event",
1545
+ "kind": "enum",
1546
+ "variants": [
1547
+ {
1548
+ "name": "Upgraded",
1549
+ "type": "openzeppelin_upgrades::upgradeable::UpgradeableComponent::Upgraded",
1550
+ "kind": "nested"
1551
+ }
1552
+ ]
1553
+ },
1554
+ {
1555
+ "type": "event",
1556
+ "name": "openzeppelin_introspection::src5::SRC5Component::Event",
1557
+ "kind": "enum",
1558
+ "variants": []
1559
+ },
1560
+ {
1561
+ "type": "event",
1562
+ "name": "openzeppelin_access::accesscontrol::accesscontrol::AccessControlComponent::RoleGranted",
1563
+ "kind": "struct",
1564
+ "members": [
1565
+ {
1566
+ "name": "role",
1567
+ "type": "core::felt252",
1568
+ "kind": "data"
1569
+ },
1570
+ {
1571
+ "name": "account",
1572
+ "type": "core::starknet::contract_address::ContractAddress",
1573
+ "kind": "data"
1574
+ },
1575
+ {
1576
+ "name": "sender",
1577
+ "type": "core::starknet::contract_address::ContractAddress",
1578
+ "kind": "data"
1579
+ }
1580
+ ]
1581
+ },
1582
+ {
1583
+ "type": "event",
1584
+ "name": "openzeppelin_access::accesscontrol::accesscontrol::AccessControlComponent::RoleGrantedWithDelay",
1585
+ "kind": "struct",
1586
+ "members": [
1587
+ {
1588
+ "name": "role",
1589
+ "type": "core::felt252",
1590
+ "kind": "data"
1591
+ },
1592
+ {
1593
+ "name": "account",
1594
+ "type": "core::starknet::contract_address::ContractAddress",
1595
+ "kind": "data"
1596
+ },
1597
+ {
1598
+ "name": "sender",
1599
+ "type": "core::starknet::contract_address::ContractAddress",
1600
+ "kind": "data"
1601
+ },
1602
+ {
1603
+ "name": "delay",
1604
+ "type": "core::integer::u64",
1605
+ "kind": "data"
1606
+ }
1607
+ ]
1608
+ },
1609
+ {
1610
+ "type": "event",
1611
+ "name": "openzeppelin_access::accesscontrol::accesscontrol::AccessControlComponent::RoleRevoked",
1612
+ "kind": "struct",
1613
+ "members": [
1614
+ {
1615
+ "name": "role",
1616
+ "type": "core::felt252",
1617
+ "kind": "data"
1618
+ },
1619
+ {
1620
+ "name": "account",
1621
+ "type": "core::starknet::contract_address::ContractAddress",
1622
+ "kind": "data"
1623
+ },
1624
+ {
1625
+ "name": "sender",
1626
+ "type": "core::starknet::contract_address::ContractAddress",
1627
+ "kind": "data"
1628
+ }
1629
+ ]
1630
+ },
1631
+ {
1632
+ "type": "event",
1633
+ "name": "openzeppelin_access::accesscontrol::accesscontrol::AccessControlComponent::RoleAdminChanged",
1634
+ "kind": "struct",
1635
+ "members": [
1636
+ {
1637
+ "name": "role",
1638
+ "type": "core::felt252",
1639
+ "kind": "data"
1640
+ },
1641
+ {
1642
+ "name": "previous_admin_role",
1643
+ "type": "core::felt252",
1644
+ "kind": "data"
1645
+ },
1646
+ {
1647
+ "name": "new_admin_role",
1648
+ "type": "core::felt252",
1649
+ "kind": "data"
1650
+ }
1651
+ ]
1652
+ },
1653
+ {
1654
+ "type": "event",
1655
+ "name": "openzeppelin_access::accesscontrol::accesscontrol::AccessControlComponent::Event",
1656
+ "kind": "enum",
1657
+ "variants": [
1658
+ {
1659
+ "name": "RoleGranted",
1660
+ "type": "openzeppelin_access::accesscontrol::accesscontrol::AccessControlComponent::RoleGranted",
1661
+ "kind": "nested"
1662
+ },
1663
+ {
1664
+ "name": "RoleGrantedWithDelay",
1665
+ "type": "openzeppelin_access::accesscontrol::accesscontrol::AccessControlComponent::RoleGrantedWithDelay",
1666
+ "kind": "nested"
1667
+ },
1668
+ {
1669
+ "name": "RoleRevoked",
1670
+ "type": "openzeppelin_access::accesscontrol::accesscontrol::AccessControlComponent::RoleRevoked",
1671
+ "kind": "nested"
1672
+ },
1673
+ {
1674
+ "name": "RoleAdminChanged",
1675
+ "type": "openzeppelin_access::accesscontrol::accesscontrol::AccessControlComponent::RoleAdminChanged",
1676
+ "kind": "nested"
1677
+ }
1678
+ ]
1679
+ },
1680
+ {
1681
+ "type": "event",
1682
+ "name": "medialane_erc1155::core::medialane::Medialane1155::Event",
1683
+ "kind": "enum",
1684
+ "variants": [
1685
+ {
1686
+ "name": "OrderCreated",
1687
+ "type": "medialane_erc1155::core::events::OrderCreated",
1688
+ "kind": "nested"
1689
+ },
1690
+ {
1691
+ "name": "OrderFulfilled",
1692
+ "type": "medialane_erc1155::core::events::OrderFulfilled",
1693
+ "kind": "nested"
1694
+ },
1695
+ {
1696
+ "name": "OrderCancelled",
1697
+ "type": "medialane_erc1155::core::events::OrderCancelled",
1698
+ "kind": "nested"
1699
+ },
1700
+ {
1701
+ "name": "NoncesEvent",
1702
+ "type": "openzeppelin_utils::cryptography::nonces::NoncesComponent::Event",
1703
+ "kind": "flat"
1704
+ },
1705
+ {
1706
+ "name": "UpgradeableEvent",
1707
+ "type": "openzeppelin_upgrades::upgradeable::UpgradeableComponent::Event",
1708
+ "kind": "flat"
1709
+ },
1710
+ {
1711
+ "name": "SRC5Event",
1712
+ "type": "openzeppelin_introspection::src5::SRC5Component::Event",
1713
+ "kind": "flat"
1714
+ },
1715
+ {
1716
+ "name": "AccessControlEvent",
1717
+ "type": "openzeppelin_access::accesscontrol::accesscontrol::AccessControlComponent::Event",
1718
+ "kind": "flat"
1719
+ }
1720
+ ]
1721
+ }
1722
+ ];
1723
+
1724
+ // src/utils/bigint.ts
1725
+ function stringifyBigInts(obj) {
1726
+ if (typeof obj === "bigint") {
1727
+ return obj.toString();
1728
+ }
1729
+ if (Array.isArray(obj)) {
1730
+ return obj.map(stringifyBigInts);
1731
+ }
1732
+ if (obj !== null && typeof obj === "object") {
1733
+ return Object.fromEntries(
1734
+ Object.entries(obj).map(([key, value]) => [
1735
+ key,
1736
+ stringifyBigInts(value)
1737
+ ])
1738
+ );
1739
+ }
1740
+ return obj;
878
1741
  }
879
- function buildCancellationTypedData(message, chainId) {
880
- return {
881
- domain: {
882
- name: "Medialane",
883
- version: "1",
884
- chainId,
885
- revision: starknet.TypedDataRevision.ACTIVE
886
- },
887
- primaryType: "OrderCancellation",
888
- types: {
889
- StarknetDomain: [
890
- { name: "name", type: "shortstring" },
891
- { name: "version", type: "shortstring" },
892
- { name: "chainId", type: "shortstring" },
893
- { name: "revision", type: "shortstring" }
894
- ],
895
- OrderCancellation: [
896
- { name: "order_hash", type: "felt" },
897
- { name: "offerer", type: "ContractAddress" },
898
- { name: "nonce", type: "felt" }
899
- ]
900
- },
901
- message
902
- };
1742
+ function u256ToBigInt(low, high) {
1743
+ return BigInt(low) + (BigInt(high) << 128n);
1744
+ }
1745
+
1746
+ // src/utils/token.ts
1747
+ function parseAmount(human, decimals) {
1748
+ const [whole, frac = ""] = human.split(".");
1749
+ const fracPadded = frac.padEnd(decimals, "0").slice(0, decimals);
1750
+ return (BigInt(whole) * BigInt(10) ** BigInt(decimals) + BigInt(fracPadded)).toString();
1751
+ }
1752
+ function formatAmount(raw, decimals) {
1753
+ const value = BigInt(raw);
1754
+ const factor = BigInt(Math.pow(10, decimals));
1755
+ const whole = value / factor;
1756
+ const remainder = value % factor;
1757
+ const fractional = remainder.toString().padStart(decimals, "0");
1758
+ return `${whole}.${fractional}`;
1759
+ }
1760
+ function getTokenByAddress(address) {
1761
+ const lower = address.toLowerCase();
1762
+ return SUPPORTED_TOKENS.find((t) => t.address.toLowerCase() === lower);
1763
+ }
1764
+ function getTokenBySymbol(symbol) {
1765
+ const upper = symbol.toUpperCase();
1766
+ return SUPPORTED_TOKENS.find((t) => t.symbol === upper);
1767
+ }
1768
+ function getListableTokens() {
1769
+ return SUPPORTED_TOKENS.filter((t) => t.listable);
903
1770
  }
904
1771
 
905
1772
  // src/marketplace/orders.ts
@@ -916,8 +1783,8 @@ function toSignatureArray(sig) {
916
1783
  const s = sig;
917
1784
  return [s.r.toString(), s.s.toString()];
918
1785
  }
919
- function getChainId(config) {
920
- return config.network === "mainnet" ? starknet.constants.StarknetChainId.SN_MAIN : starknet.constants.StarknetChainId.SN_SEPOLIA;
1786
+ function getChainId(_config) {
1787
+ return starknet.constants.StarknetChainId.SN_MAIN;
921
1788
  }
922
1789
  var _contractCache = /* @__PURE__ */ new WeakMap();
923
1790
  var _providerCache = /* @__PURE__ */ new WeakMap();
@@ -983,7 +1850,7 @@ async function createListing(account, params, config) {
983
1850
  salt,
984
1851
  nonce: currentNonce.toString()
985
1852
  };
986
- const chainId = getChainId(config);
1853
+ const chainId = getChainId();
987
1854
  const typedData = stringifyBigInts(buildOrderTypedData(orderParams, chainId));
988
1855
  const signature = await account.signMessage(typedData);
989
1856
  const signatureArray = toSignatureArray(signature);
@@ -1067,7 +1934,7 @@ async function makeOffer(account, params, config) {
1067
1934
  salt,
1068
1935
  nonce: currentNonce.toString()
1069
1936
  };
1070
- const chainId = getChainId(config);
1937
+ const chainId = getChainId();
1071
1938
  const typedData = stringifyBigInts(buildOrderTypedData(orderParams, chainId));
1072
1939
  const signature = await account.signMessage(typedData);
1073
1940
  const signatureArray = toSignatureArray(signature);
@@ -1108,7 +1975,7 @@ async function fulfillOrder(account, params, config) {
1108
1975
  const { orderHash } = params;
1109
1976
  const { contract, provider } = makeContract(config);
1110
1977
  const currentNonce = await contract.nonces(account.address);
1111
- const chainId = getChainId(config);
1978
+ const chainId = getChainId();
1112
1979
  const fulfillmentParams = {
1113
1980
  order_hash: orderHash,
1114
1981
  fulfiller: account.address,
@@ -1136,7 +2003,7 @@ async function cancelOrder(account, params, config) {
1136
2003
  const { orderHash } = params;
1137
2004
  const { contract, provider } = makeContract(config);
1138
2005
  const currentNonce = await contract.nonces(account.address);
1139
- const chainId = getChainId(config);
2006
+ const chainId = getChainId();
1140
2007
  const cancelParams = {
1141
2008
  order_hash: orderHash,
1142
2009
  offerer: account.address,
@@ -1222,7 +2089,7 @@ async function checkoutCart(account, items, config) {
1222
2089
  });
1223
2090
  const currentNonce = await contract.nonces(account.address);
1224
2091
  const baseNonce = BigInt(currentNonce.toString());
1225
- const chainId = getChainId(config);
2092
+ const chainId = getChainId();
1226
2093
  const fulfillCalls = [];
1227
2094
  for (let i = 0; i < items.length; i++) {
1228
2095
  const item = items[i];
@@ -1252,45 +2119,6 @@ async function checkoutCart(account, items, config) {
1252
2119
  }
1253
2120
  }
1254
2121
 
1255
- // src/config.ts
1256
- var MedialaneConfigSchema = zod.z.object({
1257
- network: zod.z.enum(SUPPORTED_NETWORKS).default("mainnet"),
1258
- rpcUrl: zod.z.string().url().optional(),
1259
- backendUrl: zod.z.string().url().optional(),
1260
- /** API key for authenticated /v1/* backend endpoints */
1261
- apiKey: zod.z.string().optional(),
1262
- marketplaceContract: zod.z.string().optional(),
1263
- collectionContract: zod.z.string().optional(),
1264
- retryOptions: zod.z.object({
1265
- maxAttempts: zod.z.number().int().min(1).max(10).optional(),
1266
- baseDelayMs: zod.z.number().int().min(0).optional(),
1267
- maxDelayMs: zod.z.number().int().min(0).optional()
1268
- }).optional()
1269
- });
1270
- function resolveConfig(raw) {
1271
- const parsed = MedialaneConfigSchema.parse(raw);
1272
- const isMainnet = parsed.network === "mainnet";
1273
- const defaultMarketplace = isMainnet ? MARKETPLACE_CONTRACT_MAINNET : MARKETPLACE_CONTRACT_SEPOLIA;
1274
- const defaultCollection = isMainnet ? COLLECTION_CONTRACT_MAINNET : COLLECTION_CONTRACT_SEPOLIA;
1275
- const marketplaceContract = parsed.marketplaceContract ?? defaultMarketplace;
1276
- const collectionContract = parsed.collectionContract ?? defaultCollection;
1277
- if (!marketplaceContract || !collectionContract) {
1278
- throw new MedialaneError(
1279
- `Sepolia network is not yet supported: marketplace and collection contract addresses are not configured. Pass 'marketplaceContract' and 'collectionContract' explicitly in your MedialaneClient config.`,
1280
- "NETWORK_NOT_SUPPORTED"
1281
- );
1282
- }
1283
- return {
1284
- network: parsed.network,
1285
- rpcUrl: parsed.rpcUrl ?? DEFAULT_RPC_URLS[parsed.network],
1286
- backendUrl: parsed.backendUrl,
1287
- apiKey: parsed.apiKey,
1288
- marketplaceContract,
1289
- collectionContract,
1290
- retryOptions: parsed.retryOptions
1291
- };
1292
- }
1293
-
1294
2122
  // src/marketplace/index.ts
1295
2123
  var MarketplaceModule = class {
1296
2124
  constructor(config) {
@@ -1329,6 +2157,284 @@ var MarketplaceModule = class {
1329
2157
  return buildCancellationTypedData(params, chainId);
1330
2158
  }
1331
2159
  };
2160
+ var STARKNET_DOMAIN = [
2161
+ { name: "name", type: "shortstring" },
2162
+ { name: "version", type: "shortstring" },
2163
+ { name: "chainId", type: "shortstring" },
2164
+ { name: "revision", type: "shortstring" }
2165
+ ];
2166
+ function domain1155(chainId) {
2167
+ return {
2168
+ name: "Medialane1155",
2169
+ version: "1",
2170
+ chainId,
2171
+ revision: starknet.TypedDataRevision.ACTIVE
2172
+ };
2173
+ }
2174
+ function build1155OrderTypedData(message, chainId) {
2175
+ return {
2176
+ domain: domain1155(chainId),
2177
+ primaryType: "OrderParameters",
2178
+ types: {
2179
+ StarknetDomain: STARKNET_DOMAIN,
2180
+ OrderParameters: [
2181
+ { name: "offerer", type: "ContractAddress" },
2182
+ { name: "nft_contract", type: "ContractAddress" },
2183
+ { name: "token_id", type: "felt" },
2184
+ { name: "amount", type: "felt" },
2185
+ { name: "payment_token", type: "ContractAddress" },
2186
+ { name: "price_per_unit", type: "felt" },
2187
+ { name: "start_time", type: "felt" },
2188
+ { name: "end_time", type: "felt" },
2189
+ { name: "salt", type: "felt" },
2190
+ { name: "nonce", type: "felt" }
2191
+ ]
2192
+ },
2193
+ message
2194
+ };
2195
+ }
2196
+ function build1155FulfillmentTypedData(message, chainId) {
2197
+ return {
2198
+ domain: domain1155(chainId),
2199
+ primaryType: "OrderFulfillment",
2200
+ types: {
2201
+ StarknetDomain: STARKNET_DOMAIN,
2202
+ OrderFulfillment: [
2203
+ { name: "order_hash", type: "felt" },
2204
+ { name: "fulfiller", type: "ContractAddress" },
2205
+ { name: "nonce", type: "felt" }
2206
+ ]
2207
+ },
2208
+ message
2209
+ };
2210
+ }
2211
+ function build1155CancellationTypedData(message, chainId) {
2212
+ return {
2213
+ domain: domain1155(chainId),
2214
+ primaryType: "OrderCancellation",
2215
+ types: {
2216
+ StarknetDomain: STARKNET_DOMAIN,
2217
+ OrderCancellation: [
2218
+ { name: "order_hash", type: "felt" },
2219
+ { name: "offerer", type: "ContractAddress" },
2220
+ { name: "nonce", type: "felt" }
2221
+ ]
2222
+ },
2223
+ message
2224
+ };
2225
+ }
2226
+ function toSignatureArray2(sig) {
2227
+ if (Array.isArray(sig)) return sig;
2228
+ const s = sig;
2229
+ return [s.r.toString(), s.s.toString()];
2230
+ }
2231
+ function getChainId2(_config) {
2232
+ return starknet.constants.StarknetChainId.SN_MAIN;
2233
+ }
2234
+ var _providerCache2 = /* @__PURE__ */ new WeakMap();
2235
+ var _contractCache2 = /* @__PURE__ */ new WeakMap();
2236
+ function getProvider2(config) {
2237
+ let p = _providerCache2.get(config);
2238
+ if (!p) {
2239
+ p = new starknet.RpcProvider({ nodeUrl: config.rpcUrl });
2240
+ _providerCache2.set(config, p);
2241
+ }
2242
+ return p;
2243
+ }
2244
+ function getContract(config) {
2245
+ let c = _contractCache2.get(config);
2246
+ if (!c) {
2247
+ const provider = getProvider2(config);
2248
+ c = new starknet.Contract(
2249
+ Medialane1155ABI,
2250
+ config.marketplace1155Contract,
2251
+ provider
2252
+ );
2253
+ _contractCache2.set(config, c);
2254
+ }
2255
+ return c;
2256
+ }
2257
+ function resolveToken2(currency) {
2258
+ const token = SUPPORTED_TOKENS.find(
2259
+ (t) => t.symbol === currency.toUpperCase() || t.address.toLowerCase() === currency.toLowerCase()
2260
+ );
2261
+ if (!token) throw new MedialaneError(`Unsupported currency: ${currency}`, "INVALID_PARAMS");
2262
+ return token;
2263
+ }
2264
+ async function createListing1155(account, params, config) {
2265
+ const {
2266
+ nftContract,
2267
+ tokenId,
2268
+ amount,
2269
+ pricePerUnit,
2270
+ currency = DEFAULT_CURRENCY,
2271
+ durationSeconds
2272
+ } = params;
2273
+ const contract = getContract(config);
2274
+ const provider = getProvider2(config);
2275
+ const token = resolveToken2(currency);
2276
+ const priceWei = parseAmount(pricePerUnit, token.decimals);
2277
+ const now = Math.floor(Date.now() / 1e3);
2278
+ const endTime = now + durationSeconds;
2279
+ const saltBytes = new Uint8Array(4);
2280
+ crypto.getRandomValues(saltBytes);
2281
+ const salt = new DataView(saltBytes.buffer).getUint32(0).toString();
2282
+ const currentNonce = await contract.nonces(account.address);
2283
+ const chainId = getChainId2();
2284
+ const orderParams = {
2285
+ offerer: account.address,
2286
+ nft_contract: nftContract,
2287
+ token_id: tokenId,
2288
+ amount,
2289
+ payment_token: token.address,
2290
+ price_per_unit: priceWei,
2291
+ start_time: now.toString(),
2292
+ end_time: endTime.toString(),
2293
+ salt,
2294
+ nonce: currentNonce.toString()
2295
+ };
2296
+ const typedData = stringifyBigInts(
2297
+ build1155OrderTypedData(orderParams, chainId)
2298
+ );
2299
+ const signature = await account.signMessage(typedData);
2300
+ const signatureArray = toSignatureArray2(signature);
2301
+ const orderPayload = stringifyBigInts({
2302
+ parameters: orderParams,
2303
+ signature: signatureArray
2304
+ });
2305
+ let isApproved = false;
2306
+ try {
2307
+ const result = await provider.callContract({
2308
+ contractAddress: nftContract,
2309
+ entrypoint: "is_approved_for_all",
2310
+ calldata: [account.address, config.marketplace1155Contract]
2311
+ });
2312
+ isApproved = BigInt(result[0]) === 1n;
2313
+ } catch {
2314
+ }
2315
+ const registerCall = contract.populate("register_order", [orderPayload]);
2316
+ const calls = isApproved ? [registerCall] : [
2317
+ {
2318
+ contractAddress: nftContract,
2319
+ entrypoint: "set_approval_for_all",
2320
+ calldata: [config.marketplace1155Contract, "1"]
2321
+ },
2322
+ registerCall
2323
+ ];
2324
+ try {
2325
+ const tx = await account.execute(calls);
2326
+ await provider.waitForTransaction(tx.transaction_hash);
2327
+ return { txHash: tx.transaction_hash };
2328
+ } catch (err) {
2329
+ throw new MedialaneError("Failed to create ERC-1155 listing", "TRANSACTION_FAILED", err);
2330
+ }
2331
+ }
2332
+ async function fulfillOrder1155(account, params, config) {
2333
+ const { orderHash, paymentToken, totalPrice } = params;
2334
+ const contract = getContract(config);
2335
+ const provider = getProvider2(config);
2336
+ const chainId = getChainId2();
2337
+ const currentNonce = await contract.nonces(account.address);
2338
+ const fulfillmentParams = {
2339
+ order_hash: orderHash,
2340
+ fulfiller: account.address,
2341
+ nonce: currentNonce.toString()
2342
+ };
2343
+ const typedData = stringifyBigInts(
2344
+ build1155FulfillmentTypedData(fulfillmentParams, chainId)
2345
+ );
2346
+ const signature = await account.signMessage(typedData);
2347
+ const signatureArray = toSignatureArray2(signature);
2348
+ const fulfillPayload = stringifyBigInts({
2349
+ fulfillment: fulfillmentParams,
2350
+ signature: signatureArray
2351
+ });
2352
+ const totalPriceU256 = starknet.cairo.uint256(totalPrice);
2353
+ const approveCall = {
2354
+ contractAddress: paymentToken,
2355
+ entrypoint: "approve",
2356
+ calldata: [
2357
+ config.marketplace1155Contract,
2358
+ totalPriceU256.low.toString(),
2359
+ totalPriceU256.high.toString()
2360
+ ]
2361
+ };
2362
+ const fulfillCall = contract.populate("fulfill_order", [fulfillPayload]);
2363
+ try {
2364
+ const tx = await account.execute([approveCall, fulfillCall]);
2365
+ await provider.waitForTransaction(tx.transaction_hash);
2366
+ return { txHash: tx.transaction_hash };
2367
+ } catch (err) {
2368
+ throw new MedialaneError("Failed to fulfill ERC-1155 order", "TRANSACTION_FAILED", err);
2369
+ }
2370
+ }
2371
+ async function cancelOrder1155(account, params, config) {
2372
+ const { orderHash } = params;
2373
+ const contract = getContract(config);
2374
+ const provider = getProvider2(config);
2375
+ const chainId = getChainId2();
2376
+ const currentNonce = await contract.nonces(account.address);
2377
+ const cancelParams = {
2378
+ order_hash: orderHash,
2379
+ offerer: account.address,
2380
+ nonce: currentNonce.toString()
2381
+ };
2382
+ const typedData = stringifyBigInts(
2383
+ build1155CancellationTypedData(cancelParams, chainId)
2384
+ );
2385
+ const signature = await account.signMessage(typedData);
2386
+ const signatureArray = toSignatureArray2(signature);
2387
+ const cancelPayload = stringifyBigInts({
2388
+ cancelation: cancelParams,
2389
+ signature: signatureArray
2390
+ });
2391
+ const cancelCall = contract.populate("cancel_order", [cancelPayload]);
2392
+ try {
2393
+ const tx = await account.execute(cancelCall);
2394
+ await provider.waitForTransaction(tx.transaction_hash);
2395
+ return { txHash: tx.transaction_hash };
2396
+ } catch (err) {
2397
+ throw new MedialaneError("Failed to cancel ERC-1155 order", "TRANSACTION_FAILED", err);
2398
+ }
2399
+ }
2400
+
2401
+ // src/marketplace1155/index.ts
2402
+ var Medialane1155Module = class {
2403
+ constructor(config) {
2404
+ this.config = config;
2405
+ }
2406
+ // ─── Writes ───────────────────────────────────────────────────────────────
2407
+ /**
2408
+ * Create an ERC-1155 sell listing.
2409
+ * Optionally grants `set_approval_for_all` if not already approved.
2410
+ */
2411
+ createListing(account, params) {
2412
+ return createListing1155(account, params, this.config);
2413
+ }
2414
+ /**
2415
+ * Fulfill (buy) an ERC-1155 listing.
2416
+ * Approves the payment token then calls `fulfill_order` atomically.
2417
+ */
2418
+ fulfillOrder(account, params) {
2419
+ return fulfillOrder1155(account, params, this.config);
2420
+ }
2421
+ /**
2422
+ * Cancel an ERC-1155 listing (offerer only).
2423
+ */
2424
+ cancelOrder(account, params) {
2425
+ return cancelOrder1155(account, params, this.config);
2426
+ }
2427
+ // ─── Typed data builders (for ChipiPay / custom signing flows) ───────────
2428
+ buildListingTypedData(params, chainId) {
2429
+ return build1155OrderTypedData(params, chainId);
2430
+ }
2431
+ buildFulfillmentTypedData(params, chainId) {
2432
+ return build1155FulfillmentTypedData(params, chainId);
2433
+ }
2434
+ buildCancellationTypedData(params, chainId) {
2435
+ return build1155CancellationTypedData(params, chainId);
2436
+ }
2437
+ };
1332
2438
 
1333
2439
  // src/utils/address.ts
1334
2440
  function normalizeAddress(address) {
@@ -2031,6 +3137,7 @@ var MedialaneClient = class {
2031
3137
  constructor(rawConfig = {}) {
2032
3138
  this.config = resolveConfig(rawConfig);
2033
3139
  this.marketplace = new MarketplaceModule(this.config);
3140
+ this.marketplace1155 = new Medialane1155Module(this.config);
2034
3141
  this.services = {
2035
3142
  pop: new PopService(this.config),
2036
3143
  drop: new DropService(this.config)
@@ -2065,15 +3172,19 @@ var OPEN_LICENSES = ["CC0", "CC BY", "CC BY-SA", "CC BY-NC"];
2065
3172
 
2066
3173
  exports.ApiClient = ApiClient;
2067
3174
  exports.COLLECTION_CONTRACT_MAINNET = COLLECTION_CONTRACT_MAINNET;
2068
- exports.DEFAULT_RPC_URLS = DEFAULT_RPC_URLS;
3175
+ exports.CollectionRegistryABI = CollectionRegistryABI;
3176
+ exports.DEFAULT_RPC_URL = DEFAULT_RPC_URL;
2069
3177
  exports.DROP_COLLECTION_CLASS_HASH_MAINNET = DROP_COLLECTION_CLASS_HASH_MAINNET;
2070
3178
  exports.DROP_FACTORY_CONTRACT_MAINNET = DROP_FACTORY_CONTRACT_MAINNET;
2071
3179
  exports.DropCollectionABI = DropCollectionABI;
2072
3180
  exports.DropFactoryABI = DropFactoryABI;
2073
3181
  exports.DropService = DropService;
2074
3182
  exports.IPMarketplaceABI = IPMarketplaceABI;
3183
+ exports.MARKETPLACE_1155_CONTRACT_MAINNET = MARKETPLACE_1155_CONTRACT_MAINNET;
2075
3184
  exports.MARKETPLACE_CONTRACT_MAINNET = MARKETPLACE_CONTRACT_MAINNET;
2076
3185
  exports.MarketplaceModule = MarketplaceModule;
3186
+ exports.Medialane1155ABI = Medialane1155ABI;
3187
+ exports.Medialane1155Module = Medialane1155Module;
2077
3188
  exports.MedialaneApiError = MedialaneApiError;
2078
3189
  exports.MedialaneClient = MedialaneClient;
2079
3190
  exports.MedialaneError = MedialaneError;
@@ -2085,6 +3196,9 @@ exports.POP_FACTORY_CONTRACT_MAINNET = POP_FACTORY_CONTRACT_MAINNET;
2085
3196
  exports.PopService = PopService;
2086
3197
  exports.SUPPORTED_NETWORKS = SUPPORTED_NETWORKS;
2087
3198
  exports.SUPPORTED_TOKENS = SUPPORTED_TOKENS;
3199
+ exports.build1155CancellationTypedData = build1155CancellationTypedData;
3200
+ exports.build1155FulfillmentTypedData = build1155FulfillmentTypedData;
3201
+ exports.build1155OrderTypedData = build1155OrderTypedData;
2088
3202
  exports.buildCancellationTypedData = buildCancellationTypedData;
2089
3203
  exports.buildFulfillmentTypedData = buildFulfillmentTypedData;
2090
3204
  exports.buildOrderTypedData = buildOrderTypedData;