@panoptic-eng/sdk 1.0.73 → 1.0.74
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/{chainDeployments-BGvEeQSH.js → chainDeployments-CA2k02nB.js} +18 -18
- package/dist/cow/index.js.map +1 -1
- package/dist/{cow-12OtZc7G.js → cow-DRZqTpih.js} +1 -1
- package/dist/deployments.js +18 -18
- package/dist/deployments.js.map +1 -1
- package/dist/index.d.ts +62 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +186 -28
- package/dist/index.js.map +1 -1
- package/dist/{irm-BntFNP1P.js → irm-BwOG1LRv.js} +2 -2
- package/dist/panoptic/v2/index.d.ts +8 -1
- package/dist/panoptic/v2/index.d.ts.map +1 -1
- package/dist/panoptic/v2/index.js +57 -30
- package/dist/panoptic/v2/index.js.map +1 -1
- package/dist/panoptic/v2/react-public.d.ts +8 -1
- package/dist/panoptic/v2/react-public.d.ts.map +1 -1
- package/dist/panoptic/v2/react-public.js +57 -30
- package/dist/panoptic/v2/react-public.js.map +1 -1
- package/dist/{rates-c9XVKm3m.js → rates-B9HaWnEM.js} +1 -1
- package/dist/{router-lUA1kp8A.js → router-KwjvMN_z.js} +1 -1
- package/dist/safe/index.d.ts +14 -2
- package/dist/safe/index.d.ts.map +1 -1
- package/dist/safe/index.js +34 -2
- package/dist/safe/index.js.map +1 -1
- package/dist/{transactionFees-BGfyq3Jo.js → transactionFees-CqaoQFF-.js} +1 -1
- package/dist/uniswap/index.js.map +1 -1
- package/dist/{v2-xSELV6jf.js → v2-DlmRqBju.js} +17 -10
- package/dist/vault-transaction-fees.js +18 -18
- package/dist/vault-transaction-fees.js.map +1 -1
- package/dist/{writes-_ZxthOkP.js → writes-CeRXSZwj.js} +27 -7
- package/dist/zodiac/index.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -12694,4 +12694,4 @@ function formatPerSecondRateWadAsAprPct(ratePerSecondWad, precision) {
|
|
|
12694
12694
|
}
|
|
12695
12695
|
|
|
12696
12696
|
//#endregion
|
|
12697
|
-
export { AccountInsolventError, AlreadyInitializedError, BatchValidationError, BelowMinimumRedemptionError, CastingError, ChunkHasZeroLiquidityError, ChunkLimitError, CrossPoolError, DEFAULT_MAX_SPREAD, DEFAULT_MINT_BUFFER, DEFAULT_VEGOID, DepositTooLargeError, DuplicateTokenIdError, EffectiveLiquidityAboveThresholdError, ExceedsMaximumRedemptionError, InputListFailError, InsufficientCreditLiquidityError, InvalidBuilderCodeError, InvalidHistoryRangeError, InvalidTickBoundError, InvalidTickError, InvalidTickLimitsError, InvalidTokenIdParameterError, InvalidUniswapCallbackError, LEG_BITS, LEG_LIMITS, LEG_MASKS, LengthMismatchError, LiquidityTooHighError, LoanSlotExhaustedError, MINT_BUFFER, MINT_BUFFER_DENOMINATOR, MaxRetriesExceededError, MissingPositionIdsError, MulticallNoDataError, MulticallResultFailedError, MulticallResultMissingError, NetLiquidityZeroError, NetworkMismatchError, NoLegsExercisableError, NoLoanPositionsError, NotALongLegError, NotBuilderError, NotEnoughLiquidityInChunkError, NotEnoughTokensError, NotGuardianError, NotMarginCalledError, NotPanopticPoolError, OracleRateLimitedError, PanopticError, PanopticHelperNotDeployedError, PanopticValidationError, PoolNotInitializedError, PositionCountNotZeroError, PositionNotOwnedError, PositionSnapshotNotFoundError, PositionTooLargeError, PriceBoundFailError, PriceImpactTooLargeError, ProviderLagError, ReentrancyError, RpcError, RpcResponseError, STANDARD_TICK_WIDTHS, SafeModeError, StaleDataError, StaleOracleError, StorageDataNotFoundError, SwapTokenMismatchError, SyncTimeoutError, TOKEN_ID_BITS, TokenIdHasZeroLegsError, TooManyLegsOpenError, TransferFailedError, UnauthorizedUniswapCallbackError, UnderOverFlowError, UnhealthyPoolError, UnsafePremiumSettlementError, WrongPoolIdError, WrongUniswapPoolError, ZeroAddressError, ZeroCollateralRequirementError, addLegToTokenId, annualizePerSecondRateWad, applyMintBuffer, applyMintBufferPerToken, availableToBorrow, clearTrackedPositions, collateralTrackerV2Abi, countLegs, createFileStorage, createMemoryStorage, createTxResult, decodeAllDispatchCalldata, decodeAllLegs, decodeDispatchCalldata, decodeLeftRightSigned, decodeLeftRightUnsigned, decodeLeg, decodeOraclePack, decodeOracleRiskParameters, decodeOracleTiming, decodePoolId, decodePositionBalance$1 as decodePositionBalance, decodeSnapshotTransaction, decodeTickSpacing, decodeTokenId, decodeVegoid, diagnoseOracleSafeMode, encodeLeg, encodePoolId, encodeV4PoolId, fetchPoolId, formatPerSecondRateWadAsAprPct, formatPerSecondRateWadAsApyPct, formatRateWad, formatTokenAmount, formatTokenAmountSigned, formatTokenDelta, formatTokenFlow, formatWad, formatWadPercent, formatWadSigned, getAccountPremia, getAssetIndex, getBlockMeta, getClosedPositionsKey, getForfeitablePremium, getOpenPositionIds, getOracleRiskParameters, getOracleState, getPendingPositionsKey, getPool, getPoolCurrentTick, getPoolMetaKey, getPoolMetadata, getPoolPrefix, getPosition, getPositionGreeks, getPositionMetaKey, getPositions, getPositionsKey, getPositionsWithPremia, getRiskParameters, getSchemaVersionKey, getSimpleLoanTokenIndex, getSyncCheckpointKey, getTrackedChunksKey, getTrackedPositionIds, getUtilization, hasLoanOrCredit, hasLongLeg, isCredit, isCreditLeg, isLoan, isLoanLeg, isPanopticErrorType, isPositionTracked, isShortOnly, isSpread, jsonSerializer, mintableAfterBuffer, oracleEpochAt, panopticErrorsAbi, panopticFactoryV3Abi, panopticFactoryV4Abi, panopticGuardianAbi, panopticLiquidatorAbi, panopticPoolV2Abi, panopticQueryAbi, parsePanopticError, parseTokenAmount, parseWad, recoverSnapshot, recoverSnapshotFromTx, riskEngineAbi, riskEngineMulticall, selectDispatchForAccount, semiFungiblePositionManagerV3Abi, semiFungiblePositionManagerV4Abi, stateViewAbi, submitWrite, uniswapV3PoolAbi, validateBuilderCode, validatePoolId };
|
|
12697
|
+
export { AccountInsolventError, AlreadyInitializedError, BatchValidationError, BelowMinimumRedemptionError, CastingError, ChunkHasZeroLiquidityError, ChunkLimitError, CrossPoolError, DEFAULT_MAX_SPREAD, DEFAULT_MINT_BUFFER, DEFAULT_VEGOID, DepositTooLargeError, DuplicateTokenIdError, EffectiveLiquidityAboveThresholdError, ExceedsMaximumRedemptionError, InputListFailError, InsufficientCreditLiquidityError, InvalidBuilderCodeError, InvalidHistoryRangeError, InvalidTickBoundError, InvalidTickError, InvalidTickLimitsError, InvalidTokenIdParameterError, InvalidUniswapCallbackError, LEG_BITS, LEG_LIMITS, LEG_MASKS, LengthMismatchError, LiquidityTooHighError, LoanSlotExhaustedError, MINT_BUFFER, MINT_BUFFER_DENOMINATOR, MaxRetriesExceededError, MissingPositionIdsError, MulticallNoDataError, MulticallResultFailedError, MulticallResultMissingError, NetLiquidityZeroError, NetworkMismatchError, NoLegsExercisableError, NoLoanPositionsError, NotALongLegError, NotBuilderError, NotEnoughLiquidityInChunkError, NotEnoughTokensError, NotGuardianError, NotMarginCalledError, NotPanopticPoolError, OracleRateLimitedError, PanopticError, PanopticHelperNotDeployedError, PanopticValidationError, PoolNotInitializedError, PositionCountNotZeroError, PositionNotOwnedError, PositionSnapshotNotFoundError, PositionTooLargeError, PriceBoundFailError, PriceImpactTooLargeError, ProviderLagError, ReentrancyError, RpcError, RpcResponseError, STANDARD_TICK_WIDTHS, SafeModeError, StaleDataError, StaleOracleError, StorageDataNotFoundError, SwapTokenMismatchError, SyncTimeoutError, TOKEN_ID_BITS, TokenIdHasZeroLegsError, TooManyLegsOpenError, TransferFailedError, UnauthorizedUniswapCallbackError, UnderOverFlowError, UnhealthyPoolError, UnsafePremiumSettlementError, WrongPoolIdError, WrongUniswapPoolError, ZeroAddressError, ZeroCollateralRequirementError, addLegToTokenId, annualizePerSecondRateWad, applyMintBuffer, applyMintBufferPerToken, availableToBorrow, clearTrackedPositions, collateralTrackerV2Abi, countLegs, createFileStorage, createMemoryStorage, createTxResult, decodeAllDispatchCalldata, decodeAllLegs, decodeDispatchCalldata, decodeLeftRightSigned, decodeLeftRightUnsigned, decodeLeg, decodeOraclePack, decodeOracleRiskParameters, decodeOracleTiming, decodePoolId, decodePositionBalance$1 as decodePositionBalance, decodeSnapshotTransaction, decodeTickSpacing, decodeTokenId, decodeVegoid, diagnoseOracleSafeMode, encodeLeg, encodePoolId, encodeV4PoolId, fetchPoolId, formatPerSecondRateWadAsAprPct, formatPerSecondRateWadAsApyPct, formatRateWad, formatTokenAmount, formatTokenAmountSigned, formatTokenDelta, formatTokenFlow, formatWad, formatWadPercent, formatWadSigned, getAccountPremia, getAssetIndex, getBlockMeta, getClosedPositionsKey, getForfeitablePremium, getOpenPositionIds, getOracleRiskParameters, getOracleState, getPendingPositionsKey, getPool, getPoolCurrentTick, getPoolMetaKey, getPoolMetadata, getPoolPrefix, getPosition, getPositionGreeks, getPositionMetaKey, getPositions, getPositionsKey, getPositionsWithPremia, getRiskParameters, getSchemaVersionKey, getSimpleLoanTokenIndex, getSyncCheckpointKey, getTrackedChunksKey, getTrackedPositionIds, getUtilization, hasLoanOrCredit, hasLongLeg, isCredit, isCreditLeg, isLoan, isLoanLeg, isPanopticErrorType, isPositionTracked, isShortOnly, isSpread, jsonSerializer, mintableAfterBuffer, oracleEpochAt, panopticErrorsAbi, panopticFactoryV3Abi, panopticFactoryV4Abi, panopticGuardianAbi, panopticLiquidatorAbi, panopticPoolV2Abi, panopticQueryAbi as panopticQueryAbi$1, parsePanopticError, parseTokenAmount, parseWad, recoverSnapshot, recoverSnapshotFromTx, riskEngineAbi, riskEngineMulticall, selectDispatchForAccount, semiFungiblePositionManagerV3Abi, semiFungiblePositionManagerV4Abi, stateViewAbi, submitWrite, uniswapV3PoolAbi, validateBuilderCode, validatePoolId };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StateViewAbi } from "./StateView-q4yMpBY6.js";
|
|
2
|
-
import { PanopticError, decodeAllLegs, decodeTokenId, getBlockMeta, getPool, getPoolMetadata, stateViewAbi, submitWrite, uniswapV3PoolAbi } from "./rates-
|
|
2
|
+
import { PanopticError, decodeAllLegs, decodeTokenId, getBlockMeta, getPool, getPoolMetadata, stateViewAbi, submitWrite, uniswapV3PoolAbi } from "./rates-B9HaWnEM.js";
|
|
3
3
|
import { getLegLiquidityRange, tickToSqrtPriceX96 } from "./greeks-CEv-Uex1.js";
|
|
4
4
|
import { BaseError, ContractFunctionRevertedError, ExecutionRevertedError, encodeAbiParameters, encodeFunctionData, encodePacked, erc20Abi, isAddressEqual, maxUint256, toHex, zeroAddress } from "viem";
|
|
5
5
|
import Decimal from "decimal.js";
|
package/dist/safe/index.d.ts
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
|
-
import { Address, Hex } from "viem";
|
|
1
|
+
import { Address, Hex, PublicClient } from "viem";
|
|
2
2
|
|
|
3
|
+
//#region src/safe/isSafeAccount.d.ts
|
|
4
|
+
/** Detect deployed Safes by their account interface; RPC failures remain errors. */
|
|
5
|
+
/** Detect deployed Safes by their account interface; RPC failures remain errors. */
|
|
6
|
+
declare function isSafeAccount({
|
|
7
|
+
client,
|
|
8
|
+
address
|
|
9
|
+
}: {
|
|
10
|
+
client: Pick<PublicClient, 'getCode' | 'readContract'>;
|
|
11
|
+
address: Address;
|
|
12
|
+
}): Promise<boolean>;
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
3
15
|
//#region src/safe/signedSafeTx.d.ts
|
|
4
16
|
declare const safeAbi: readonly [{
|
|
5
17
|
readonly type: "event";
|
|
@@ -162,5 +174,5 @@ declare function resolveSignedSafeTx(params: {
|
|
|
162
174
|
}): Promise<SignedSafeTx>;
|
|
163
175
|
/** `execTransaction` arguments for a resolved signed SafeTx. */
|
|
164
176
|
declare function execTransactionArgs(signed: SignedSafeTx): readonly [Address, bigint, `0x${string}`, 0 | 1, bigint, bigint, bigint, Address, Address, `0x${string}`]; //#endregion
|
|
165
|
-
export { SafeCall, SafeTx, SignedSafeTx, SignedSafeTxError, SignedSafeTxErrorCode, assertSafeOwnerSignature, execTransactionArgs, hashSafeTx, isSafeOwnerSignature, recoverSafeTxSigner, resolveSignedSafeTx, safeAbi, safeTxForCall };
|
|
177
|
+
export { SafeCall, SafeTx, SignedSafeTx, SignedSafeTxError, SignedSafeTxErrorCode, assertSafeOwnerSignature, execTransactionArgs, hashSafeTx, isSafeAccount, isSafeOwnerSignature, recoverSafeTxSigner, resolveSignedSafeTx, safeAbi, safeTxForCall };
|
|
166
178
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/safe/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["Address","Hex","safeAbi","SafeCall","SafeTx","SignedSafeTx","SignedSafeTxErrorCode","SignedSafeTxError","Error","hashSafeTx","safeTxForCall","isSafeOwnerSignature","assertSafeOwnerSignature","recoverSafeTxSigner","Promise","resolveSignedSafeTx","execTransactionArgs"],"sources":["../../src/safe/signedSafeTx.d.ts"],"sourcesContent":null,"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["Address","PublicClient","isSafeAccount","client","address","Pick","Promise","Address","Hex","safeAbi","SafeCall","SafeTx","SignedSafeTx","SignedSafeTxErrorCode","SignedSafeTxError","Error","hashSafeTx","safeTxForCall","isSafeOwnerSignature","assertSafeOwnerSignature","recoverSafeTxSigner","Promise","resolveSignedSafeTx","execTransactionArgs"],"sources":["../../src/safe/isSafeAccount.d.ts","../../src/safe/signedSafeTx.d.ts"],"sourcesContent":null,"mappings":";;;;;iBAEwBE,aAAAA;;;;UACZG,KAAKJ;EADOC,OAAAA,EAEXK,OAFwB;CAAA,CAAA,EAGjCc,OAHiC,CAAA,OAAA,CAAA;;;;cCDhBZ;;;EDCGP,SAAAA,MAAAA,EAAa,SAAA,CAAA;IAAA,SAAA,IAAA,EAAA,QAAA;IAAGC,SAAAA,IAAAA,EAAAA,SAAAA;IAAQC,SAAAA,OAAAA,EAAAA,IAAAA;EAAO,CAAA,EACtCH;IAALI,SAAAA,IAAAA,EAAAA,SAAAA;IACCE,SAAAA,IAAAA,EAAAA,SAAA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@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { concatHex, getAddress, hashMessage, hashTypedData, hexToBigInt, hexToNumber, isAddressEqual, numberToHex, recoverAddress, sliceHex, zeroAddress } from "viem";
|
|
1
|
+
import { BaseError, ContractFunctionRevertedError, ContractFunctionZeroDataError, concatHex, getAddress, hashMessage, hashTypedData, hexToBigInt, hexToNumber, isAddressEqual, numberToHex, recoverAddress, sliceHex, zeroAddress } from "viem";
|
|
2
2
|
|
|
3
3
|
//#region src/safe/signedSafeTx.ts
|
|
4
4
|
const safeAbi = [
|
|
@@ -274,5 +274,37 @@ function execTransactionArgs(signed) {
|
|
|
274
274
|
}
|
|
275
275
|
|
|
276
276
|
//#endregion
|
|
277
|
-
|
|
277
|
+
//#region src/safe/isSafeAccount.ts
|
|
278
|
+
/** Detect deployed Safes by their account interface; RPC failures remain errors. */
|
|
279
|
+
async function isSafeAccount({ client, address }) {
|
|
280
|
+
const code = await client.getCode({ address });
|
|
281
|
+
if (!code || code === "0x") return false;
|
|
282
|
+
try {
|
|
283
|
+
const [version, threshold, owners] = await Promise.all([
|
|
284
|
+
client.readContract({
|
|
285
|
+
address,
|
|
286
|
+
abi: safeAbi,
|
|
287
|
+
functionName: "VERSION"
|
|
288
|
+
}),
|
|
289
|
+
client.readContract({
|
|
290
|
+
address,
|
|
291
|
+
abi: safeAbi,
|
|
292
|
+
functionName: "getThreshold"
|
|
293
|
+
}),
|
|
294
|
+
client.readContract({
|
|
295
|
+
address,
|
|
296
|
+
abi: safeAbi,
|
|
297
|
+
functionName: "getOwners"
|
|
298
|
+
})
|
|
299
|
+
]);
|
|
300
|
+
return /^\d+\.\d+\.\d+/.test(version) && threshold > 0n && threshold <= BigInt(owners.length);
|
|
301
|
+
} catch (error) {
|
|
302
|
+
const cause = error instanceof BaseError ? error.walk((cause$1) => cause$1 instanceof ContractFunctionRevertedError || cause$1 instanceof ContractFunctionZeroDataError) : error;
|
|
303
|
+
if (cause instanceof ContractFunctionRevertedError || cause instanceof ContractFunctionZeroDataError) return false;
|
|
304
|
+
throw error;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
//#endregion
|
|
309
|
+
export { SignedSafeTxError, assertSafeOwnerSignature, execTransactionArgs, hashSafeTx, isSafeAccount, isSafeOwnerSignature, recoverSafeTxSigner, resolveSignedSafeTx, safeAbi, safeTxForCall };
|
|
278
310
|
//# sourceMappingURL=index.js.map
|
package/dist/safe/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["code: SignedSafeTxErrorCode","message: string","params: { chainId: number; safe: Address; tx: SafeTx }","call: SafeCall","nonce: bigint","value: unknown","signature: Hex","safeTxHash: Hex","params: {\n chainId: number\n safe: Address\n call: SafeCall\n signature: Hex\n state: { nonce: bigint; threshold: bigint; owners: readonly Address[] }\n nonceWindow?: number\n}","signed: SignedSafeTx"],"sources":["../../src/safe/signedSafeTx.ts"],"sourcesContent":["import {\n type Address,\n type Hex,\n concatHex,\n getAddress,\n hashMessage,\n hashTypedData,\n hexToBigInt,\n hexToNumber,\n isAddressEqual,\n numberToHex,\n recoverAddress,\n sliceHex,\n zeroAddress,\n} from 'viem'\n\nexport const safeAbi = [\n {\n type: 'event',\n name: 'ExecutionSuccess',\n inputs: [\n { name: 'txHash', type: 'bytes32', indexed: true },\n { name: 'payment', type: 'uint256', indexed: false },\n ],\n },\n {\n type: 'function',\n name: 'execTransaction',\n stateMutability: 'payable',\n inputs: [\n { name: 'to', type: 'address' },\n { name: 'value', type: 'uint256' },\n { name: 'data', type: 'bytes' },\n { name: 'operation', type: 'uint8' },\n { name: 'safeTxGas', type: 'uint256' },\n { name: 'baseGas', type: 'uint256' },\n { name: 'gasPrice', type: 'uint256' },\n { name: 'gasToken', type: 'address' },\n { name: 'refundReceiver', type: 'address' },\n { name: 'signatures', type: 'bytes' },\n ],\n outputs: [{ name: 'success', type: 'bool' }],\n },\n {\n type: 'function',\n name: 'VERSION',\n stateMutability: 'view',\n inputs: [],\n outputs: [{ type: 'string' }],\n },\n {\n type: 'function',\n name: 'nonce',\n stateMutability: 'view',\n inputs: [],\n outputs: [{ type: 'uint256' }],\n },\n {\n type: 'function',\n name: 'getThreshold',\n stateMutability: 'view',\n inputs: [],\n outputs: [{ type: 'uint256' }],\n },\n {\n type: 'function',\n name: 'getOwners',\n stateMutability: 'view',\n inputs: [],\n outputs: [{ type: 'address[]' }],\n },\n] as const\n\n/** A plain call the owner asked their wallet to send from the Safe. */\nexport interface SafeCall {\n to: Address\n value: bigint\n data: Hex\n}\n\nexport interface SafeTx extends SafeCall {\n operation: 0 | 1\n safeTxGas: bigint\n baseGas: bigint\n gasPrice: bigint\n gasToken: Address\n refundReceiver: Address\n nonce: bigint\n}\n\nexport interface SignedSafeTx {\n safe: Address\n chainId: number\n tx: SafeTx\n safeTxHash: Hex\n signer: Address\n /** Packed `signatures` argument for `execTransaction`. */\n signatures: Hex\n}\n\nexport type SignedSafeTxErrorCode = 'INVALID_SIGNATURE' | 'THRESHOLD_NOT_MET' | 'SIGNATURE_MISMATCH'\n\nexport class SignedSafeTxError extends Error {\n constructor(\n readonly code: SignedSafeTxErrorCode,\n message: string,\n ) {\n super(message)\n this.name = 'SignedSafeTxError'\n }\n}\n\nconst SAFE_TX_TYPES = {\n SafeTx: [\n { name: 'to', type: 'address' },\n { name: 'value', type: 'uint256' },\n { name: 'data', type: 'bytes' },\n { name: 'operation', type: 'uint8' },\n { name: 'safeTxGas', type: 'uint256' },\n { name: 'baseGas', type: 'uint256' },\n { name: 'gasPrice', type: 'uint256' },\n { name: 'gasToken', type: 'address' },\n { name: 'refundReceiver', type: 'address' },\n { name: 'nonce', type: 'uint256' },\n ],\n} as const\n\n/** EIP-712 SafeTx hash (Safe ≥ 1.3 domain: chainId + verifyingContract). */\nexport function hashSafeTx(params: { chainId: number; safe: Address; tx: SafeTx }): Hex {\n return hashTypedData({\n domain: { chainId: params.chainId, verifyingContract: params.safe },\n types: SAFE_TX_TYPES,\n primaryType: 'SafeTx',\n message: params.tx,\n })\n}\n\n/**\n * A wallet signing a plain call for a Safe owner (Rabby, Safe{Wallet}) signs it\n * with no refund or gas fields; only the nonce varies.\n */\nexport function safeTxForCall(call: SafeCall, nonce: bigint): SafeTx {\n return {\n ...call,\n operation: 0,\n safeTxGas: 0n,\n baseGas: 0n,\n gasPrice: 0n,\n gasToken: zeroAddress,\n refundReceiver: zeroAddress,\n nonce,\n }\n}\n\n/** True for a 65-byte ECDSA signature — what a Safe-owner wallet returns instead of a tx hash. */\nexport function isSafeOwnerSignature(value: unknown): value is Hex {\n return typeof value === 'string' && /^0x[0-9a-fA-F]{130}$/.test(value)\n}\n\nconst SECP256K1_N = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n\nconst SUPPORTED_V = new Set([0, 1, 27, 28, 31, 32])\n\n/**\n * Rejects anything that cannot be a Safe owner's ECDSA signature, without any\n * RPC: 65 bytes, supported v (raw 0/1/27/28 or `eth_sign` 31/32), and r, s in\n * the curve range.\n */\nexport function assertSafeOwnerSignature(signature: Hex): void {\n if (!isSafeOwnerSignature(signature)) {\n throw new SignedSafeTxError('INVALID_SIGNATURE', 'expected a 65-byte ECDSA signature')\n }\n const r = hexToBigInt(sliceHex(signature, 0, 32))\n const s = hexToBigInt(sliceHex(signature, 32, 64))\n const v = hexToNumber(sliceHex(signature, 64, 65))\n if (!SUPPORTED_V.has(v)) {\n throw new SignedSafeTxError('INVALID_SIGNATURE', `unsupported signature v=${v}`)\n }\n if (r === 0n || r >= SECP256K1_N || s === 0n || s >= SECP256K1_N) {\n throw new SignedSafeTxError('INVALID_SIGNATURE', 'signature r/s out of range')\n }\n}\n\n/**\n * Recovers the signer of `safeTxHash`, accepting raw ECDSA (v 27/28, or 0/1)\n * and `eth_sign` (v 31/32) signatures, and returns the signature in the form\n * the Safe verifies.\n */\nexport async function recoverSafeTxSigner(\n safeTxHash: Hex,\n signature: Hex,\n): Promise<{ signer: Address; signature: Hex }> {\n assertSafeOwnerSignature(signature)\n const rs = sliceHex(signature, 0, 64)\n const v = hexToNumber(sliceHex(signature, 64, 65))\n const ethSign = v === 31 || v === 32\n const normalized = ethSign\n ? signature\n : concatHex([rs, numberToHex(v < 27 ? v + 27 : v, { size: 1 })])\n try {\n const signer = ethSign\n ? await recoverAddress({\n hash: hashMessage({ raw: safeTxHash }),\n signature: concatHex([rs, numberToHex(v - 4, { size: 1 })]),\n })\n : await recoverAddress({ hash: safeTxHash, signature: normalized })\n return { signer, signature: normalized }\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error)\n throw new SignedSafeTxError('INVALID_SIGNATURE', `signature recovery failed: ${reason}`)\n }\n}\n\n/**\n * Resolves an owner's signature over a plain call into an executable SafeTx,\n * given the Safe's on-chain `nonce`, `owners` and `threshold`. The signed nonce\n * is not part of the call, so it is searched from the on-chain nonce forward\n * (wallets may sign ahead of queued transactions).\n */\nexport async function resolveSignedSafeTx(params: {\n chainId: number\n safe: Address\n call: SafeCall\n signature: Hex\n state: { nonce: bigint; threshold: bigint; owners: readonly Address[] }\n nonceWindow?: number\n}): Promise<SignedSafeTx> {\n const safe = getAddress(params.safe)\n const nonceWindow = params.nonceWindow ?? 5\n const { nonce, threshold, owners } = params.state\n if (threshold !== 1n) {\n throw new SignedSafeTxError(\n 'THRESHOLD_NOT_MET',\n `Safe threshold is ${threshold}; a single owner signature cannot execute`,\n )\n }\n\n for (let offset = 0n; offset < BigInt(nonceWindow); offset++) {\n const tx = safeTxForCall(params.call, nonce + offset)\n const safeTxHash = hashSafeTx({ chainId: params.chainId, safe, tx })\n const { signer, signature } = await recoverSafeTxSigner(safeTxHash, params.signature)\n if (owners.some((owner) => isAddressEqual(owner, signer))) {\n return { safe, chainId: params.chainId, tx, safeTxHash, signer, signatures: signature }\n }\n }\n throw new SignedSafeTxError(\n 'SIGNATURE_MISMATCH',\n `signature does not recover to an owner of ${safe} for nonces ${nonce}..${nonce + BigInt(nonceWindow) - 1n}`,\n )\n}\n\n/** `execTransaction` arguments for a resolved signed SafeTx. */\nexport function execTransactionArgs(signed: SignedSafeTx) {\n const { tx } = signed\n return [\n tx.to,\n tx.value,\n tx.data,\n tx.operation,\n tx.safeTxGas,\n tx.baseGas,\n tx.gasPrice,\n tx.gasToken,\n tx.refundReceiver,\n signed.signatures,\n ] as const\n}\n"],"mappings":";;;AAgBA,MAAa,UAAU;CACrB;EACE,MAAM;EACN,MAAM;EACN,QAAQ,CACN;GAAE,MAAM;GAAU,MAAM;GAAW,SAAS;EAAM,GAClD;GAAE,MAAM;GAAW,MAAM;GAAW,SAAS;EAAO,CACrD;CACF;CACD;EACE,MAAM;EACN,MAAM;EACN,iBAAiB;EACjB,QAAQ;GACN;IAAE,MAAM;IAAM,MAAM;GAAW;GAC/B;IAAE,MAAM;IAAS,MAAM;GAAW;GAClC;IAAE,MAAM;IAAQ,MAAM;GAAS;GAC/B;IAAE,MAAM;IAAa,MAAM;GAAS;GACpC;IAAE,MAAM;IAAa,MAAM;GAAW;GACtC;IAAE,MAAM;IAAW,MAAM;GAAW;GACpC;IAAE,MAAM;IAAY,MAAM;GAAW;GACrC;IAAE,MAAM;IAAY,MAAM;GAAW;GACrC;IAAE,MAAM;IAAkB,MAAM;GAAW;GAC3C;IAAE,MAAM;IAAc,MAAM;GAAS;EACtC;EACD,SAAS,CAAC;GAAE,MAAM;GAAW,MAAM;EAAQ,CAAC;CAC7C;CACD;EACE,MAAM;EACN,MAAM;EACN,iBAAiB;EACjB,QAAQ,CAAE;EACV,SAAS,CAAC,EAAE,MAAM,SAAU,CAAC;CAC9B;CACD;EACE,MAAM;EACN,MAAM;EACN,iBAAiB;EACjB,QAAQ,CAAE;EACV,SAAS,CAAC,EAAE,MAAM,UAAW,CAAC;CAC/B;CACD;EACE,MAAM;EACN,MAAM;EACN,iBAAiB;EACjB,QAAQ,CAAE;EACV,SAAS,CAAC,EAAE,MAAM,UAAW,CAAC;CAC/B;CACD;EACE,MAAM;EACN,MAAM;EACN,iBAAiB;EACjB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AK,IAAI,SAAS,IAAI,SAAS,OAAO,YAAY,EAAE,UAAU;EAC5D,MAAM,KAAK,cAAc,OAAO,MAAM,QAAQ,OAAO;EACrD,MAAM,aAAa,WAAW;GAAE,SAAS,OAAO;GAAS;GAAM;EAAI,EAAC;EACpE,MAAM,EAAE,QAAQ,WAAW,GAAG,MAAM,oBAAoB,YAAY,OAAO,UAAU;AACrF,MAAI,OAAO,KAAK,CAAC,UAAU,eAAe,OAAO,OAAO,CAAC,CACvD,QAAO;GAAE;GAAM,SAAS,OAAO;GAAS;GAAI;GAAY;GAAQ,YAAY;EAAW;CAE1F;AACD,OAAM,IAAI,kBACR,uBACC,4CAA4C,KAAK,cAAc,MAAM,IAAI,QAAQ,OAAO,YAAY,GAAG,GAAG;AAE9G;;AAGD,SAAgB,oBAAoBC,QAAsB;CACxD,MAAM,EAAE,IAAI,GAAG;AACf,QAAO;EACL,GAAG;EACH,GAAG;EACH,GAAG;EACH,GAAG;EACH,GAAG;EACH,GAAG;EACH,GAAG;EACH,GAAG;EACH,GAAG;EACH,OAAO;CACR;AACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["code: SignedSafeTxErrorCode","message: string","params: { chainId: number; safe: Address; tx: SafeTx }","call: SafeCall","nonce: bigint","value: unknown","signature: Hex","safeTxHash: Hex","params: {\n chainId: number\n safe: Address\n call: SafeCall\n signature: Hex\n state: { nonce: bigint; threshold: bigint; owners: readonly Address[] }\n nonceWindow?: number\n}","signed: SignedSafeTx","cause"],"sources":["../../src/safe/signedSafeTx.ts","../../src/safe/isSafeAccount.ts"],"sourcesContent":["import {\n type Address,\n type Hex,\n concatHex,\n getAddress,\n hashMessage,\n hashTypedData,\n hexToBigInt,\n hexToNumber,\n isAddressEqual,\n numberToHex,\n recoverAddress,\n sliceHex,\n zeroAddress,\n} from 'viem'\n\nexport const safeAbi = [\n {\n type: 'event',\n name: 'ExecutionSuccess',\n inputs: [\n { name: 'txHash', type: 'bytes32', indexed: true },\n { name: 'payment', type: 'uint256', indexed: false },\n ],\n },\n {\n type: 'function',\n name: 'execTransaction',\n stateMutability: 'payable',\n inputs: [\n { name: 'to', type: 'address' },\n { name: 'value', type: 'uint256' },\n { name: 'data', type: 'bytes' },\n { name: 'operation', type: 'uint8' },\n { name: 'safeTxGas', type: 'uint256' },\n { name: 'baseGas', type: 'uint256' },\n { name: 'gasPrice', type: 'uint256' },\n { name: 'gasToken', type: 'address' },\n { name: 'refundReceiver', type: 'address' },\n { name: 'signatures', type: 'bytes' },\n ],\n outputs: [{ name: 'success', type: 'bool' }],\n },\n {\n type: 'function',\n name: 'VERSION',\n stateMutability: 'view',\n inputs: [],\n outputs: [{ type: 'string' }],\n },\n {\n type: 'function',\n name: 'nonce',\n stateMutability: 'view',\n inputs: [],\n outputs: [{ type: 'uint256' }],\n },\n {\n type: 'function',\n name: 'getThreshold',\n stateMutability: 'view',\n inputs: [],\n outputs: [{ type: 'uint256' }],\n },\n {\n type: 'function',\n name: 'getOwners',\n stateMutability: 'view',\n inputs: [],\n outputs: [{ type: 'address[]' }],\n },\n] as const\n\n/** A plain call the owner asked their wallet to send from the Safe. */\nexport interface SafeCall {\n to: Address\n value: bigint\n data: Hex\n}\n\nexport interface SafeTx extends SafeCall {\n operation: 0 | 1\n safeTxGas: bigint\n baseGas: bigint\n gasPrice: bigint\n gasToken: Address\n refundReceiver: Address\n nonce: bigint\n}\n\nexport interface SignedSafeTx {\n safe: Address\n chainId: number\n tx: SafeTx\n safeTxHash: Hex\n signer: Address\n /** Packed `signatures` argument for `execTransaction`. */\n signatures: Hex\n}\n\nexport type SignedSafeTxErrorCode = 'INVALID_SIGNATURE' | 'THRESHOLD_NOT_MET' | 'SIGNATURE_MISMATCH'\n\nexport class SignedSafeTxError extends Error {\n constructor(\n readonly code: SignedSafeTxErrorCode,\n message: string,\n ) {\n super(message)\n this.name = 'SignedSafeTxError'\n }\n}\n\nconst SAFE_TX_TYPES = {\n SafeTx: [\n { name: 'to', type: 'address' },\n { name: 'value', type: 'uint256' },\n { name: 'data', type: 'bytes' },\n { name: 'operation', type: 'uint8' },\n { name: 'safeTxGas', type: 'uint256' },\n { name: 'baseGas', type: 'uint256' },\n { name: 'gasPrice', type: 'uint256' },\n { name: 'gasToken', type: 'address' },\n { name: 'refundReceiver', type: 'address' },\n { name: 'nonce', type: 'uint256' },\n ],\n} as const\n\n/** EIP-712 SafeTx hash (Safe ≥ 1.3 domain: chainId + verifyingContract). */\nexport function hashSafeTx(params: { chainId: number; safe: Address; tx: SafeTx }): Hex {\n return hashTypedData({\n domain: { chainId: params.chainId, verifyingContract: params.safe },\n types: SAFE_TX_TYPES,\n primaryType: 'SafeTx',\n message: params.tx,\n })\n}\n\n/**\n * A wallet signing a plain call for a Safe owner (Rabby, Safe{Wallet}) signs it\n * with no refund or gas fields; only the nonce varies.\n */\nexport function safeTxForCall(call: SafeCall, nonce: bigint): SafeTx {\n return {\n ...call,\n operation: 0,\n safeTxGas: 0n,\n baseGas: 0n,\n gasPrice: 0n,\n gasToken: zeroAddress,\n refundReceiver: zeroAddress,\n nonce,\n }\n}\n\n/** True for a 65-byte ECDSA signature — what a Safe-owner wallet returns instead of a tx hash. */\nexport function isSafeOwnerSignature(value: unknown): value is Hex {\n return typeof value === 'string' && /^0x[0-9a-fA-F]{130}$/.test(value)\n}\n\nconst SECP256K1_N = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n\nconst SUPPORTED_V = new Set([0, 1, 27, 28, 31, 32])\n\n/**\n * Rejects anything that cannot be a Safe owner's ECDSA signature, without any\n * RPC: 65 bytes, supported v (raw 0/1/27/28 or `eth_sign` 31/32), and r, s in\n * the curve range.\n */\nexport function assertSafeOwnerSignature(signature: Hex): void {\n if (!isSafeOwnerSignature(signature)) {\n throw new SignedSafeTxError('INVALID_SIGNATURE', 'expected a 65-byte ECDSA signature')\n }\n const r = hexToBigInt(sliceHex(signature, 0, 32))\n const s = hexToBigInt(sliceHex(signature, 32, 64))\n const v = hexToNumber(sliceHex(signature, 64, 65))\n if (!SUPPORTED_V.has(v)) {\n throw new SignedSafeTxError('INVALID_SIGNATURE', `unsupported signature v=${v}`)\n }\n if (r === 0n || r >= SECP256K1_N || s === 0n || s >= SECP256K1_N) {\n throw new SignedSafeTxError('INVALID_SIGNATURE', 'signature r/s out of range')\n }\n}\n\n/**\n * Recovers the signer of `safeTxHash`, accepting raw ECDSA (v 27/28, or 0/1)\n * and `eth_sign` (v 31/32) signatures, and returns the signature in the form\n * the Safe verifies.\n */\nexport async function recoverSafeTxSigner(\n safeTxHash: Hex,\n signature: Hex,\n): Promise<{ signer: Address; signature: Hex }> {\n assertSafeOwnerSignature(signature)\n const rs = sliceHex(signature, 0, 64)\n const v = hexToNumber(sliceHex(signature, 64, 65))\n const ethSign = v === 31 || v === 32\n const normalized = ethSign\n ? signature\n : concatHex([rs, numberToHex(v < 27 ? v + 27 : v, { size: 1 })])\n try {\n const signer = ethSign\n ? await recoverAddress({\n hash: hashMessage({ raw: safeTxHash }),\n signature: concatHex([rs, numberToHex(v - 4, { size: 1 })]),\n })\n : await recoverAddress({ hash: safeTxHash, signature: normalized })\n return { signer, signature: normalized }\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error)\n throw new SignedSafeTxError('INVALID_SIGNATURE', `signature recovery failed: ${reason}`)\n }\n}\n\n/**\n * Resolves an owner's signature over a plain call into an executable SafeTx,\n * given the Safe's on-chain `nonce`, `owners` and `threshold`. The signed nonce\n * is not part of the call, so it is searched from the on-chain nonce forward\n * (wallets may sign ahead of queued transactions).\n */\nexport async function resolveSignedSafeTx(params: {\n chainId: number\n safe: Address\n call: SafeCall\n signature: Hex\n state: { nonce: bigint; threshold: bigint; owners: readonly Address[] }\n nonceWindow?: number\n}): Promise<SignedSafeTx> {\n const safe = getAddress(params.safe)\n const nonceWindow = params.nonceWindow ?? 5\n const { nonce, threshold, owners } = params.state\n if (threshold !== 1n) {\n throw new SignedSafeTxError(\n 'THRESHOLD_NOT_MET',\n `Safe threshold is ${threshold}; a single owner signature cannot execute`,\n )\n }\n\n for (let offset = 0n; offset < BigInt(nonceWindow); offset++) {\n const tx = safeTxForCall(params.call, nonce + offset)\n const safeTxHash = hashSafeTx({ chainId: params.chainId, safe, tx })\n const { signer, signature } = await recoverSafeTxSigner(safeTxHash, params.signature)\n if (owners.some((owner) => isAddressEqual(owner, signer))) {\n return { safe, chainId: params.chainId, tx, safeTxHash, signer, signatures: signature }\n }\n }\n throw new SignedSafeTxError(\n 'SIGNATURE_MISMATCH',\n `signature does not recover to an owner of ${safe} for nonces ${nonce}..${nonce + BigInt(nonceWindow) - 1n}`,\n )\n}\n\n/** `execTransaction` arguments for a resolved signed SafeTx. */\nexport function execTransactionArgs(signed: SignedSafeTx) {\n const { tx } = signed\n return [\n tx.to,\n tx.value,\n tx.data,\n tx.operation,\n tx.safeTxGas,\n tx.baseGas,\n tx.gasPrice,\n tx.gasToken,\n tx.refundReceiver,\n signed.signatures,\n ] as const\n}\n","import {\n type Address,\n type PublicClient,\n BaseError,\n ContractFunctionRevertedError,\n ContractFunctionZeroDataError,\n} from 'viem'\n\nimport { safeAbi } from './signedSafeTx'\n\n/** Detect deployed Safes by their account interface; RPC failures remain errors. */\nexport async function isSafeAccount({\n client,\n address,\n}: {\n client: Pick<PublicClient, 'getCode' | 'readContract'>\n address: Address\n}): Promise<boolean> {\n const code = await client.getCode({ address })\n if (!code || code === '0x') return false\n\n try {\n const [version, threshold, owners] = await Promise.all([\n client.readContract({ address, abi: safeAbi, functionName: 'VERSION' }),\n client.readContract({ address, abi: safeAbi, functionName: 'getThreshold' }),\n client.readContract({ address, abi: safeAbi, functionName: 'getOwners' }),\n ])\n return /^\\d+\\.\\d+\\.\\d+/.test(version) && threshold > 0n && threshold <= BigInt(owners.length)\n } catch (error) {\n const cause =\n error instanceof BaseError\n ? error.walk(\n (cause) =>\n cause instanceof ContractFunctionRevertedError ||\n cause instanceof ContractFunctionZeroDataError,\n )\n : error\n if (\n cause instanceof ContractFunctionRevertedError ||\n cause instan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