@reserve-protocol/sdk 0.1.2 → 0.1.4

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.d.mts CHANGED
@@ -25789,6 +25789,7 @@ type ProposalContractDecoder = {
25789
25789
  readonly contract: string;
25790
25790
  readonly abi: Abi;
25791
25791
  };
25792
+ type ProposalContractDecoderMap = Map<string, ProposalContractDecoder | readonly ProposalContractDecoder[]>;
25792
25793
  type IndexDtfProposalGovernanceContractContext = {
25793
25794
  readonly address: Address;
25794
25795
  readonly timelock: {
@@ -25823,7 +25824,7 @@ type IndexDtfProposalDtfContractContext = {
25823
25824
  type DecodeIndexDtfProposalCalldatasParams = {
25824
25825
  readonly targets: readonly Address[];
25825
25826
  readonly calldatas: readonly `0x${string}`[];
25826
- readonly contractMap: Map<string, ProposalContractDecoder>;
25827
+ readonly contractMap: ProposalContractDecoderMap;
25827
25828
  };
25828
25829
  type DecodeIndexDtfProposalParams = {
25829
25830
  readonly chainId: SupportedChainId;
package/dist/index.mjs CHANGED
@@ -10314,6 +10314,51 @@ const dtfIndexStakingVaultOptimisticAbi = [
10314
10314
  }
10315
10315
  ];
10316
10316
  //#endregion
10317
+ //#region src/index-dtf/abis/optimistic-timelock.ts
10318
+ const optimisticTimelockAbi = [{
10319
+ type: "function",
10320
+ name: "getRoleMemberCount",
10321
+ inputs: [{
10322
+ name: "role",
10323
+ type: "bytes32",
10324
+ internalType: "bytes32"
10325
+ }],
10326
+ outputs: [{
10327
+ name: "",
10328
+ type: "uint256",
10329
+ internalType: "uint256"
10330
+ }],
10331
+ stateMutability: "view"
10332
+ }, {
10333
+ type: "function",
10334
+ name: "getRoleMember",
10335
+ inputs: [{
10336
+ name: "role",
10337
+ type: "bytes32",
10338
+ internalType: "bytes32"
10339
+ }, {
10340
+ name: "index",
10341
+ type: "uint256",
10342
+ internalType: "uint256"
10343
+ }],
10344
+ outputs: [{
10345
+ name: "",
10346
+ type: "address",
10347
+ internalType: "address"
10348
+ }],
10349
+ stateMutability: "view"
10350
+ }];
10351
+ //#endregion
10352
+ //#region src/index-dtf/governance/optimistic-errors.ts
10353
+ function isUnsupportedOptimisticContractError(error) {
10354
+ const message = error instanceof Error ? error.message.toLowerCase() : String(error).toLowerCase();
10355
+ return message.includes("returned no data") || message.includes("could not decode") || message.includes("data size of 0 bytes") || message.includes("function") && message.includes("not found");
10356
+ }
10357
+ function isUnsupportedVoteLockOptimisticReadError(error) {
10358
+ const message = error instanceof Error ? error.message.toLowerCase() : String(error).toLowerCase();
10359
+ return isUnsupportedOptimisticContractError(error) || (message.includes("execution reverted") || message.includes("reverted")) && (message.includes("optimisticdelegates") || message.includes("getoptimisticvotes") || message.includes("getpastoptimisticvotes"));
10360
+ }
10361
+ //#endregion
10317
10362
  //#region src/index-dtf/governance/utils.ts
10318
10363
  const D18$1 = 10n ** 18n;
10319
10364
  const MAX_UINT256$2 = (1n << 256n) - 1n;
@@ -10466,51 +10511,6 @@ function getVotePercentage(votes, totalVotes) {
10466
10511
  return Number(votes * 10000n / totalVotes) / 100;
10467
10512
  }
10468
10513
  //#endregion
10469
- //#region src/index-dtf/abis/optimistic-timelock.ts
10470
- const optimisticTimelockAbi = [{
10471
- type: "function",
10472
- name: "getRoleMemberCount",
10473
- inputs: [{
10474
- name: "role",
10475
- type: "bytes32",
10476
- internalType: "bytes32"
10477
- }],
10478
- outputs: [{
10479
- name: "",
10480
- type: "uint256",
10481
- internalType: "uint256"
10482
- }],
10483
- stateMutability: "view"
10484
- }, {
10485
- type: "function",
10486
- name: "getRoleMember",
10487
- inputs: [{
10488
- name: "role",
10489
- type: "bytes32",
10490
- internalType: "bytes32"
10491
- }, {
10492
- name: "index",
10493
- type: "uint256",
10494
- internalType: "uint256"
10495
- }],
10496
- outputs: [{
10497
- name: "",
10498
- type: "address",
10499
- internalType: "address"
10500
- }],
10501
- stateMutability: "view"
10502
- }];
10503
- //#endregion
10504
- //#region src/index-dtf/governance/optimistic-errors.ts
10505
- function isUnsupportedOptimisticContractError(error) {
10506
- const message = error instanceof Error ? error.message.toLowerCase() : String(error).toLowerCase();
10507
- return message.includes("returned no data") || message.includes("could not decode") || message.includes("data size of 0 bytes") || message.includes("function") && message.includes("not found");
10508
- }
10509
- function isUnsupportedVoteLockOptimisticReadError(error) {
10510
- const message = error instanceof Error ? error.message.toLowerCase() : String(error).toLowerCase();
10511
- return isUnsupportedOptimisticContractError(error) || (message.includes("execution reverted") || message.includes("reverted")) && (message.includes("optimisticdelegates") || message.includes("getoptimisticvotes") || message.includes("getpastoptimisticvotes"));
10512
- }
10513
- //#endregion
10514
10514
  //#region src/index-dtf/governance/optimistic.ts
10515
10515
  const MAX_UINT256$1 = (1n << 256n) - 1n;
10516
10516
  const OPTIMISTIC_PROPOSER_ROLE = "0x26f49d08685d9cdd4951a7470bc8fbe9dd0f00419c1a44c1b89f845867ae12e0";
@@ -22882,9 +22882,9 @@ const EXTRA_PROPOSAL_CONTRACTS = [
22882
22882
  contract: "Reserve Optimistic Governance Spell",
22883
22883
  abi: upgradeSpellProposalAbi,
22884
22884
  addresses: {
22885
- 1: "0x082E701456cd702fBE5797Ab515e6B00580E5a14",
22886
- 8453: "0x0aDc69041a2B086f8772aCcE2A754f410F211bed",
22887
- 56: "0x02Ee6862cF431D7CEaa78112D635D2Be7DdFC178"
22885
+ 1: "0xd7238463494fdd4b103c2ad9d229b3985b5bc6f1",
22886
+ 8453: "0xe9ae2cb2b5e5658035617f92efa1878429f9cd3f",
22887
+ 56: "0x3dde17cfd36e740cb7452cb2f59fc925eacb91ab"
22888
22888
  }
22889
22889
  }
22890
22890
  ];
@@ -22916,24 +22916,33 @@ function buildProposalContractMap({ chainId, dtf, proposalGovernance }) {
22916
22916
  addContract(contracts, proposalGovernance.address, getGovernanceContractName(proposalGovernance.timelock.type), dtfIndexGovernanceProposalAbi);
22917
22917
  addContract(contracts, proposalGovernance.timelock.address, getTimelockContractName(proposalGovernance.timelock.type), timelockAbi);
22918
22918
  }
22919
- for (const extraContract of EXTRA_PROPOSAL_CONTRACTS) addContract(contracts, extraContract.addresses[chainId], extraContract.contract, extraContract.abi);
22919
+ for (const extraContract of EXTRA_PROPOSAL_CONTRACTS) addContract(contracts, extraContract.addresses[chainId], extraContract.contract, extraContract.abi, true);
22920
22920
  return contracts;
22921
22921
  }
22922
22922
  function getContractAliases(contractMap) {
22923
22923
  const aliases = {};
22924
- for (const contract of contractMap.values()) aliases[contract.target] = contract.contract;
22924
+ for (const entry of contractMap.values()) {
22925
+ const contract = getContractDecoders$1(entry)[0];
22926
+ if (!contract) continue;
22927
+ aliases[contract.target] = contract.contract;
22928
+ }
22925
22929
  return aliases;
22926
22930
  }
22927
- function addContract(contracts, target, contract, abi) {
22931
+ function addContract(contracts, target, contract, abi, prefer = false) {
22928
22932
  if (!target) return;
22929
22933
  const address = getAddress(target);
22930
22934
  const key = address.toLowerCase();
22931
- if (contracts.has(key)) return;
22932
- contracts.set(key, {
22935
+ const decoder = {
22933
22936
  target: address,
22934
22937
  contract,
22935
22938
  abi
22936
- });
22939
+ };
22940
+ const existing = getContractDecoders$1(contracts.get(key));
22941
+ contracts.set(key, existing ? prefer ? [decoder, ...existing] : [...existing, decoder] : [decoder]);
22942
+ }
22943
+ function getContractDecoders$1(entry) {
22944
+ if (!entry) return [];
22945
+ return "abi" in entry ? [entry] : entry;
22937
22946
  }
22938
22947
  function getGovernanceContractName(type) {
22939
22948
  if (type === "OWNER") return "Owner Governance";
@@ -22967,8 +22976,8 @@ function decodeIndexDtfProposalCalldatas({ targets, calldatas, contractMap }) {
22967
22976
  const callData = calldatas[i];
22968
22977
  const targetAddress = getAddress(target);
22969
22978
  const targetKey = targetAddress.toLowerCase();
22970
- const contractDecoder = contractMap.get(targetKey);
22971
- if (!contractDecoder) {
22979
+ const contractDecoders = getContractDecoders(contractMap.get(targetKey));
22980
+ if (contractDecoders.length === 0) {
22972
22981
  const fallbackDecoded = decodeFallbackProposalCalldata(i, targetAddress, callData);
22973
22982
  if (fallbackDecoded) {
22974
22983
  calls.push(fallbackDecoded);
@@ -22985,7 +22994,7 @@ function decodeIndexDtfProposalCalldatas({ targets, calldatas, contractMap }) {
22985
22994
  pushUnknownContractGroup(unknownContracts, unknownGroupMap, unknownCall);
22986
22995
  continue;
22987
22996
  }
22988
- const decoded = decodeProposalCalldata(contractDecoder, i, targetAddress, callData);
22997
+ const decoded = decodeProposalCalldata(contractDecoders, i, targetAddress, callData);
22989
22998
  if (decoded) {
22990
22999
  calls.push(decoded);
22991
23000
  pushDecodedContractGroup(dataByContract, dataGroupMap, decoded);
@@ -22993,7 +23002,7 @@ function decodeIndexDtfProposalCalldatas({ targets, calldatas, contractMap }) {
22993
23002
  const unknownCall = {
22994
23003
  index: i,
22995
23004
  target: targetAddress,
22996
- contract: contractDecoder.contract,
23005
+ contract: contractDecoders[0].contract,
22997
23006
  callData
22998
23007
  };
22999
23008
  unknownCalls.push(unknownCall);
@@ -23043,28 +23052,42 @@ async function getExternalAbiContractMap(explorer, chainId, unknownCalls, contra
23043
23052
  const externalContractMap = new Map(contractMap);
23044
23053
  for (const { target, metadata } of withMetadata) {
23045
23054
  const key = target.toLowerCase();
23046
- const existing = externalContractMap.get(key);
23047
- externalContractMap.set(key, {
23055
+ const existing = getContractDecoders(externalContractMap.get(key));
23056
+ if (existing.length > 0) {
23057
+ const [primary, ...rest] = existing;
23058
+ externalContractMap.set(key, [{
23059
+ ...primary,
23060
+ abi: [...primary.abi, ...metadata.abi]
23061
+ }, ...rest]);
23062
+ continue;
23063
+ }
23064
+ externalContractMap.set(key, [{
23048
23065
  target,
23049
- contract: existing?.contract ?? metadata.contractName,
23050
- abi: existing ? [...existing.abi, ...metadata.abi] : metadata.abi
23051
- });
23066
+ contract: metadata.contractName,
23067
+ abi: metadata.abi
23068
+ }]);
23052
23069
  }
23053
23070
  return externalContractMap;
23054
23071
  }
23055
- function decodeProposalCalldata(contractDecoder, index, target, callData) {
23056
- const decoded = tryDecodeCalldata(contractDecoder.abi, callData);
23057
- if (!decoded) return;
23058
- return {
23059
- index,
23060
- target,
23061
- contract: contractDecoder.contract,
23062
- functionName: decoded.functionName,
23063
- signature: decoded.signature,
23064
- parameters: decoded.parameters,
23065
- params: decoded.params,
23066
- callData
23067
- };
23072
+ function decodeProposalCalldata(contractDecoders, index, target, callData) {
23073
+ for (const contractDecoder of contractDecoders) {
23074
+ const decoded = tryDecodeCalldata(contractDecoder.abi, callData);
23075
+ if (!decoded) continue;
23076
+ return {
23077
+ index,
23078
+ target,
23079
+ contract: contractDecoder.contract,
23080
+ functionName: decoded.functionName,
23081
+ signature: decoded.signature,
23082
+ parameters: decoded.parameters,
23083
+ params: decoded.params,
23084
+ callData
23085
+ };
23086
+ }
23087
+ }
23088
+ function getContractDecoders(entry) {
23089
+ if (!entry) return [];
23090
+ return "abi" in entry ? [entry] : entry;
23068
23091
  }
23069
23092
  function tryDecodeCalldata(abi, callData) {
23070
23093
  try {
@@ -23091,10 +23114,10 @@ function tryDecodeCalldata(abi, callData) {
23091
23114
  }
23092
23115
  function decodeFallbackProposalCalldata(index, target, callData) {
23093
23116
  for (const fallbackDecoder of FALLBACK_DECODERS) {
23094
- const decoded = decodeProposalCalldata({
23117
+ const decoded = decodeProposalCalldata([{
23095
23118
  ...fallbackDecoder,
23096
23119
  target
23097
- }, index, target, callData);
23120
+ }], index, target, callData);
23098
23121
  if (decoded) return decoded;
23099
23122
  }
23100
23123
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reserve-protocol/sdk",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Core TypeScript SDK for DTF interface integrations.",
5
5
  "keywords": [
6
6
  "dtf",