@campnetwork/origin 1.3.0-alpha.5 → 1.3.0-alpha.6
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 +82 -66
- package/dist/core.d.ts +26 -0
- package/dist/core.esm.d.ts +26 -0
- package/dist/core.esm.js +72 -56
- package/dist/react/index.esm.d.ts +26 -0
- package/dist/react/index.esm.js +66 -0
- package/package.json +1 -1
|
@@ -541,6 +541,31 @@ interface DisputeProgress {
|
|
|
541
541
|
*/
|
|
542
542
|
declare function getDisputeProgress(this: Origin, disputeId: bigint): Promise<DisputeProgress>;
|
|
543
543
|
|
|
544
|
+
interface DisputeRequirements {
|
|
545
|
+
bondAmount: bigint;
|
|
546
|
+
protocolFee: bigint;
|
|
547
|
+
totalRequired: bigint;
|
|
548
|
+
tokenAddress: Address;
|
|
549
|
+
isNativeToken: boolean;
|
|
550
|
+
userBalance: bigint;
|
|
551
|
+
hasSufficientBalance: boolean;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Gets the requirements for raising a dispute, including balance check.
|
|
555
|
+
*
|
|
556
|
+
* @param userAddress The address to check balance for.
|
|
557
|
+
* @returns A promise that resolves with the dispute requirements.
|
|
558
|
+
*
|
|
559
|
+
* @example
|
|
560
|
+
* ```typescript
|
|
561
|
+
* const requirements = await origin.getDisputeRequirements(walletAddress);
|
|
562
|
+
* if (!requirements.hasSufficientBalance) {
|
|
563
|
+
* console.log(`Need ${requirements.totalRequired} but only have ${requirements.userBalance}`);
|
|
564
|
+
* }
|
|
565
|
+
* ```
|
|
566
|
+
*/
|
|
567
|
+
declare function getDisputeRequirements(this: Origin, userAddress: Address): Promise<DisputeRequirements>;
|
|
568
|
+
|
|
544
569
|
/**
|
|
545
570
|
* Fractionalizes an IP NFT into fungible ERC20 tokens.
|
|
546
571
|
* The NFT is transferred to the fractionalizer contract and a new ERC20 token is created.
|
|
@@ -909,6 +934,7 @@ declare class Origin {
|
|
|
909
934
|
getDispute: typeof getDispute;
|
|
910
935
|
canVoteOnDispute: typeof canVoteOnDispute;
|
|
911
936
|
getDisputeProgress: typeof getDisputeProgress;
|
|
937
|
+
getDisputeRequirements: typeof getDisputeRequirements;
|
|
912
938
|
fractionalize: typeof fractionalize;
|
|
913
939
|
redeem: typeof redeem;
|
|
914
940
|
getTokenForNFT: typeof getTokenForNFT;
|
package/dist/react/index.esm.js
CHANGED
|
@@ -7301,6 +7301,71 @@ function getDisputeProgress(disputeId) {
|
|
|
7301
7301
|
});
|
|
7302
7302
|
}
|
|
7303
7303
|
|
|
7304
|
+
/**
|
|
7305
|
+
* Gets the requirements for raising a dispute, including balance check.
|
|
7306
|
+
*
|
|
7307
|
+
* @param userAddress The address to check balance for.
|
|
7308
|
+
* @returns A promise that resolves with the dispute requirements.
|
|
7309
|
+
*
|
|
7310
|
+
* @example
|
|
7311
|
+
* ```typescript
|
|
7312
|
+
* const requirements = await origin.getDisputeRequirements(walletAddress);
|
|
7313
|
+
* if (!requirements.hasSufficientBalance) {
|
|
7314
|
+
* console.log(`Need ${requirements.totalRequired} but only have ${requirements.userBalance}`);
|
|
7315
|
+
* }
|
|
7316
|
+
* ```
|
|
7317
|
+
*/
|
|
7318
|
+
function getDisputeRequirements(userAddress) {
|
|
7319
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
7320
|
+
const publicClient = getPublicClient();
|
|
7321
|
+
const disputeContractAddress = this.environment
|
|
7322
|
+
.DISPUTE_CONTRACT_ADDRESS;
|
|
7323
|
+
const disputeAbi = this.environment.DISPUTE_ABI;
|
|
7324
|
+
// Get dispute parameters from the contract
|
|
7325
|
+
const [bondAmount, protocolFee, tokenAddress] = yield Promise.all([
|
|
7326
|
+
publicClient.readContract({
|
|
7327
|
+
address: disputeContractAddress,
|
|
7328
|
+
abi: disputeAbi,
|
|
7329
|
+
functionName: "disputeBond",
|
|
7330
|
+
}),
|
|
7331
|
+
publicClient.readContract({
|
|
7332
|
+
address: disputeContractAddress,
|
|
7333
|
+
abi: disputeAbi,
|
|
7334
|
+
functionName: "protocolDisputeFee",
|
|
7335
|
+
}),
|
|
7336
|
+
publicClient.readContract({
|
|
7337
|
+
address: disputeContractAddress,
|
|
7338
|
+
abi: disputeAbi,
|
|
7339
|
+
functionName: "disputeToken",
|
|
7340
|
+
}),
|
|
7341
|
+
]);
|
|
7342
|
+
const isNativeToken = tokenAddress === zeroAddress;
|
|
7343
|
+
const totalRequired = bondAmount + protocolFee;
|
|
7344
|
+
// Get user's balance
|
|
7345
|
+
let userBalance;
|
|
7346
|
+
if (isNativeToken) {
|
|
7347
|
+
userBalance = yield publicClient.getBalance({ address: userAddress });
|
|
7348
|
+
}
|
|
7349
|
+
else {
|
|
7350
|
+
userBalance = (yield publicClient.readContract({
|
|
7351
|
+
address: tokenAddress,
|
|
7352
|
+
abi: erc20Abi,
|
|
7353
|
+
functionName: "balanceOf",
|
|
7354
|
+
args: [userAddress],
|
|
7355
|
+
}));
|
|
7356
|
+
}
|
|
7357
|
+
return {
|
|
7358
|
+
bondAmount,
|
|
7359
|
+
protocolFee,
|
|
7360
|
+
totalRequired,
|
|
7361
|
+
tokenAddress,
|
|
7362
|
+
isNativeToken,
|
|
7363
|
+
userBalance,
|
|
7364
|
+
hasSufficientBalance: userBalance >= totalRequired,
|
|
7365
|
+
};
|
|
7366
|
+
});
|
|
7367
|
+
}
|
|
7368
|
+
|
|
7304
7369
|
/**
|
|
7305
7370
|
* Fractionalizes an IP NFT into fungible ERC20 tokens.
|
|
7306
7371
|
* The NFT is transferred to the fractionalizer contract and a new ERC20 token is created.
|
|
@@ -7943,6 +8008,7 @@ class Origin {
|
|
|
7943
8008
|
this.getDispute = getDispute.bind(this);
|
|
7944
8009
|
this.canVoteOnDispute = canVoteOnDispute.bind(this);
|
|
7945
8010
|
this.getDisputeProgress = getDisputeProgress.bind(this);
|
|
8011
|
+
this.getDisputeRequirements = getDisputeRequirements.bind(this);
|
|
7946
8012
|
// Fractionalizer module methods
|
|
7947
8013
|
this.fractionalize = fractionalize.bind(this);
|
|
7948
8014
|
this.redeem = redeem.bind(this);
|