@campnetwork/origin 1.0.0-alpha.13 → 1.0.0-alpha.2
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 +37 -68
- package/dist/core.d.ts +9 -49
- package/dist/core.esm.d.ts +9 -49
- package/dist/core.esm.js +77 -108
- package/dist/react/index.esm.d.ts +9 -49
- package/dist/react/index.esm.js +155 -436
- package/package.json +1 -1
package/dist/react/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import React, { createContext, useState, useContext, useEffect, useLayoutEffect, useRef, useSyncExternalStore } from 'react';
|
|
3
|
-
import { custom, createWalletClient, createPublicClient, http, erc20Abi, getAbiItem,
|
|
3
|
+
import { custom, createWalletClient, createPublicClient, http, erc20Abi, getAbiItem, encodeFunctionData, zeroAddress, checksumAddress } from 'viem';
|
|
4
4
|
import { toAccount } from 'viem/accounts';
|
|
5
5
|
import { createSiweMessage } from 'viem/siwe';
|
|
6
6
|
import axios from 'axios';
|
|
@@ -128,20 +128,20 @@ const mainnet = {
|
|
|
128
128
|
// @ts-ignore
|
|
129
129
|
let client = null;
|
|
130
130
|
let publicClient = null;
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
131
|
+
const getClient = (provider, name = "window.ethereum",
|
|
132
|
+
// chain: "mainnet" | "testnet" = "testnet",
|
|
133
|
+
chain, address) => {
|
|
134
|
+
var _a;
|
|
134
135
|
if (!provider && !client) {
|
|
135
136
|
console.warn("Provider is required to create a client.");
|
|
136
137
|
return null;
|
|
137
138
|
}
|
|
138
|
-
const selectedChain = chain || testnet;
|
|
139
139
|
if (!client ||
|
|
140
140
|
(client.transport.name !== name && provider) ||
|
|
141
|
-
(address !== ((_a = client.account) === null || _a === void 0 ? void 0 : _a.address) && provider)
|
|
142
|
-
(currentChain === null || currentChain === void 0 ? void 0 : currentChain.id) !== selectedChain.id) {
|
|
141
|
+
(address !== ((_a = client.account) === null || _a === void 0 ? void 0 : _a.address) && provider)) {
|
|
143
142
|
const obj = {
|
|
144
|
-
chain:
|
|
143
|
+
// chain: chain === "mainnet" ? mainnet : testnet,
|
|
144
|
+
chain: chain || testnet,
|
|
145
145
|
transport: custom(provider, {
|
|
146
146
|
name: name,
|
|
147
147
|
}),
|
|
@@ -150,28 +150,18 @@ const getClient = (provider, name = "window.ethereum", chain, address) => {
|
|
|
150
150
|
obj.account = toAccount(address);
|
|
151
151
|
}
|
|
152
152
|
client = createWalletClient(obj);
|
|
153
|
-
currentChain = selectedChain;
|
|
154
|
-
if (publicClient && ((_b = publicClient.chain) === null || _b === void 0 ? void 0 : _b.id) !== selectedChain.id) {
|
|
155
|
-
publicClient = null;
|
|
156
|
-
}
|
|
157
153
|
}
|
|
158
154
|
return client;
|
|
159
155
|
};
|
|
160
|
-
const getPublicClient = (
|
|
161
|
-
|
|
162
|
-
const selectedChain = currentChain || testnet;
|
|
163
|
-
if (!publicClient || ((_a = publicClient.chain) === null || _a === void 0 ? void 0 : _a.id) !== selectedChain.id) {
|
|
156
|
+
const getPublicClient = () => {
|
|
157
|
+
if (!publicClient) {
|
|
164
158
|
publicClient = createPublicClient({
|
|
165
|
-
chain:
|
|
159
|
+
chain: testnet,
|
|
166
160
|
transport: http(),
|
|
167
161
|
});
|
|
168
162
|
}
|
|
169
163
|
return publicClient;
|
|
170
164
|
};
|
|
171
|
-
const setChain = (chain) => {
|
|
172
|
-
currentChain = chain;
|
|
173
|
-
publicClient = null; // reset public client to be recreated with new chain
|
|
174
|
-
};
|
|
175
165
|
|
|
176
166
|
var ipnftMainnetAbi = [
|
|
177
167
|
{
|
|
@@ -2404,116 +2394,6 @@ var marketplaceMainnetAbi = [
|
|
|
2404
2394
|
}
|
|
2405
2395
|
];
|
|
2406
2396
|
|
|
2407
|
-
var royaltyVaultAbi = [
|
|
2408
|
-
{
|
|
2409
|
-
type: "constructor",
|
|
2410
|
-
inputs: [
|
|
2411
|
-
{
|
|
2412
|
-
name: "_owner",
|
|
2413
|
-
type: "address",
|
|
2414
|
-
internalType: "address"
|
|
2415
|
-
}
|
|
2416
|
-
],
|
|
2417
|
-
stateMutability: "nonpayable"
|
|
2418
|
-
},
|
|
2419
|
-
{
|
|
2420
|
-
type: "receive",
|
|
2421
|
-
stateMutability: "payable"
|
|
2422
|
-
},
|
|
2423
|
-
{
|
|
2424
|
-
type: "function",
|
|
2425
|
-
name: "claimRoyalty",
|
|
2426
|
-
inputs: [
|
|
2427
|
-
{
|
|
2428
|
-
name: "token",
|
|
2429
|
-
type: "address",
|
|
2430
|
-
internalType: "address"
|
|
2431
|
-
}
|
|
2432
|
-
],
|
|
2433
|
-
outputs: [
|
|
2434
|
-
],
|
|
2435
|
-
stateMutability: "nonpayable"
|
|
2436
|
-
},
|
|
2437
|
-
{
|
|
2438
|
-
type: "function",
|
|
2439
|
-
name: "owner",
|
|
2440
|
-
inputs: [
|
|
2441
|
-
],
|
|
2442
|
-
outputs: [
|
|
2443
|
-
{
|
|
2444
|
-
name: "",
|
|
2445
|
-
type: "address",
|
|
2446
|
-
internalType: "address"
|
|
2447
|
-
}
|
|
2448
|
-
],
|
|
2449
|
-
stateMutability: "view"
|
|
2450
|
-
},
|
|
2451
|
-
{
|
|
2452
|
-
type: "function",
|
|
2453
|
-
name: "renounceOwnership",
|
|
2454
|
-
inputs: [
|
|
2455
|
-
],
|
|
2456
|
-
outputs: [
|
|
2457
|
-
],
|
|
2458
|
-
stateMutability: "nonpayable"
|
|
2459
|
-
},
|
|
2460
|
-
{
|
|
2461
|
-
type: "function",
|
|
2462
|
-
name: "transferOwnership",
|
|
2463
|
-
inputs: [
|
|
2464
|
-
{
|
|
2465
|
-
name: "newOwner",
|
|
2466
|
-
type: "address",
|
|
2467
|
-
internalType: "address"
|
|
2468
|
-
}
|
|
2469
|
-
],
|
|
2470
|
-
outputs: [
|
|
2471
|
-
],
|
|
2472
|
-
stateMutability: "nonpayable"
|
|
2473
|
-
},
|
|
2474
|
-
{
|
|
2475
|
-
type: "event",
|
|
2476
|
-
name: "OwnershipTransferred",
|
|
2477
|
-
inputs: [
|
|
2478
|
-
{
|
|
2479
|
-
name: "previousOwner",
|
|
2480
|
-
type: "address",
|
|
2481
|
-
indexed: true,
|
|
2482
|
-
internalType: "address"
|
|
2483
|
-
},
|
|
2484
|
-
{
|
|
2485
|
-
name: "newOwner",
|
|
2486
|
-
type: "address",
|
|
2487
|
-
indexed: true,
|
|
2488
|
-
internalType: "address"
|
|
2489
|
-
}
|
|
2490
|
-
],
|
|
2491
|
-
anonymous: false
|
|
2492
|
-
},
|
|
2493
|
-
{
|
|
2494
|
-
type: "error",
|
|
2495
|
-
name: "OwnableInvalidOwner",
|
|
2496
|
-
inputs: [
|
|
2497
|
-
{
|
|
2498
|
-
name: "owner",
|
|
2499
|
-
type: "address",
|
|
2500
|
-
internalType: "address"
|
|
2501
|
-
}
|
|
2502
|
-
]
|
|
2503
|
-
},
|
|
2504
|
-
{
|
|
2505
|
-
type: "error",
|
|
2506
|
-
name: "OwnableUnauthorizedAccount",
|
|
2507
|
-
inputs: [
|
|
2508
|
-
{
|
|
2509
|
-
name: "account",
|
|
2510
|
-
type: "address",
|
|
2511
|
-
internalType: "address"
|
|
2512
|
-
}
|
|
2513
|
-
]
|
|
2514
|
-
}
|
|
2515
|
-
];
|
|
2516
|
-
|
|
2517
2397
|
var constants = {
|
|
2518
2398
|
SIWE_MESSAGE_STATEMENT: "Connect with Camp Network",
|
|
2519
2399
|
AUTH_HUB_BASE_API: "https://wv2h4to5qa.execute-api.us-east-2.amazonaws.com/dev",
|
|
@@ -2555,7 +2435,6 @@ const ENVIRONMENTS = {
|
|
|
2555
2435
|
CHAIN: testnet,
|
|
2556
2436
|
IPNFT_ABI: ipnftMainnetAbi,
|
|
2557
2437
|
MARKETPLACE_ABI: marketplaceMainnetAbi,
|
|
2558
|
-
ROYALTY_VAULT_ABI: royaltyVaultAbi,
|
|
2559
2438
|
},
|
|
2560
2439
|
PRODUCTION: {
|
|
2561
2440
|
NAME: "PRODUCTION",
|
|
@@ -2567,7 +2446,6 @@ const ENVIRONMENTS = {
|
|
|
2567
2446
|
CHAIN: mainnet,
|
|
2568
2447
|
IPNFT_ABI: ipnftMainnetAbi,
|
|
2569
2448
|
MARKETPLACE_ABI: marketplaceMainnetAbi,
|
|
2570
|
-
ROYALTY_VAULT_ABI: royaltyVaultAbi,
|
|
2571
2449
|
},
|
|
2572
2450
|
};
|
|
2573
2451
|
|
|
@@ -2733,21 +2611,6 @@ function finalizeDelete(tokenId) {
|
|
|
2733
2611
|
return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS, this.environment.IPNFT_ABI, "finalizeDelete", [tokenId]);
|
|
2734
2612
|
}
|
|
2735
2613
|
|
|
2736
|
-
/**
|
|
2737
|
-
* Calls the getOrCreateRoyaltyVault method on the IPNFT contract.
|
|
2738
|
-
* @param tokenOwner The address of the token owner for whom to get or create the royalty vault.
|
|
2739
|
-
* @param simulateOnly If true, simulates the transaction without executing it.
|
|
2740
|
-
* @returns The address of the royalty vault associated with the specified token owner.
|
|
2741
|
-
*/
|
|
2742
|
-
function getOrCreateRoyaltyVault(tokenOwner_1) {
|
|
2743
|
-
return __awaiter(this, arguments, void 0, function* (tokenOwner, simulateOnly = false) {
|
|
2744
|
-
const royaltyVaultTx = yield this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS, this.environment.IPNFT_ABI, "getOrCreateRoyaltyVault", [tokenOwner], { waitForReceipt: true, simulate: simulateOnly });
|
|
2745
|
-
return simulateOnly
|
|
2746
|
-
? royaltyVaultTx
|
|
2747
|
-
: royaltyVaultTx.simulatedResult;
|
|
2748
|
-
});
|
|
2749
|
-
}
|
|
2750
|
-
|
|
2751
2614
|
/**
|
|
2752
2615
|
* Returns the license terms associated with a specific token ID.
|
|
2753
2616
|
* @param tokenId The token ID to query.
|
|
@@ -2884,7 +2747,7 @@ function approveIfNeeded(_a) {
|
|
|
2884
2747
|
});
|
|
2885
2748
|
}
|
|
2886
2749
|
|
|
2887
|
-
var _Origin_instances, _Origin_generateURL, _Origin_setOriginStatus, _Origin_waitForTxReceipt, _Origin_ensureChainId
|
|
2750
|
+
var _Origin_instances, _Origin_generateURL, _Origin_setOriginStatus, _Origin_waitForTxReceipt, _Origin_ensureChainId;
|
|
2888
2751
|
/**
|
|
2889
2752
|
* The Origin class
|
|
2890
2753
|
* Handles the upload of files to Origin, as well as querying the user's stats
|
|
@@ -2892,41 +2755,61 @@ var _Origin_instances, _Origin_generateURL, _Origin_setOriginStatus, _Origin_wai
|
|
|
2892
2755
|
class Origin {
|
|
2893
2756
|
constructor(jwt, environment, viemClient) {
|
|
2894
2757
|
_Origin_instances.add(this);
|
|
2895
|
-
this
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2758
|
+
_Origin_generateURL.set(this, (file) => __awaiter(this, void 0, void 0, function* () {
|
|
2759
|
+
try {
|
|
2760
|
+
const uploadRes = yield fetch(`${this.environment.AUTH_HUB_BASE_API}/${this.environment.AUTH_ENDPOINT}/origin/upload-url`, {
|
|
2761
|
+
method: "POST",
|
|
2762
|
+
body: JSON.stringify({
|
|
2763
|
+
name: file.name,
|
|
2764
|
+
type: file.type,
|
|
2765
|
+
}),
|
|
2766
|
+
headers: {
|
|
2767
|
+
Authorization: `Bearer ${this.jwt}`,
|
|
2768
|
+
"Content-Type": "application/json",
|
|
2769
|
+
},
|
|
2770
|
+
});
|
|
2771
|
+
if (!uploadRes.ok) {
|
|
2772
|
+
throw new Error(`HTTP ${uploadRes.status}: ${uploadRes.statusText}`);
|
|
2773
|
+
}
|
|
2774
|
+
const data = yield uploadRes.json();
|
|
2775
|
+
if (data.isError) {
|
|
2776
|
+
throw new Error(data.message || "Failed to generate upload URL");
|
|
2777
|
+
}
|
|
2778
|
+
return data.data;
|
|
2779
|
+
}
|
|
2780
|
+
catch (error) {
|
|
2781
|
+
console.error("Failed to generate upload URL:", error);
|
|
2782
|
+
throw error;
|
|
2783
|
+
}
|
|
2784
|
+
}));
|
|
2785
|
+
_Origin_setOriginStatus.set(this, (key, status) => __awaiter(this, void 0, void 0, function* () {
|
|
2786
|
+
try {
|
|
2787
|
+
const res = yield fetch(`${this.environment.AUTH_HUB_BASE_API}/${this.environment.AUTH_ENDPOINT}/origin/update-status`, {
|
|
2788
|
+
method: "PATCH",
|
|
2789
|
+
body: JSON.stringify({
|
|
2790
|
+
status,
|
|
2791
|
+
fileKey: key,
|
|
2792
|
+
}),
|
|
2793
|
+
headers: {
|
|
2794
|
+
Authorization: `Bearer ${this.jwt}`,
|
|
2795
|
+
"Content-Type": "application/json",
|
|
2796
|
+
},
|
|
2797
|
+
});
|
|
2798
|
+
if (!res.ok) {
|
|
2799
|
+
const errorText = yield res.text().catch(() => "Unknown error");
|
|
2800
|
+
throw new Error(`HTTP ${res.status}: ${errorText}`);
|
|
2801
|
+
}
|
|
2802
|
+
return true;
|
|
2803
|
+
}
|
|
2804
|
+
catch (error) {
|
|
2805
|
+
console.error("Failed to update origin status:", error);
|
|
2806
|
+
throw error;
|
|
2807
|
+
}
|
|
2808
|
+
}));
|
|
2809
|
+
this.uploadFile = (file, options) => __awaiter(this, void 0, void 0, function* () {
|
|
2927
2810
|
let uploadInfo;
|
|
2928
2811
|
try {
|
|
2929
|
-
uploadInfo = yield __classPrivateFieldGet(this,
|
|
2812
|
+
uploadInfo = yield __classPrivateFieldGet(this, _Origin_generateURL, "f").call(this, file);
|
|
2930
2813
|
}
|
|
2931
2814
|
catch (error) {
|
|
2932
2815
|
console.error("Failed to generate upload URL:", error);
|
|
@@ -2940,7 +2823,7 @@ class Origin {
|
|
|
2940
2823
|
}
|
|
2941
2824
|
catch (error) {
|
|
2942
2825
|
try {
|
|
2943
|
-
yield __classPrivateFieldGet(this,
|
|
2826
|
+
yield __classPrivateFieldGet(this, _Origin_setOriginStatus, "f").call(this, uploadInfo.key, "failed");
|
|
2944
2827
|
}
|
|
2945
2828
|
catch (statusError) {
|
|
2946
2829
|
console.error("Failed to update status to failed:", statusError);
|
|
@@ -2949,16 +2832,14 @@ class Origin {
|
|
|
2949
2832
|
throw new Error(`Failed to upload file: ${errorMessage}`);
|
|
2950
2833
|
}
|
|
2951
2834
|
try {
|
|
2952
|
-
yield __classPrivateFieldGet(this,
|
|
2835
|
+
yield __classPrivateFieldGet(this, _Origin_setOriginStatus, "f").call(this, uploadInfo.key, "success");
|
|
2953
2836
|
}
|
|
2954
2837
|
catch (statusError) {
|
|
2955
2838
|
console.error("Failed to update status to success:", statusError);
|
|
2956
2839
|
}
|
|
2957
2840
|
return uploadInfo;
|
|
2958
2841
|
});
|
|
2959
|
-
|
|
2960
|
-
mintFile(file, metadata, license, parents, options) {
|
|
2961
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2842
|
+
this.mintFile = (file, metadata, license, parents, options) => __awaiter(this, void 0, void 0, function* () {
|
|
2962
2843
|
if (!this.viemClient) {
|
|
2963
2844
|
throw new Error("WalletClient not connected.");
|
|
2964
2845
|
}
|
|
@@ -2976,21 +2857,18 @@ class Origin {
|
|
|
2976
2857
|
!uri) {
|
|
2977
2858
|
throw new Error("Failed to register IpNFT: Missing required fields in registration response.");
|
|
2978
2859
|
}
|
|
2979
|
-
const
|
|
2860
|
+
const [account] = yield this.viemClient.request({
|
|
2980
2861
|
method: "eth_requestAccounts",
|
|
2981
2862
|
params: [],
|
|
2982
|
-
})
|
|
2983
|
-
const account = accounts[0];
|
|
2863
|
+
});
|
|
2984
2864
|
const mintResult = yield this.mintWithSignature(account, tokenId, parents || [], creatorContentHash, uri, license, deadline, signature);
|
|
2985
|
-
if (
|
|
2865
|
+
if (mintResult.status !== "0x1") {
|
|
2986
2866
|
console.error("Minting failed:", mintResult);
|
|
2987
|
-
throw new Error(`Minting failed with status: ${mintResult.
|
|
2867
|
+
throw new Error(`Minting failed with status: ${mintResult.status}`);
|
|
2988
2868
|
}
|
|
2989
2869
|
return tokenId.toString();
|
|
2990
2870
|
});
|
|
2991
|
-
|
|
2992
|
-
mintSocial(source, metadata, license) {
|
|
2993
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2871
|
+
this.mintSocial = (source, metadata, license) => __awaiter(this, void 0, void 0, function* () {
|
|
2994
2872
|
if (!this.viemClient) {
|
|
2995
2873
|
throw new Error("WalletClient not connected.");
|
|
2996
2874
|
}
|
|
@@ -3004,20 +2882,17 @@ class Origin {
|
|
|
3004
2882
|
!uri) {
|
|
3005
2883
|
throw new Error("Failed to register Social IpNFT: Missing required fields in registration response.");
|
|
3006
2884
|
}
|
|
3007
|
-
const
|
|
2885
|
+
const [account] = yield this.viemClient.request({
|
|
3008
2886
|
method: "eth_requestAccounts",
|
|
3009
2887
|
params: [],
|
|
3010
|
-
})
|
|
3011
|
-
const account = accounts[0];
|
|
2888
|
+
});
|
|
3012
2889
|
const mintResult = yield this.mintWithSignature(account, tokenId, [], creatorContentHash, uri, license, deadline, signature);
|
|
3013
|
-
if (
|
|
2890
|
+
if (mintResult.status !== "0x1") {
|
|
3014
2891
|
throw new Error(`Minting Social IpNFT failed with status: ${mintResult.status}`);
|
|
3015
2892
|
}
|
|
3016
2893
|
return tokenId.toString();
|
|
3017
2894
|
});
|
|
3018
|
-
|
|
3019
|
-
getOriginUploads() {
|
|
3020
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2895
|
+
this.getOriginUploads = () => __awaiter(this, void 0, void 0, function* () {
|
|
3021
2896
|
const res = yield fetch(`${this.environment.AUTH_HUB_BASE_API}/${this.environment.AUTH_ENDPOINT}/origin/files`, {
|
|
3022
2897
|
method: "GET",
|
|
3023
2898
|
headers: {
|
|
@@ -3031,6 +2906,34 @@ class Origin {
|
|
|
3031
2906
|
const data = yield res.json();
|
|
3032
2907
|
return data.data;
|
|
3033
2908
|
});
|
|
2909
|
+
this.jwt = jwt;
|
|
2910
|
+
this.viemClient = viemClient;
|
|
2911
|
+
this.environment = environment;
|
|
2912
|
+
// DataNFT methods
|
|
2913
|
+
this.mintWithSignature = mintWithSignature.bind(this);
|
|
2914
|
+
this.registerIpNFT = registerIpNFT.bind(this);
|
|
2915
|
+
this.updateTerms = updateTerms.bind(this);
|
|
2916
|
+
this.finalizeDelete = finalizeDelete.bind(this);
|
|
2917
|
+
this.getTerms = getTerms.bind(this);
|
|
2918
|
+
this.ownerOf = ownerOf.bind(this);
|
|
2919
|
+
this.balanceOf = balanceOf.bind(this);
|
|
2920
|
+
this.tokenURI = tokenURI.bind(this);
|
|
2921
|
+
this.dataStatus = dataStatus.bind(this);
|
|
2922
|
+
this.isApprovedForAll = isApprovedForAll.bind(this);
|
|
2923
|
+
this.transferFrom = transferFrom.bind(this);
|
|
2924
|
+
this.safeTransferFrom = safeTransferFrom.bind(this);
|
|
2925
|
+
this.approve = approve.bind(this);
|
|
2926
|
+
this.setApprovalForAll = setApprovalForAll.bind(this);
|
|
2927
|
+
// Marketplace methods
|
|
2928
|
+
this.buyAccess = buyAccess.bind(this);
|
|
2929
|
+
this.hasAccess = hasAccess.bind(this);
|
|
2930
|
+
this.subscriptionExpiry = subscriptionExpiry.bind(this);
|
|
2931
|
+
}
|
|
2932
|
+
getJwt() {
|
|
2933
|
+
return this.jwt;
|
|
2934
|
+
}
|
|
2935
|
+
setViemClient(client) {
|
|
2936
|
+
this.viemClient = client;
|
|
3034
2937
|
}
|
|
3035
2938
|
/**
|
|
3036
2939
|
* Get the user's Origin stats (multiplier, consent, usage, etc.).
|
|
@@ -3099,6 +3002,9 @@ class Origin {
|
|
|
3099
3002
|
"stateMutability" in abiItem &&
|
|
3100
3003
|
(abiItem.stateMutability === "view" ||
|
|
3101
3004
|
abiItem.stateMutability === "pure");
|
|
3005
|
+
if (!isView && !this.viemClient) {
|
|
3006
|
+
throw new Error("WalletClient not connected.");
|
|
3007
|
+
}
|
|
3102
3008
|
if (isView) {
|
|
3103
3009
|
const publicClient = getPublicClient();
|
|
3104
3010
|
const result = (yield publicClient.readContract({
|
|
@@ -3109,41 +3015,38 @@ class Origin {
|
|
|
3109
3015
|
})) || null;
|
|
3110
3016
|
return result;
|
|
3111
3017
|
}
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3018
|
+
else {
|
|
3019
|
+
const [account] = yield this.viemClient.request({
|
|
3020
|
+
method: "eth_requestAccounts",
|
|
3021
|
+
params: [],
|
|
3022
|
+
});
|
|
3023
|
+
const data = encodeFunctionData({
|
|
3024
|
+
abi,
|
|
3025
|
+
functionName: methodName,
|
|
3026
|
+
args: params,
|
|
3027
|
+
});
|
|
3028
|
+
yield __classPrivateFieldGet(this, _Origin_instances, "m", _Origin_ensureChainId).call(this, this.environment.CHAIN);
|
|
3029
|
+
try {
|
|
3030
|
+
const txHash = yield this.viemClient.sendTransaction({
|
|
3031
|
+
to: contractAddress,
|
|
3032
|
+
data,
|
|
3033
|
+
account,
|
|
3034
|
+
value: options.value,
|
|
3035
|
+
gas: options.gas,
|
|
3036
|
+
});
|
|
3037
|
+
if (typeof txHash !== "string") {
|
|
3038
|
+
throw new Error("Transaction failed to send.");
|
|
3039
|
+
}
|
|
3040
|
+
if (!options.waitForReceipt) {
|
|
3041
|
+
return txHash;
|
|
3042
|
+
}
|
|
3043
|
+
const receipt = yield __classPrivateFieldGet(this, _Origin_instances, "m", _Origin_waitForTxReceipt).call(this, txHash);
|
|
3044
|
+
return receipt;
|
|
3137
3045
|
}
|
|
3138
|
-
|
|
3139
|
-
|
|
3046
|
+
catch (error) {
|
|
3047
|
+
console.error("Transaction failed:", error);
|
|
3048
|
+
throw new Error("Transaction failed: " + error);
|
|
3140
3049
|
}
|
|
3141
|
-
const receipt = yield __classPrivateFieldGet(this, _Origin_instances, "m", _Origin_waitForTxReceipt).call(this, txHash);
|
|
3142
|
-
return { txHash, receipt, simulatedResult };
|
|
3143
|
-
}
|
|
3144
|
-
catch (error) {
|
|
3145
|
-
console.error("Transaction failed:", error);
|
|
3146
|
-
throw new Error("Transaction failed: " + error);
|
|
3147
3050
|
}
|
|
3148
3051
|
});
|
|
3149
3052
|
}
|
|
@@ -3166,11 +3069,10 @@ class Origin {
|
|
|
3166
3069
|
duration === undefined) {
|
|
3167
3070
|
throw new Error("Terms missing price, paymentToken, or duration");
|
|
3168
3071
|
}
|
|
3169
|
-
const
|
|
3072
|
+
const [account] = yield this.viemClient.request({
|
|
3170
3073
|
method: "eth_requestAccounts",
|
|
3171
3074
|
params: [],
|
|
3172
|
-
})
|
|
3173
|
-
const account = accounts[0];
|
|
3075
|
+
});
|
|
3174
3076
|
const totalCost = price;
|
|
3175
3077
|
const isNative = paymentToken === zeroAddress;
|
|
3176
3078
|
if (isNative) {
|
|
@@ -3203,173 +3105,20 @@ class Origin {
|
|
|
3203
3105
|
return response.json();
|
|
3204
3106
|
});
|
|
3205
3107
|
}
|
|
3206
|
-
/**
|
|
3207
|
-
* Get royalty information for a wallet address, including the royalty vault address and its balance.
|
|
3208
|
-
* @param {Address} [token] - Optional token address to check royalties for. If not provided, checks for native token.
|
|
3209
|
-
* @param {Address} [owner] - Optional wallet address to check royalties for. If not provided, uses the connected wallet.
|
|
3210
|
-
* @returns {Promise<RoyaltyInfo>} A promise that resolves with the royalty vault address and balance information.
|
|
3211
|
-
* @throws {Error} Throws an error if no wallet is connected and no owner address is provided.
|
|
3212
|
-
* @example
|
|
3213
|
-
* ```typescript
|
|
3214
|
-
* // Get royalties for connected wallet
|
|
3215
|
-
* const royalties = await origin.getRoyalties();
|
|
3216
|
-
*
|
|
3217
|
-
* // Get royalties for specific address
|
|
3218
|
-
* const royalties = await origin.getRoyalties("0x1234...");
|
|
3219
|
-
* ```
|
|
3220
|
-
*/
|
|
3221
|
-
getRoyalties(token, owner) {
|
|
3222
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
3223
|
-
const walletAddress = yield __classPrivateFieldGet(this, _Origin_instances, "m", _Origin_resolveWalletAddress).call(this, owner);
|
|
3224
|
-
try {
|
|
3225
|
-
const royaltyVaultAddress = yield this.getOrCreateRoyaltyVault(walletAddress, true);
|
|
3226
|
-
const publicClient = getPublicClient();
|
|
3227
|
-
let balance;
|
|
3228
|
-
let balanceFormatted;
|
|
3229
|
-
if (!token || token === zeroAddress) {
|
|
3230
|
-
balance = yield publicClient.getBalance({
|
|
3231
|
-
address: royaltyVaultAddress,
|
|
3232
|
-
});
|
|
3233
|
-
balanceFormatted = formatEther(balance);
|
|
3234
|
-
}
|
|
3235
|
-
else {
|
|
3236
|
-
// erc20 (wrapped camp)
|
|
3237
|
-
const erc20Abi = [
|
|
3238
|
-
{
|
|
3239
|
-
inputs: [{ name: "owner", type: "address" }],
|
|
3240
|
-
name: "balanceOf",
|
|
3241
|
-
outputs: [{ name: "", type: "uint256" }],
|
|
3242
|
-
stateMutability: "view",
|
|
3243
|
-
type: "function",
|
|
3244
|
-
},
|
|
3245
|
-
{
|
|
3246
|
-
inputs: [],
|
|
3247
|
-
name: "decimals",
|
|
3248
|
-
outputs: [{ name: "", type: "uint8" }],
|
|
3249
|
-
stateMutability: "view",
|
|
3250
|
-
type: "function",
|
|
3251
|
-
},
|
|
3252
|
-
];
|
|
3253
|
-
balance = yield this.callContractMethod(token, erc20Abi, "balanceOf", [
|
|
3254
|
-
royaltyVaultAddress,
|
|
3255
|
-
]);
|
|
3256
|
-
const decimals = yield this.callContractMethod(token, erc20Abi, "decimals", []);
|
|
3257
|
-
balanceFormatted = formatUnits(balance, decimals);
|
|
3258
|
-
}
|
|
3259
|
-
return {
|
|
3260
|
-
royaltyVault: royaltyVaultAddress,
|
|
3261
|
-
balance,
|
|
3262
|
-
balanceFormatted,
|
|
3263
|
-
};
|
|
3264
|
-
}
|
|
3265
|
-
catch (error) {
|
|
3266
|
-
throw new Error(`Failed to retrieve royalties for address ${walletAddress}: ${error instanceof Error ? error.message : String(error)}`);
|
|
3267
|
-
}
|
|
3268
|
-
});
|
|
3269
|
-
}
|
|
3270
|
-
/**
|
|
3271
|
-
* Claim royalties from the royalty vault.
|
|
3272
|
-
* @param {Address} [token] - Optional token address to claim royalties in. If not provided, claims in native token.
|
|
3273
|
-
* @param {Address} [owner] - Optional wallet address to claim royalties for. If not provided, uses the connected wallet.
|
|
3274
|
-
* @returns {Promise<any>} A promise that resolves when the claim transaction is confirmed.
|
|
3275
|
-
* @throws {Error} Throws an error if no wallet is connected and no owner address is provided.
|
|
3276
|
-
*/
|
|
3277
|
-
claimRoyalties(token, owner) {
|
|
3278
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
3279
|
-
const walletAddress = yield __classPrivateFieldGet(this, _Origin_instances, "m", _Origin_resolveWalletAddress).call(this, owner);
|
|
3280
|
-
const royaltyVaultAddress = yield this.getOrCreateRoyaltyVault(walletAddress, true);
|
|
3281
|
-
return this.callContractMethod(royaltyVaultAddress, this.environment.ROYALTY_VAULT_ABI, "claimRoyalty", [token !== null && token !== void 0 ? token : zeroAddress], { waitForReceipt: true });
|
|
3282
|
-
});
|
|
3283
|
-
}
|
|
3284
3108
|
}
|
|
3285
|
-
_Origin_instances = new WeakSet(),
|
|
3286
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
3287
|
-
try {
|
|
3288
|
-
const uploadRes = yield fetch(`${this.environment.AUTH_HUB_BASE_API}/${this.environment.AUTH_ENDPOINT}/origin/upload-url`, {
|
|
3289
|
-
method: "POST",
|
|
3290
|
-
body: JSON.stringify({
|
|
3291
|
-
name: file.name,
|
|
3292
|
-
type: file.type,
|
|
3293
|
-
}),
|
|
3294
|
-
headers: {
|
|
3295
|
-
Authorization: `Bearer ${this.jwt}`,
|
|
3296
|
-
"Content-Type": "application/json",
|
|
3297
|
-
},
|
|
3298
|
-
});
|
|
3299
|
-
if (!uploadRes.ok) {
|
|
3300
|
-
throw new Error(`HTTP ${uploadRes.status}: ${uploadRes.statusText}`);
|
|
3301
|
-
}
|
|
3302
|
-
const data = yield uploadRes.json();
|
|
3303
|
-
if (data.isError) {
|
|
3304
|
-
throw new Error(data.message || "Failed to generate upload URL");
|
|
3305
|
-
}
|
|
3306
|
-
return data.data;
|
|
3307
|
-
}
|
|
3308
|
-
catch (error) {
|
|
3309
|
-
console.error("Failed to generate upload URL:", error);
|
|
3310
|
-
throw error;
|
|
3311
|
-
}
|
|
3312
|
-
});
|
|
3313
|
-
}, _Origin_setOriginStatus = function _Origin_setOriginStatus(key, status) {
|
|
3109
|
+
_Origin_generateURL = new WeakMap(), _Origin_setOriginStatus = new WeakMap(), _Origin_instances = new WeakSet(), _Origin_waitForTxReceipt = function _Origin_waitForTxReceipt(txHash) {
|
|
3314
3110
|
return __awaiter(this, void 0, void 0, function* () {
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
}),
|
|
3322
|
-
headers: {
|
|
3323
|
-
Authorization: `Bearer ${this.jwt}`,
|
|
3324
|
-
"Content-Type": "application/json",
|
|
3325
|
-
},
|
|
3326
|
-
});
|
|
3327
|
-
if (!res.ok) {
|
|
3328
|
-
const errorText = yield res.text().catch(() => "Unknown error");
|
|
3329
|
-
throw new Error(`HTTP ${res.status}: ${errorText}`);
|
|
3330
|
-
}
|
|
3331
|
-
return true;
|
|
3332
|
-
}
|
|
3333
|
-
catch (error) {
|
|
3334
|
-
console.error("Failed to update origin status:", error);
|
|
3335
|
-
throw error;
|
|
3336
|
-
}
|
|
3337
|
-
});
|
|
3338
|
-
}, _Origin_waitForTxReceipt = function _Origin_waitForTxReceipt(txHash_1) {
|
|
3339
|
-
return __awaiter(this, arguments, void 0, function* (txHash, opts = {}) {
|
|
3340
|
-
var _a, _b, _c;
|
|
3341
|
-
const publicClient = getPublicClient();
|
|
3342
|
-
let currentHash = txHash;
|
|
3343
|
-
const confirmations = (_a = opts.confirmations) !== null && _a !== void 0 ? _a : 1;
|
|
3344
|
-
const timeout = (_b = opts.timeoutMs) !== null && _b !== void 0 ? _b : 180000;
|
|
3345
|
-
const pollingInterval = (_c = opts.pollingIntervalMs) !== null && _c !== void 0 ? _c : 1500;
|
|
3346
|
-
try {
|
|
3347
|
-
const receipt = yield publicClient.waitForTransactionReceipt({
|
|
3348
|
-
hash: currentHash,
|
|
3349
|
-
confirmations,
|
|
3350
|
-
timeout,
|
|
3351
|
-
pollingInterval,
|
|
3352
|
-
onReplaced: (replacement) => {
|
|
3353
|
-
currentHash = replacement.transaction.hash;
|
|
3354
|
-
},
|
|
3111
|
+
if (!this.viemClient)
|
|
3112
|
+
throw new Error("WalletClient not connected.");
|
|
3113
|
+
while (true) {
|
|
3114
|
+
const receipt = yield this.viemClient.request({
|
|
3115
|
+
method: "eth_getTransactionReceipt",
|
|
3116
|
+
params: [txHash],
|
|
3355
3117
|
});
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
catch (err) {
|
|
3359
|
-
// fallback
|
|
3360
|
-
const start = Date.now();
|
|
3361
|
-
while (Date.now() - start < timeout) {
|
|
3362
|
-
try {
|
|
3363
|
-
const receipt = yield publicClient.getTransactionReceipt({
|
|
3364
|
-
hash: currentHash,
|
|
3365
|
-
});
|
|
3366
|
-
if (receipt && receipt.blockNumber)
|
|
3367
|
-
return receipt;
|
|
3368
|
-
}
|
|
3369
|
-
catch (_d) { }
|
|
3370
|
-
yield new Promise((r) => setTimeout(r, pollingInterval));
|
|
3118
|
+
if (receipt && receipt.blockNumber) {
|
|
3119
|
+
return receipt;
|
|
3371
3120
|
}
|
|
3372
|
-
|
|
3121
|
+
yield new Promise((res) => setTimeout(res, 1000));
|
|
3373
3122
|
}
|
|
3374
3123
|
});
|
|
3375
3124
|
}, _Origin_ensureChainId = function _Origin_ensureChainId(chain) {
|
|
@@ -3377,15 +3126,14 @@ _Origin_instances = new WeakSet(), _Origin_generateURL = function _Origin_genera
|
|
|
3377
3126
|
// return;
|
|
3378
3127
|
if (!this.viemClient)
|
|
3379
3128
|
throw new Error("WalletClient not connected.");
|
|
3380
|
-
let currentChainId =
|
|
3129
|
+
let currentChainId = yield this.viemClient.request({
|
|
3381
3130
|
method: "eth_chainId",
|
|
3382
3131
|
params: [],
|
|
3383
|
-
})
|
|
3132
|
+
});
|
|
3384
3133
|
if (typeof currentChainId === "string") {
|
|
3385
3134
|
currentChainId = parseInt(currentChainId, 16);
|
|
3386
3135
|
}
|
|
3387
3136
|
if (currentChainId !== chain.id) {
|
|
3388
|
-
setChain(chain);
|
|
3389
3137
|
try {
|
|
3390
3138
|
yield this.viemClient.request({
|
|
3391
3139
|
method: "wallet_switchEthereumChain",
|
|
@@ -3417,28 +3165,6 @@ _Origin_instances = new WeakSet(), _Origin_generateURL = function _Origin_genera
|
|
|
3417
3165
|
}
|
|
3418
3166
|
}
|
|
3419
3167
|
});
|
|
3420
|
-
}, _Origin_resolveWalletAddress = function _Origin_resolveWalletAddress(owner) {
|
|
3421
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
3422
|
-
if (owner) {
|
|
3423
|
-
return owner;
|
|
3424
|
-
}
|
|
3425
|
-
if (!this.viemClient) {
|
|
3426
|
-
throw new Error("No wallet address provided and no wallet client connected. Please provide an owner address or connect a wallet.");
|
|
3427
|
-
}
|
|
3428
|
-
try {
|
|
3429
|
-
const accounts = yield this.viemClient.request({
|
|
3430
|
-
method: "eth_requestAccounts",
|
|
3431
|
-
params: [],
|
|
3432
|
-
});
|
|
3433
|
-
if (!accounts || accounts.length === 0) {
|
|
3434
|
-
throw new Error("No accounts found in connected wallet.");
|
|
3435
|
-
}
|
|
3436
|
-
return accounts[0];
|
|
3437
|
-
}
|
|
3438
|
-
catch (error) {
|
|
3439
|
-
throw new Error(`Failed to get wallet address: ${error instanceof Error ? error.message : String(error)}`);
|
|
3440
|
-
}
|
|
3441
|
-
});
|
|
3442
3168
|
};
|
|
3443
3169
|
|
|
3444
3170
|
var _Auth_instances, _Auth_triggers, _Auth_ackeeInstance, _Auth_trigger, _Auth_loadAuthStatusFromStorage, _Auth_requestAccount, _Auth_fetchNonce, _Auth_verifySignature, _Auth_createMessage, _Auth_sendAnalyticsEvent;
|
|
@@ -5130,7 +4856,6 @@ const AuthModal = ({ setIsVisible, wcProvider, loading, onlyWagmi, defaultProvid
|
|
|
5130
4856
|
wagmiConnectorClient = useConnectorClient();
|
|
5131
4857
|
wagmiAccount = useAccount();
|
|
5132
4858
|
}
|
|
5133
|
-
const { addToast: toast } = useToast();
|
|
5134
4859
|
if (!auth) {
|
|
5135
4860
|
throw new Error("Auth instance is not available. Make sure to wrap your component with CampProvider.");
|
|
5136
4861
|
}
|
|
@@ -5203,7 +4928,7 @@ const AuthModal = ({ setIsVisible, wcProvider, loading, onlyWagmi, defaultProvid
|
|
|
5203
4928
|
}
|
|
5204
4929
|
};
|
|
5205
4930
|
}, [wcProvider]);
|
|
5206
|
-
const handleConnect = (provider) =>
|
|
4931
|
+
const handleConnect = (provider) => {
|
|
5207
4932
|
var _a, _b;
|
|
5208
4933
|
if (provider) {
|
|
5209
4934
|
let addr = null;
|
|
@@ -5221,14 +4946,8 @@ const AuthModal = ({ setIsVisible, wcProvider, loading, onlyWagmi, defaultProvid
|
|
|
5221
4946
|
((_b = provider === null || provider === void 0 ? void 0 : provider.provider) === null || _b === void 0 ? void 0 : _b.uid) === (customProvider === null || customProvider === void 0 ? void 0 : customProvider.uid)) {
|
|
5222
4947
|
auth.setWalletAddress(customAccount === null || customAccount === void 0 ? void 0 : customAccount.address);
|
|
5223
4948
|
}
|
|
5224
|
-
|
|
5225
|
-
|
|
5226
|
-
}
|
|
5227
|
-
catch (error) {
|
|
5228
|
-
console.error("Error during connect:", error);
|
|
5229
|
-
toast("Error connecting wallet. Please try again.", "error", 5000);
|
|
5230
|
-
}
|
|
5231
|
-
});
|
|
4949
|
+
connect();
|
|
4950
|
+
};
|
|
5232
4951
|
return (React.createElement("div", { className: styles["outer-container"] },
|
|
5233
4952
|
React.createElement("div", { className: `${styles.container} ${styles["linking-container"]}` },
|
|
5234
4953
|
React.createElement(ArrowCorners, { padding: 8, color: "#AAA" }),
|