@dzapio/sdk
Version:
A TypeScript/JavaScript SDK for interacting with the DZap protocol, providing utilities for DeFi operations including Swaps, Bridges, and Zaps.
192 lines (191 loc) • 5.87 kB
TypeScript
import { Signer, TypedDataField } from 'ethers';
import { HexString, PermitMode, StatusCodes, TxnStatus } from '..';
import { GaslessTxType } from '../constants';
import { permit2PrimaryType } from '../constants/permit';
import { ContractVersion } from '../enums';
import { Address, TypedDataDomain, WalletClient } from 'viem';
import { AvailableDZapServices, TokenPermitData } from '.';
export declare const defaultWitnessType: {
typeName: string;
type: {
DZapTransferWitness: {
name: string;
type: string;
}[];
};
};
export declare const swapGaslessWitnessType: {
typeName: string;
type: {
DZapSwapWitness: {
name: string;
type: string;
}[];
};
};
export declare const bridgeGaslessWitnessType: {
typeName: string;
type: {
DZapBridgeWitness: {
name: string;
type: string;
}[];
};
};
export declare const BatchPermitAbiParams: readonly [{
readonly name: "permit";
readonly type: "tuple";
readonly components: readonly [{
readonly name: "permitted";
readonly type: "tuple[]";
readonly components: readonly [{
readonly name: "token";
readonly type: "address";
}, {
readonly name: "amount";
readonly type: "uint256";
}];
}, {
readonly name: "nonce";
readonly type: "uint256";
}, {
readonly name: "deadline";
readonly type: "uint256";
}];
}, {
readonly name: "permitSignature";
readonly type: "bytes";
}];
type BaseToken = {
address: HexString;
amount: string;
};
export type TokenWithIndex = {
index: number;
} & BaseToken;
type TokenPermissions = {
token: Address;
amount: bigint;
};
export type TokenWithPermitData = {
index: number;
address: HexString;
amount: string;
permit?: TokenPermitData;
};
export type Permit2PrimaryType = (typeof permit2PrimaryType)[keyof typeof permit2PrimaryType];
type GaslessBaseParams = {
gasless: true;
txId: HexString;
executorFeesHash: HexString;
};
export type GaslessSwapParams = {
txType: typeof GaslessTxType.swap;
swapDataHash: HexString;
} & GaslessBaseParams;
export type GaslessBridgeParams = {
txType: typeof GaslessTxType.bridge;
adapterDataHash: HexString;
swapDataHash?: HexString;
} & GaslessBaseParams;
export type BasePermitParams = {
chainId: number;
account: HexString;
spender: HexString;
rpcUrls?: string[];
deadline?: bigint;
signer: WalletClient | Signer;
contractVersion: ContractVersion;
service: AvailableDZapServices;
};
type Permit2612BaseParams = {
token: TokenWithPermitData;
version: string;
sigDeadline?: bigint;
name: string;
nonce: bigint;
} & BasePermitParams;
export type DefaultPermit2612Params = {
gasless: false;
} & Permit2612BaseParams;
type GaslessSwapPermit2612Params = BasePermitParams & GaslessSwapParams;
type GaslessBridgePermit2612Params = BasePermitParams & GaslessBridgeParams;
export type Gasless2612PermitParams = GaslessSwapPermit2612Params | GaslessBridgePermit2612Params;
export type CustomTypedDataParams = {
account: HexString;
signer: WalletClient | Signer;
domain: TypedDataDomain;
types: Record<string, Array<TypedDataField>>;
message: Record<string, any>;
primaryType: string;
};
export type Permit2612Params = DefaultPermit2612Params | Gasless2612PermitParams;
export type BasePermit2Params = {
tokens: TokenWithPermitData[];
expiration?: bigint;
permitType: Permit2PrimaryType;
firstTokenNonce?: bigint;
} & BasePermitParams;
type DefaultPermit2Params = {
gasless: false;
} & BasePermit2Params;
type GaslessSwapPermit2Params = BasePermit2Params & GaslessSwapParams;
type GaslessBridgePermit2Params = BasePermit2Params & GaslessBridgeParams;
export type Permit2Params = DefaultPermit2Params | GaslessSwapPermit2Params | GaslessBridgePermit2Params;
export type PermitParams = Permit2612Params | Permit2Params;
export type BasePermitResponse = {
status: TxnStatus;
code: StatusCodes;
permitData?: HexString;
nonce?: bigint;
};
export type PermitResponse = {
permitType: PermitMode;
} & BasePermitResponse;
export type BatchPermitResponse = {
permitType: typeof permit2PrimaryType.PermitBatchWitnessTransferFrom;
} & BasePermitResponse;
type BaseWitnessStructure<T, N extends string, TType> = {
witness: T;
witnessTypeName: N;
witnessType: TType;
};
type GaslessWitnessData = {
txId: HexString;
user: HexString;
executorFeesHash: HexString;
swapDataHash: HexString;
};
type BridgeWitnessData = {
adapterDataHash: HexString;
} & GaslessWitnessData;
export type DefaultWitnessData = BaseWitnessStructure<{
owner: HexString;
recipient: HexString;
}, typeof defaultWitnessType.typeName, typeof defaultWitnessType.type>;
export type SwapGaslessWitnessData = BaseWitnessStructure<GaslessWitnessData, typeof swapGaslessWitnessType.typeName, typeof swapGaslessWitnessType.type>;
export type BridgeGaslessWitnessData = BaseWitnessStructure<BridgeWitnessData, typeof bridgeGaslessWitnessType.typeName, typeof bridgeGaslessWitnessType.type>;
export type WitnessData = DefaultWitnessData | SwapGaslessWitnessData | BridgeGaslessWitnessData;
export type PermitSingleValues = {
details: {
token: Address;
amount: bigint;
expiration: bigint;
nonce: number;
};
spender: Address;
sigDeadline: bigint;
};
export type PermitTransferFromValues = {
permitted: TokenPermissions;
spender: Address;
nonce: bigint;
deadline: bigint;
};
export type PermitBatchTransferFromValues = {
permitted: TokenPermissions[];
spender: Address;
nonce: bigint;
deadline: bigint;
};
export {};