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