@oddmaki-protocol/sdk 1.4.1 → 1.5.0

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.mjs CHANGED
@@ -7119,6 +7119,24 @@ var UmaOracle_default = [
7119
7119
  ],
7120
7120
  outputs: [],
7121
7121
  stateMutability: "nonpayable"
7122
+ },
7123
+ {
7124
+ type: "function",
7125
+ name: "disputeAssertion",
7126
+ inputs: [
7127
+ {
7128
+ name: "assertionId",
7129
+ type: "bytes32",
7130
+ internalType: "bytes32"
7131
+ },
7132
+ {
7133
+ name: "disputer",
7134
+ type: "address",
7135
+ internalType: "address"
7136
+ }
7137
+ ],
7138
+ outputs: [],
7139
+ stateMutability: "nonpayable"
7122
7140
  }
7123
7141
  ];
7124
7142
 
@@ -10497,6 +10515,97 @@ var UmaModule = class extends BaseModule {
10497
10515
  });
10498
10516
  return wallet.writeContract(request);
10499
10517
  }
10518
+ /**
10519
+ * Get the UMA Optimistic Oracle V3 address for the active Diamond.
10520
+ */
10521
+ async getUmaOracleAddress() {
10522
+ return await this.publicClient.readContract({
10523
+ address: this.config.diamondAddress,
10524
+ abi: ProtocolFacet_default,
10525
+ functionName: "getUmaOracle"
10526
+ });
10527
+ }
10528
+ /**
10529
+ * Dispute an active assertion directly on the UMA Optimistic Oracle V3.
10530
+ *
10531
+ * The dispute escalates the assertion to UMA's DVM, which arbitrates the
10532
+ * outcome via tokenholder vote. The disputer must post a bond equal to the
10533
+ * asserter's bond — the winner is reimbursed and receives a share of the
10534
+ * loser's bond.
10535
+ *
10536
+ * @param params.assertionId - The active assertionId to dispute
10537
+ * @param params.autoApprove - Approve the bond currency to the oracle if needed (default: true)
10538
+ *
10539
+ * @returns Transaction hash
10540
+ */
10541
+ async disputeAssertion(params) {
10542
+ const wallet = this.walletClient;
10543
+ const account = await this.getSignerAccount();
10544
+ const accountAddress = await this.getSignerAddress();
10545
+ const autoApprove = params.autoApprove ?? true;
10546
+ const oracleAddress = await this.getUmaOracleAddress();
10547
+ const assertion = await this.publicClient.readContract({
10548
+ address: oracleAddress,
10549
+ abi: UmaOracle_default,
10550
+ functionName: "getAssertion",
10551
+ args: [params.assertionId]
10552
+ });
10553
+ const currency = assertion.currency;
10554
+ const bondAmount = BigInt(assertion.bond);
10555
+ if (assertion.disputer !== "0x0000000000000000000000000000000000000000") {
10556
+ throw new Error("Assertion has already been disputed");
10557
+ }
10558
+ if (assertion.settled) {
10559
+ throw new Error("Assertion is already settled");
10560
+ }
10561
+ const currentTime = Math.floor(Date.now() / 1e3);
10562
+ if (currentTime >= Number(assertion.expirationTime)) {
10563
+ throw new Error("Liveness period has expired \u2014 assertion can no longer be disputed");
10564
+ }
10565
+ const currentAllowance = await this.publicClient.readContract({
10566
+ address: currency,
10567
+ abi: erc20Abi,
10568
+ functionName: "allowance",
10569
+ args: [accountAddress, oracleAddress]
10570
+ });
10571
+ if (currentAllowance < bondAmount && autoApprove) {
10572
+ const approveHash = await wallet.writeContract({
10573
+ address: currency,
10574
+ abi: erc20Abi,
10575
+ functionName: "approve",
10576
+ args: [oracleAddress, bondAmount],
10577
+ account,
10578
+ chain: this.config.chain
10579
+ });
10580
+ await this.publicClient.waitForTransactionReceipt({
10581
+ hash: approveHash,
10582
+ confirmations: 2
10583
+ });
10584
+ } else if (currentAllowance < bondAmount) {
10585
+ throw new Error(
10586
+ `Insufficient bond currency allowance for oracle. Required: ${bondAmount.toString()}, Current: ${currentAllowance.toString()}.`
10587
+ );
10588
+ }
10589
+ const balance = await this.publicClient.readContract({
10590
+ address: currency,
10591
+ abi: erc20Abi,
10592
+ functionName: "balanceOf",
10593
+ args: [accountAddress]
10594
+ });
10595
+ if (balance < bondAmount) {
10596
+ throw new Error(
10597
+ `Insufficient bond currency balance. Required: ${bondAmount.toString()}, Have: ${balance.toString()}`
10598
+ );
10599
+ }
10600
+ const { request } = await this.publicClient.simulateContract({
10601
+ address: oracleAddress,
10602
+ abi: UmaOracle_default,
10603
+ functionName: "disputeAssertion",
10604
+ args: [params.assertionId, accountAddress],
10605
+ account
10606
+ });
10607
+ return wallet.writeContract(request);
10608
+ }
10500
10609
  /**
10501
10610
  * Report resolution after UMA settlement
10502
10611
  */
@@ -10712,7 +10821,9 @@ var UmaModule = class extends BaseModule {
10712
10821
  expirationTime,
10713
10822
  canSettle: currentTime >= expirationTime,
10714
10823
  disputer: assertion.disputer,
10715
- isDisputed: assertion.disputer !== "0x0000000000000000000000000000000000000000"
10824
+ isDisputed: assertion.disputer !== "0x0000000000000000000000000000000000000000",
10825
+ currency: assertion.currency,
10826
+ bond: BigInt(assertion.bond)
10716
10827
  };
10717
10828
  }
10718
10829
  /**