@campnetwork/origin 1.2.6 → 1.2.7
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/core.cjs +185 -79
- package/dist/core.d.ts +138 -1
- package/dist/core.esm.d.ts +138 -1
- package/dist/core.esm.js +189 -83
- package/dist/react/index.esm.d.ts +127 -0
- package/dist/react/index.esm.js +550 -0
- package/package.json +1 -1
package/dist/react/index.esm.js
CHANGED
|
@@ -2959,6 +2959,369 @@ var tbaAbi = [
|
|
|
2959
2959
|
}
|
|
2960
2960
|
];
|
|
2961
2961
|
|
|
2962
|
+
var batchPurchaseAbi = [
|
|
2963
|
+
{
|
|
2964
|
+
inputs: [
|
|
2965
|
+
{
|
|
2966
|
+
internalType: "address",
|
|
2967
|
+
name: "_marketplace",
|
|
2968
|
+
type: "address"
|
|
2969
|
+
},
|
|
2970
|
+
{
|
|
2971
|
+
internalType: "address",
|
|
2972
|
+
name: "_ipNFT",
|
|
2973
|
+
type: "address"
|
|
2974
|
+
}
|
|
2975
|
+
],
|
|
2976
|
+
stateMutability: "nonpayable",
|
|
2977
|
+
type: "constructor"
|
|
2978
|
+
},
|
|
2979
|
+
{
|
|
2980
|
+
inputs: [
|
|
2981
|
+
],
|
|
2982
|
+
name: "EmptyPurchaseList",
|
|
2983
|
+
type: "error"
|
|
2984
|
+
},
|
|
2985
|
+
{
|
|
2986
|
+
inputs: [
|
|
2987
|
+
],
|
|
2988
|
+
name: "InvalidTotalPayment",
|
|
2989
|
+
type: "error"
|
|
2990
|
+
},
|
|
2991
|
+
{
|
|
2992
|
+
inputs: [
|
|
2993
|
+
{
|
|
2994
|
+
internalType: "uint256",
|
|
2995
|
+
name: "tokenId",
|
|
2996
|
+
type: "uint256"
|
|
2997
|
+
},
|
|
2998
|
+
{
|
|
2999
|
+
internalType: "string",
|
|
3000
|
+
name: "reason",
|
|
3001
|
+
type: "string"
|
|
3002
|
+
}
|
|
3003
|
+
],
|
|
3004
|
+
name: "PurchaseFailed",
|
|
3005
|
+
type: "error"
|
|
3006
|
+
},
|
|
3007
|
+
{
|
|
3008
|
+
inputs: [
|
|
3009
|
+
],
|
|
3010
|
+
name: "RefundFailed",
|
|
3011
|
+
type: "error"
|
|
3012
|
+
},
|
|
3013
|
+
{
|
|
3014
|
+
inputs: [
|
|
3015
|
+
],
|
|
3016
|
+
name: "ZeroAddress",
|
|
3017
|
+
type: "error"
|
|
3018
|
+
},
|
|
3019
|
+
{
|
|
3020
|
+
anonymous: false,
|
|
3021
|
+
inputs: [
|
|
3022
|
+
{
|
|
3023
|
+
indexed: true,
|
|
3024
|
+
internalType: "address",
|
|
3025
|
+
name: "buyer",
|
|
3026
|
+
type: "address"
|
|
3027
|
+
},
|
|
3028
|
+
{
|
|
3029
|
+
indexed: false,
|
|
3030
|
+
internalType: "uint256",
|
|
3031
|
+
name: "count",
|
|
3032
|
+
type: "uint256"
|
|
3033
|
+
},
|
|
3034
|
+
{
|
|
3035
|
+
indexed: false,
|
|
3036
|
+
internalType: "uint256",
|
|
3037
|
+
name: "totalPaid",
|
|
3038
|
+
type: "uint256"
|
|
3039
|
+
}
|
|
3040
|
+
],
|
|
3041
|
+
name: "BulkPurchaseExecuted",
|
|
3042
|
+
type: "event"
|
|
3043
|
+
},
|
|
3044
|
+
{
|
|
3045
|
+
anonymous: false,
|
|
3046
|
+
inputs: [
|
|
3047
|
+
{
|
|
3048
|
+
indexed: true,
|
|
3049
|
+
internalType: "address",
|
|
3050
|
+
name: "buyer",
|
|
3051
|
+
type: "address"
|
|
3052
|
+
},
|
|
3053
|
+
{
|
|
3054
|
+
indexed: false,
|
|
3055
|
+
internalType: "uint256",
|
|
3056
|
+
name: "successCount",
|
|
3057
|
+
type: "uint256"
|
|
3058
|
+
},
|
|
3059
|
+
{
|
|
3060
|
+
indexed: false,
|
|
3061
|
+
internalType: "uint256",
|
|
3062
|
+
name: "failureCount",
|
|
3063
|
+
type: "uint256"
|
|
3064
|
+
},
|
|
3065
|
+
{
|
|
3066
|
+
indexed: false,
|
|
3067
|
+
internalType: "uint256[]",
|
|
3068
|
+
name: "failedTokenIds",
|
|
3069
|
+
type: "uint256[]"
|
|
3070
|
+
}
|
|
3071
|
+
],
|
|
3072
|
+
name: "BulkPurchasePartial",
|
|
3073
|
+
type: "event"
|
|
3074
|
+
},
|
|
3075
|
+
{
|
|
3076
|
+
inputs: [
|
|
3077
|
+
{
|
|
3078
|
+
internalType: "address",
|
|
3079
|
+
name: "buyer",
|
|
3080
|
+
type: "address"
|
|
3081
|
+
},
|
|
3082
|
+
{
|
|
3083
|
+
components: [
|
|
3084
|
+
{
|
|
3085
|
+
internalType: "uint256",
|
|
3086
|
+
name: "tokenId",
|
|
3087
|
+
type: "uint256"
|
|
3088
|
+
},
|
|
3089
|
+
{
|
|
3090
|
+
internalType: "uint256",
|
|
3091
|
+
name: "expectedPrice",
|
|
3092
|
+
type: "uint256"
|
|
3093
|
+
},
|
|
3094
|
+
{
|
|
3095
|
+
internalType: "uint32",
|
|
3096
|
+
name: "expectedDuration",
|
|
3097
|
+
type: "uint32"
|
|
3098
|
+
},
|
|
3099
|
+
{
|
|
3100
|
+
internalType: "address",
|
|
3101
|
+
name: "expectedPaymentToken",
|
|
3102
|
+
type: "address"
|
|
3103
|
+
}
|
|
3104
|
+
],
|
|
3105
|
+
internalType: "struct IBatchPurchase.BuyParams[]",
|
|
3106
|
+
name: "purchases",
|
|
3107
|
+
type: "tuple[]"
|
|
3108
|
+
}
|
|
3109
|
+
],
|
|
3110
|
+
name: "bulkBuyAccess",
|
|
3111
|
+
outputs: [
|
|
3112
|
+
{
|
|
3113
|
+
internalType: "uint256",
|
|
3114
|
+
name: "totalPaid",
|
|
3115
|
+
type: "uint256"
|
|
3116
|
+
}
|
|
3117
|
+
],
|
|
3118
|
+
stateMutability: "payable",
|
|
3119
|
+
type: "function"
|
|
3120
|
+
},
|
|
3121
|
+
{
|
|
3122
|
+
inputs: [
|
|
3123
|
+
{
|
|
3124
|
+
internalType: "address",
|
|
3125
|
+
name: "buyer",
|
|
3126
|
+
type: "address"
|
|
3127
|
+
},
|
|
3128
|
+
{
|
|
3129
|
+
components: [
|
|
3130
|
+
{
|
|
3131
|
+
internalType: "uint256",
|
|
3132
|
+
name: "tokenId",
|
|
3133
|
+
type: "uint256"
|
|
3134
|
+
},
|
|
3135
|
+
{
|
|
3136
|
+
internalType: "uint256",
|
|
3137
|
+
name: "expectedPrice",
|
|
3138
|
+
type: "uint256"
|
|
3139
|
+
},
|
|
3140
|
+
{
|
|
3141
|
+
internalType: "uint32",
|
|
3142
|
+
name: "expectedDuration",
|
|
3143
|
+
type: "uint32"
|
|
3144
|
+
},
|
|
3145
|
+
{
|
|
3146
|
+
internalType: "address",
|
|
3147
|
+
name: "expectedPaymentToken",
|
|
3148
|
+
type: "address"
|
|
3149
|
+
}
|
|
3150
|
+
],
|
|
3151
|
+
internalType: "struct IBatchPurchase.BuyParams[]",
|
|
3152
|
+
name: "purchases",
|
|
3153
|
+
type: "tuple[]"
|
|
3154
|
+
}
|
|
3155
|
+
],
|
|
3156
|
+
name: "bulkBuyAccessTolerant",
|
|
3157
|
+
outputs: [
|
|
3158
|
+
{
|
|
3159
|
+
components: [
|
|
3160
|
+
{
|
|
3161
|
+
internalType: "uint256",
|
|
3162
|
+
name: "successCount",
|
|
3163
|
+
type: "uint256"
|
|
3164
|
+
},
|
|
3165
|
+
{
|
|
3166
|
+
internalType: "uint256",
|
|
3167
|
+
name: "failureCount",
|
|
3168
|
+
type: "uint256"
|
|
3169
|
+
},
|
|
3170
|
+
{
|
|
3171
|
+
internalType: "uint256",
|
|
3172
|
+
name: "totalSpent",
|
|
3173
|
+
type: "uint256"
|
|
3174
|
+
},
|
|
3175
|
+
{
|
|
3176
|
+
internalType: "uint256",
|
|
3177
|
+
name: "refundAmount",
|
|
3178
|
+
type: "uint256"
|
|
3179
|
+
},
|
|
3180
|
+
{
|
|
3181
|
+
internalType: "uint256[]",
|
|
3182
|
+
name: "failedTokenIds",
|
|
3183
|
+
type: "uint256[]"
|
|
3184
|
+
}
|
|
3185
|
+
],
|
|
3186
|
+
internalType: "struct IBatchPurchase.TolerantResult",
|
|
3187
|
+
name: "result",
|
|
3188
|
+
type: "tuple"
|
|
3189
|
+
}
|
|
3190
|
+
],
|
|
3191
|
+
stateMutability: "payable",
|
|
3192
|
+
type: "function"
|
|
3193
|
+
},
|
|
3194
|
+
{
|
|
3195
|
+
inputs: [
|
|
3196
|
+
{
|
|
3197
|
+
internalType: "uint256[]",
|
|
3198
|
+
name: "tokenIds",
|
|
3199
|
+
type: "uint256[]"
|
|
3200
|
+
}
|
|
3201
|
+
],
|
|
3202
|
+
name: "buildPurchaseParams",
|
|
3203
|
+
outputs: [
|
|
3204
|
+
{
|
|
3205
|
+
components: [
|
|
3206
|
+
{
|
|
3207
|
+
internalType: "uint256",
|
|
3208
|
+
name: "tokenId",
|
|
3209
|
+
type: "uint256"
|
|
3210
|
+
},
|
|
3211
|
+
{
|
|
3212
|
+
internalType: "uint256",
|
|
3213
|
+
name: "expectedPrice",
|
|
3214
|
+
type: "uint256"
|
|
3215
|
+
},
|
|
3216
|
+
{
|
|
3217
|
+
internalType: "uint32",
|
|
3218
|
+
name: "expectedDuration",
|
|
3219
|
+
type: "uint32"
|
|
3220
|
+
},
|
|
3221
|
+
{
|
|
3222
|
+
internalType: "address",
|
|
3223
|
+
name: "expectedPaymentToken",
|
|
3224
|
+
type: "address"
|
|
3225
|
+
}
|
|
3226
|
+
],
|
|
3227
|
+
internalType: "struct IBatchPurchase.BuyParams[]",
|
|
3228
|
+
name: "purchases",
|
|
3229
|
+
type: "tuple[]"
|
|
3230
|
+
}
|
|
3231
|
+
],
|
|
3232
|
+
stateMutability: "view",
|
|
3233
|
+
type: "function"
|
|
3234
|
+
},
|
|
3235
|
+
{
|
|
3236
|
+
inputs: [
|
|
3237
|
+
{
|
|
3238
|
+
internalType: "uint256[]",
|
|
3239
|
+
name: "tokenIds",
|
|
3240
|
+
type: "uint256[]"
|
|
3241
|
+
}
|
|
3242
|
+
],
|
|
3243
|
+
name: "checkActiveStatus",
|
|
3244
|
+
outputs: [
|
|
3245
|
+
{
|
|
3246
|
+
internalType: "bool[]",
|
|
3247
|
+
name: "activeFlags",
|
|
3248
|
+
type: "bool[]"
|
|
3249
|
+
}
|
|
3250
|
+
],
|
|
3251
|
+
stateMutability: "view",
|
|
3252
|
+
type: "function"
|
|
3253
|
+
},
|
|
3254
|
+
{
|
|
3255
|
+
inputs: [
|
|
3256
|
+
],
|
|
3257
|
+
name: "ipNFT",
|
|
3258
|
+
outputs: [
|
|
3259
|
+
{
|
|
3260
|
+
internalType: "contract IIpNFT",
|
|
3261
|
+
name: "",
|
|
3262
|
+
type: "address"
|
|
3263
|
+
}
|
|
3264
|
+
],
|
|
3265
|
+
stateMutability: "view",
|
|
3266
|
+
type: "function"
|
|
3267
|
+
},
|
|
3268
|
+
{
|
|
3269
|
+
inputs: [
|
|
3270
|
+
],
|
|
3271
|
+
name: "marketplace",
|
|
3272
|
+
outputs: [
|
|
3273
|
+
{
|
|
3274
|
+
internalType: "contract IMarketplace",
|
|
3275
|
+
name: "",
|
|
3276
|
+
type: "address"
|
|
3277
|
+
}
|
|
3278
|
+
],
|
|
3279
|
+
stateMutability: "view",
|
|
3280
|
+
type: "function"
|
|
3281
|
+
},
|
|
3282
|
+
{
|
|
3283
|
+
inputs: [
|
|
3284
|
+
{
|
|
3285
|
+
internalType: "uint256[]",
|
|
3286
|
+
name: "tokenIds",
|
|
3287
|
+
type: "uint256[]"
|
|
3288
|
+
}
|
|
3289
|
+
],
|
|
3290
|
+
name: "previewBulkCost",
|
|
3291
|
+
outputs: [
|
|
3292
|
+
{
|
|
3293
|
+
components: [
|
|
3294
|
+
{
|
|
3295
|
+
internalType: "uint256",
|
|
3296
|
+
name: "totalNativeCost",
|
|
3297
|
+
type: "uint256"
|
|
3298
|
+
},
|
|
3299
|
+
{
|
|
3300
|
+
internalType: "uint256",
|
|
3301
|
+
name: "totalERC20Cost",
|
|
3302
|
+
type: "uint256"
|
|
3303
|
+
},
|
|
3304
|
+
{
|
|
3305
|
+
internalType: "uint256",
|
|
3306
|
+
name: "validCount",
|
|
3307
|
+
type: "uint256"
|
|
3308
|
+
},
|
|
3309
|
+
{
|
|
3310
|
+
internalType: "uint256[]",
|
|
3311
|
+
name: "invalidTokenIds",
|
|
3312
|
+
type: "uint256[]"
|
|
3313
|
+
}
|
|
3314
|
+
],
|
|
3315
|
+
internalType: "struct IBatchPurchase.BulkCostPreview",
|
|
3316
|
+
name: "preview",
|
|
3317
|
+
type: "tuple"
|
|
3318
|
+
}
|
|
3319
|
+
],
|
|
3320
|
+
stateMutability: "view",
|
|
3321
|
+
type: "function"
|
|
3322
|
+
}
|
|
3323
|
+
];
|
|
3324
|
+
|
|
2962
3325
|
var constants = {
|
|
2963
3326
|
SIWE_MESSAGE_STATEMENT: "Connect with Camp Network",
|
|
2964
3327
|
ORIGIN_DASHBOARD: "https://origin.campnetwork.xyz",
|
|
@@ -2986,10 +3349,12 @@ const ENVIRONMENTS = {
|
|
|
2986
3349
|
ORIGIN_DASHBOARD: "https://origin.campnetwork.xyz",
|
|
2987
3350
|
DATANFT_CONTRACT_ADDRESS: "0xB53F5723Dd4E46da32e1769Bd36A5aD880e707A5",
|
|
2988
3351
|
MARKETPLACE_CONTRACT_ADDRESS: "0x97b0A18B2888e904940fFd19E480a28aeec3F055",
|
|
3352
|
+
BATCH_PURCHASE_CONTRACT_ADDRESS: "0xaF0cF04DBfeeAcEdC77Dc68A91381AFB967B8518",
|
|
2989
3353
|
CHAIN: testnet,
|
|
2990
3354
|
IPNFT_ABI: ipnftMainnetAbi,
|
|
2991
3355
|
MARKETPLACE_ABI: marketplaceMainnetAbi,
|
|
2992
3356
|
TBA_ABI: tbaAbi,
|
|
3357
|
+
BATCH_PURCHASE_ABI: batchPurchaseAbi,
|
|
2993
3358
|
},
|
|
2994
3359
|
PRODUCTION: {
|
|
2995
3360
|
NAME: "PRODUCTION",
|
|
@@ -2998,10 +3363,12 @@ const ENVIRONMENTS = {
|
|
|
2998
3363
|
ORIGIN_DASHBOARD: "https://origin.campnetwork.xyz",
|
|
2999
3364
|
DATANFT_CONTRACT_ADDRESS: "0x39EeE1C3989f0dD543Dee60f8582F7F81F522C38",
|
|
3000
3365
|
MARKETPLACE_CONTRACT_ADDRESS: "0xc69BAa987757d054455fC0f2d9797684E9FB8b9C",
|
|
3366
|
+
BATCH_PURCHASE_CONTRACT_ADDRESS: "0x31885cD2A445322067dF890bACf6CeFE9b233BCC",
|
|
3001
3367
|
CHAIN: mainnet,
|
|
3002
3368
|
IPNFT_ABI: ipnftMainnetAbi,
|
|
3003
3369
|
MARKETPLACE_ABI: marketplaceMainnetAbi,
|
|
3004
3370
|
TBA_ABI: tbaAbi,
|
|
3371
|
+
BATCH_PURCHASE_ABI: batchPurchaseAbi,
|
|
3005
3372
|
},
|
|
3006
3373
|
};
|
|
3007
3374
|
|
|
@@ -3851,6 +4218,182 @@ function approveIfNeeded(_a) {
|
|
|
3851
4218
|
});
|
|
3852
4219
|
}
|
|
3853
4220
|
|
|
4221
|
+
/**
|
|
4222
|
+
* Executes an atomic bulk purchase of multiple IP-NFT licenses.
|
|
4223
|
+
* All purchases succeed or all fail together.
|
|
4224
|
+
*
|
|
4225
|
+
* @param buyer The address that will receive the licenses.
|
|
4226
|
+
* @param purchases Array of purchase parameters for each token.
|
|
4227
|
+
* @param value Total native token value to send (sum of all native token purchases).
|
|
4228
|
+
* @returns A promise that resolves with the transaction result.
|
|
4229
|
+
*
|
|
4230
|
+
* @example
|
|
4231
|
+
* ```typescript
|
|
4232
|
+
* const purchases = [
|
|
4233
|
+
* { tokenId: 1n, expectedPrice: 1000000000000000n, expectedDuration: 86400, expectedPaymentToken: zeroAddress },
|
|
4234
|
+
* { tokenId: 2n, expectedPrice: 2000000000000000n, expectedDuration: 86400, expectedPaymentToken: zeroAddress },
|
|
4235
|
+
* ];
|
|
4236
|
+
* const totalValue = 3000000000000000n;
|
|
4237
|
+
* await origin.bulkBuyAccess(buyerAddress, purchases, totalValue);
|
|
4238
|
+
* ```
|
|
4239
|
+
*/
|
|
4240
|
+
function bulkBuyAccess(buyer, purchases, value) {
|
|
4241
|
+
return this.callContractMethod(this.environment.BATCH_PURCHASE_CONTRACT_ADDRESS, this.environment.BATCH_PURCHASE_ABI, "bulkBuyAccess", [buyer, purchases], { waitForReceipt: true, value });
|
|
4242
|
+
}
|
|
4243
|
+
/**
|
|
4244
|
+
* Executes a fault-tolerant bulk purchase of multiple IP-NFT licenses.
|
|
4245
|
+
* Individual purchases can fail without reverting the entire transaction.
|
|
4246
|
+
* Unused funds are automatically refunded.
|
|
4247
|
+
*
|
|
4248
|
+
* @param buyer The address that will receive the licenses.
|
|
4249
|
+
* @param purchases Array of purchase parameters for each token.
|
|
4250
|
+
* @param value Total native token value to send (can be more than needed; excess is refunded).
|
|
4251
|
+
* @returns A promise that resolves with the tolerant result including success/failure counts.
|
|
4252
|
+
*
|
|
4253
|
+
* @example
|
|
4254
|
+
* ```typescript
|
|
4255
|
+
* const result = await origin.bulkBuyAccessTolerant(buyerAddress, purchases, totalValue);
|
|
4256
|
+
* console.log(`Purchased ${result.successCount} of ${purchases.length} IPs`);
|
|
4257
|
+
* console.log(`Failed tokens: ${result.failedTokenIds}`);
|
|
4258
|
+
* ```
|
|
4259
|
+
*/
|
|
4260
|
+
function bulkBuyAccessTolerant(buyer, purchases, value) {
|
|
4261
|
+
return this.callContractMethod(this.environment.BATCH_PURCHASE_CONTRACT_ADDRESS, this.environment.BATCH_PURCHASE_ABI, "bulkBuyAccessTolerant", [buyer, purchases], { waitForReceipt: true, value });
|
|
4262
|
+
}
|
|
4263
|
+
/**
|
|
4264
|
+
* Previews the total cost of purchasing multiple IP-NFT licenses.
|
|
4265
|
+
* This is a view function that doesn't require a transaction.
|
|
4266
|
+
*
|
|
4267
|
+
* @param tokenIds Array of token IDs to preview costs for.
|
|
4268
|
+
* @returns A promise that resolves with the cost preview including total costs and invalid tokens.
|
|
4269
|
+
*
|
|
4270
|
+
* @example
|
|
4271
|
+
* ```typescript
|
|
4272
|
+
* const preview = await origin.previewBulkCost([1n, 2n, 3n]);
|
|
4273
|
+
* console.log(`Total cost: ${preview.totalNativeCost} wei`);
|
|
4274
|
+
* console.log(`Valid tokens: ${preview.validCount}`);
|
|
4275
|
+
* ```
|
|
4276
|
+
*/
|
|
4277
|
+
function previewBulkCost(tokenIds) {
|
|
4278
|
+
return this.callContractMethod(this.environment.BATCH_PURCHASE_CONTRACT_ADDRESS, this.environment.BATCH_PURCHASE_ABI, "previewBulkCost", [tokenIds]);
|
|
4279
|
+
}
|
|
4280
|
+
/**
|
|
4281
|
+
* Builds purchase parameters for multiple tokens by fetching their current license terms.
|
|
4282
|
+
* This is a view function that doesn't require a transaction.
|
|
4283
|
+
*
|
|
4284
|
+
* @param tokenIds Array of token IDs to build parameters for.
|
|
4285
|
+
* @returns A promise that resolves with an array of BuyParams ready for bulk purchase.
|
|
4286
|
+
*
|
|
4287
|
+
* @example
|
|
4288
|
+
* ```typescript
|
|
4289
|
+
* const params = await origin.buildPurchaseParams([1n, 2n, 3n]);
|
|
4290
|
+
* await origin.bulkBuyAccess(buyer, params, totalValue);
|
|
4291
|
+
* ```
|
|
4292
|
+
*/
|
|
4293
|
+
function buildPurchaseParams(tokenIds) {
|
|
4294
|
+
return this.callContractMethod(this.environment.BATCH_PURCHASE_CONTRACT_ADDRESS, this.environment.BATCH_PURCHASE_ABI, "buildPurchaseParams", [tokenIds]);
|
|
4295
|
+
}
|
|
4296
|
+
/**
|
|
4297
|
+
* Checks the active status of multiple tokens.
|
|
4298
|
+
*
|
|
4299
|
+
* @param tokenIds Array of token IDs to check.
|
|
4300
|
+
* @returns A promise that resolves with an array of boolean flags indicating active status.
|
|
4301
|
+
*
|
|
4302
|
+
* @example
|
|
4303
|
+
* ```typescript
|
|
4304
|
+
* const activeFlags = await origin.checkActiveStatus([1n, 2n, 3n]);
|
|
4305
|
+
* const activeTokens = tokenIds.filter((_, i) => activeFlags[i]);
|
|
4306
|
+
* ```
|
|
4307
|
+
*/
|
|
4308
|
+
function checkActiveStatus(tokenIds) {
|
|
4309
|
+
return this.callContractMethod(this.environment.BATCH_PURCHASE_CONTRACT_ADDRESS, this.environment.BATCH_PURCHASE_ABI, "checkActiveStatus", [tokenIds]);
|
|
4310
|
+
}
|
|
4311
|
+
/**
|
|
4312
|
+
* Smart bulk purchase that automatically fetches terms and handles the entire purchase flow.
|
|
4313
|
+
* This is the recommended method for most use cases.
|
|
4314
|
+
*
|
|
4315
|
+
* @param tokenIds Array of token IDs to purchase.
|
|
4316
|
+
* @param options Optional configuration for the purchase.
|
|
4317
|
+
* @returns A promise that resolves with the transaction result.
|
|
4318
|
+
*
|
|
4319
|
+
* @example
|
|
4320
|
+
* ```typescript
|
|
4321
|
+
* // Atomic purchase - all succeed or all fail
|
|
4322
|
+
* const result = await origin.bulkBuyAccessSmart([1n, 2n, 3n]);
|
|
4323
|
+
*
|
|
4324
|
+
* // Tolerant purchase - continue even if some fail
|
|
4325
|
+
* const result = await origin.bulkBuyAccessSmart([1n, 2n, 3n], { tolerant: true });
|
|
4326
|
+
* ```
|
|
4327
|
+
*/
|
|
4328
|
+
function bulkBuyAccessSmart(tokenIds, options) {
|
|
4329
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4330
|
+
if (!tokenIds || tokenIds.length === 0) {
|
|
4331
|
+
throw new Error("No token IDs provided for bulk purchase");
|
|
4332
|
+
}
|
|
4333
|
+
// Get the buyer's wallet address
|
|
4334
|
+
const viemClient = this.viemClient;
|
|
4335
|
+
if (!viemClient) {
|
|
4336
|
+
throw new Error("WalletClient not connected. Please connect a wallet.");
|
|
4337
|
+
}
|
|
4338
|
+
let buyer;
|
|
4339
|
+
if (viemClient.account) {
|
|
4340
|
+
buyer = viemClient.account.address;
|
|
4341
|
+
}
|
|
4342
|
+
else {
|
|
4343
|
+
const accounts = yield viemClient.request({
|
|
4344
|
+
method: "eth_requestAccounts",
|
|
4345
|
+
params: [],
|
|
4346
|
+
});
|
|
4347
|
+
if (!accounts || accounts.length === 0) {
|
|
4348
|
+
throw new Error("No accounts found in connected wallet.");
|
|
4349
|
+
}
|
|
4350
|
+
buyer = accounts[0];
|
|
4351
|
+
}
|
|
4352
|
+
// Build purchase params from on-chain data
|
|
4353
|
+
const purchases = yield this.buildPurchaseParams(tokenIds);
|
|
4354
|
+
// Calculate total native token cost
|
|
4355
|
+
let totalNativeValue = BigInt(0);
|
|
4356
|
+
const erc20Purchases = [];
|
|
4357
|
+
for (const purchase of purchases) {
|
|
4358
|
+
if (purchase.expectedPaymentToken === zeroAddress) {
|
|
4359
|
+
totalNativeValue += purchase.expectedPrice;
|
|
4360
|
+
}
|
|
4361
|
+
else {
|
|
4362
|
+
// Group ERC20 purchases by token
|
|
4363
|
+
const existing = erc20Purchases.find((p) => p.token === purchase.expectedPaymentToken);
|
|
4364
|
+
if (existing) {
|
|
4365
|
+
existing.amount += purchase.expectedPrice;
|
|
4366
|
+
}
|
|
4367
|
+
else {
|
|
4368
|
+
erc20Purchases.push({
|
|
4369
|
+
token: purchase.expectedPaymentToken,
|
|
4370
|
+
amount: purchase.expectedPrice,
|
|
4371
|
+
});
|
|
4372
|
+
}
|
|
4373
|
+
}
|
|
4374
|
+
}
|
|
4375
|
+
// Approve ERC20 tokens if needed
|
|
4376
|
+
const publicClient = getPublicClient();
|
|
4377
|
+
for (const erc20 of erc20Purchases) {
|
|
4378
|
+
yield approveIfNeeded({
|
|
4379
|
+
walletClient: viemClient,
|
|
4380
|
+
publicClient,
|
|
4381
|
+
tokenAddress: erc20.token,
|
|
4382
|
+
owner: buyer,
|
|
4383
|
+
spender: this.environment.BATCH_PURCHASE_CONTRACT_ADDRESS,
|
|
4384
|
+
amount: erc20.amount,
|
|
4385
|
+
});
|
|
4386
|
+
}
|
|
4387
|
+
// Execute the purchase
|
|
4388
|
+
if (options === null || options === void 0 ? void 0 : options.tolerant) {
|
|
4389
|
+
return this.bulkBuyAccessTolerant(buyer, purchases, totalNativeValue);
|
|
4390
|
+
}
|
|
4391
|
+
else {
|
|
4392
|
+
return this.bulkBuyAccess(buyer, purchases, totalNativeValue);
|
|
4393
|
+
}
|
|
4394
|
+
});
|
|
4395
|
+
}
|
|
4396
|
+
|
|
3854
4397
|
var _Origin_instances, _Origin_generateURL, _Origin_setOriginStatus, _Origin_uploadToIPFS, _Origin_uploadFile, _Origin_waitForTxReceipt, _Origin_ensureChainId, _Origin_getCurrentAccount, _Origin_resolveWalletAddress;
|
|
3855
4398
|
/**
|
|
3856
4399
|
* The Origin class
|
|
@@ -3893,6 +4436,13 @@ class Origin {
|
|
|
3893
4436
|
this.subscriptionExpiry = subscriptionExpiry.bind(this);
|
|
3894
4437
|
this.settlePaymentIntent = settlePaymentIntent.bind(this);
|
|
3895
4438
|
this.getDataWithIntent = getDataWithIntent.bind(this);
|
|
4439
|
+
// Bulk purchase methods
|
|
4440
|
+
this.bulkBuyAccess = bulkBuyAccess.bind(this);
|
|
4441
|
+
this.bulkBuyAccessTolerant = bulkBuyAccessTolerant.bind(this);
|
|
4442
|
+
this.bulkBuyAccessSmart = bulkBuyAccessSmart.bind(this);
|
|
4443
|
+
this.previewBulkCost = previewBulkCost.bind(this);
|
|
4444
|
+
this.buildPurchaseParams = buildPurchaseParams.bind(this);
|
|
4445
|
+
this.checkActiveStatus = checkActiveStatus.bind(this);
|
|
3896
4446
|
}
|
|
3897
4447
|
getJwt() {
|
|
3898
4448
|
return this.jwt;
|