Skip to content

Commit

Permalink
Merge branch 'feat/etherV6_support' into feat/delta
Browse files Browse the repository at this point in the history
  • Loading branch information
Velenir committed Nov 11, 2024
2 parents 36fb501 + 9103ded commit ace4561
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Refer to the documentation of the ParaSwap API: https://developers.paraswap.netw

**Canonical**: bring only the functions you actually need

**Lightweight**: 400B Gzipped for the minimal variant
**Lightweight**: 10KB Gzipped for the minimal variant

## Installing ParaSwap SDK

Expand Down
21 changes: 1 addition & 20 deletions src/helpers/providers/ethersV6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import type {
ContractRunner,
Contract as EthersContract,
Overrides,
TypedDataDomain,
ContractTransactionResponse,
} from 'ethers';

Expand Down Expand Up @@ -103,14 +102,7 @@ export const constructContractCaller = (

const { data, domain, types } = typedData;

const normalizedDomain: TypedDataDomain = {
...domain,
salt: isArrayLikeNumber(domain.salt)
? new Uint8Array(domain.salt)
: domain.salt,
};

return signer.signTypedData(normalizedDomain, types, data);
return signer.signTypedData(domain, types, data);
};

return { staticCall, transactCall, signTypedDataCall };
Expand All @@ -127,14 +119,3 @@ function isEthersSigner(
): providerOrSigner is Signer {
return 'getAddress' in providerOrSigner;
}

function isArrayLikeNumber(arr: unknown): arr is ArrayLike<number> {
const isArrLike =
typeof arr === 'object' &&
arr !== null &&
'length' in arr &&
typeof arr['length'] === 'number';
if (!isArrLike) return false;
if (arr.length === 0) return true;
return '0' in arr && typeof arr[0] === 'number';
}
2 changes: 1 addition & 1 deletion src/helpers/providers/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { TypedDataField } from '@ethersproject/abstract-signer';
import { assert } from 'ts-essentials';
import { TypedDataField } from '../../methods/common/orders/buildOrderData';

// regex from @ethersproject/hash TypedDataEncoder.constructor
// may be overly strict, but reliable
Expand Down
4 changes: 3 additions & 1 deletion src/helpers/providers/viem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,10 @@ export const constructContractCaller = (

const primaryType = findPrimaryType(types);

const chainId =
domain.chainId === undefined ? undefined : Number(domain.chainId);
const viemDomain: TypedDataDomain = {
chainId: domain.chainId,
chainId,
name: domain.name,
version: domain.version,
verifyingContract: domain.verifyingContract as Hex,
Expand Down
18 changes: 11 additions & 7 deletions src/methods/common/orders/buildOrderData.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import type {
TypedDataDomain as EthersTypedDataDomain,
TypedDataField,
} from '@ethersproject/abstract-signer';

export const name = 'AUGUSTUS RFQ';
export const version = '1';
export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';

type TypedDataDomain = Omit<EthersTypedDataDomain, 'chainId'> & {
chainId: number;
type TypedDataDomain = {
name?: string;
version?: string;
chainId?: bigint | string | number;
verifyingContract?: string;
salt?: string;
};

export type TypedDataField = {
name: string;
type: string;
};

export type SignableTypedData = {
Expand Down
76 changes: 75 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { JsonFragment } from '@ethersproject/abi';
import type {
OptimalRate,
OptionalRate,
Expand Down Expand Up @@ -161,3 +160,78 @@ export type PriceRouteApiErrorResponse =
| { error: string; value: string; priceRoute: OptimalRate };

export type AnyFunction = (...args: any[]) => any;

// --------- from ethers types --------------
export interface JsonFragmentType {
/**
* The parameter name.
*/
readonly name?: string;

/**
* If the parameter is indexed.
*/
readonly indexed?: boolean;

/**
* The type of the parameter.
*/
readonly type?: string;

/**
* The internal Solidity type.
*/
readonly internalType?: string;

/**
* The components for a tuple.
*/
readonly components?: ReadonlyArray<JsonFragmentType>;
}

export interface JsonFragment {
/**
* The name of the error, event, function, etc.
*/
readonly name?: string;

/**
* The type of the fragment (e.g. ``event``, ``"function"``, etc.)
*/
readonly type?: string;

/**
* If the event is anonymous.
*/
readonly anonymous?: boolean;

/**
* If the function is payable.
*/
readonly payable?: boolean;

/**
* If the function is constant.
*/
readonly constant?: boolean;

/**
* The mutability state of the function.
*/
readonly stateMutability?: string;

/**
* The input parameters.
*/
readonly inputs?: ReadonlyArray<JsonFragmentType>;

/**
* The output parameters.
*/
readonly outputs?: ReadonlyArray<JsonFragmentType>;

/**
* The gas limit to use when sending a transaction for this function.
*/
readonly gas?: string;
}

0 comments on commit ace4561

Please sign in to comment.