@dzapio/sdk 2.0.26 → 2.0.28
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/README.md +4 -2
- package/dist/index.d.mts +9 -3
- package/dist/index.d.ts +9 -3
- package/dist/index.js +22 -28
- package/dist/index.mjs +22 -29
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -245,9 +245,11 @@ const dZapWithCustomRpc = DZapClient.getInstance(customRpcUrls);
|
|
|
245
245
|
- `service`: AvailableDZapServices
|
|
246
246
|
- `mode?`: ApprovalMode (defaults to `ApprovalModes.AutoPermit`)
|
|
247
247
|
- **Output:**
|
|
248
|
-
- `{ status, code, data
|
|
248
|
+
- `{ status, code, data} }`
|
|
249
249
|
- **Description:**
|
|
250
|
-
|
|
250
|
+
- `data` is a map **token address → `{ allowance: bigint, type }`**
|
|
251
|
+
- `type` is an allowance route (`AllowanceTypes`): e.g. direct DZap contract (`dzap`), Permit2 (`permit2`), or EIP-2612 (`eip2612`).
|
|
252
|
+
Use the returned `allowance` vs your required `amount` per token to see if an `approve` or `sign` step is still needed; combine with `type` to choose the right follow-up (`approve`, `sign`, etc.).
|
|
251
253
|
|
|
252
254
|
#### `approve({ chainId, signer, sender, rpcUrls, tokens, service, mode, approvalTxnCallback })`
|
|
253
255
|
|
package/dist/index.d.mts
CHANGED
|
@@ -144,6 +144,13 @@ type PsbtOutput = {
|
|
|
144
144
|
value: number;
|
|
145
145
|
};
|
|
146
146
|
|
|
147
|
+
declare const AllowanceTypes: {
|
|
148
|
+
readonly eip2612: "eip2612";
|
|
149
|
+
readonly permit2: "permit2";
|
|
150
|
+
readonly dzap: "dzap";
|
|
151
|
+
};
|
|
152
|
+
type AllowanceType = (typeof AllowanceTypes)[keyof typeof AllowanceTypes];
|
|
153
|
+
|
|
147
154
|
type HexString = `0x${string}`;
|
|
148
155
|
type StatusResponse = keyof typeof STATUS_RESPONSE;
|
|
149
156
|
type ChainData = {
|
|
@@ -1850,8 +1857,7 @@ declare class DZapClient {
|
|
|
1850
1857
|
data: {
|
|
1851
1858
|
[key: string]: {
|
|
1852
1859
|
allowance: bigint;
|
|
1853
|
-
|
|
1854
|
-
signatureNeeded: boolean;
|
|
1860
|
+
type: AllowanceType;
|
|
1855
1861
|
};
|
|
1856
1862
|
};
|
|
1857
1863
|
}>;
|
|
@@ -1954,4 +1960,4 @@ declare const checkEIP2612PermitSupport: ({ address, chainId, rpcUrls, owner, pe
|
|
|
1954
1960
|
|
|
1955
1961
|
declare const formatToken: <T extends HexString | string = string>(token: T, nativeTokenAddress?: T) => T;
|
|
1956
1962
|
|
|
1957
|
-
export { type ApiRpcResponse, type ApprovalMode, ApprovalModes, type BatchPermitCallbackParams, type BtcTxData, type Chain, type ChainData, type ContractErrorResponse, DZapClient, DZapPermitMode, type DZapTransactionResponse, type EvmTxData, type Fee, type FeeDetails, type GaslessTradeBuildTxnResponse, type HexString, OtherAbis, type ParamQuotes, type PermitMode, PermitTypes, type ProviderDetails, type PsbtInput, type PsbtOutput, type QuoteFilter, QuoteFilters, STATUS, type SVMTxnDetails, Services, type SignPermitResponse, type SignatureCallbackParams, SignatureExpiryInSecs, type SinglePermitCallbackParams, StatusCodes, type StepAction, type SvmTxData, type SwapInfo, SwapInputDataDecoder, type Token, type TokenInfo, type TokenPermitData, type TokenResponse, type TradeBuildTxnRequest, type TradeBuildTxnRequestData, type TradeBuildTxnResponse, type TradeGasBuildTxnResponse, type TradePath, type TradeQuotesRequest, type TradeQuotesRequestData, type TradeQuotesResponse, type TradeStatusResponse, type TradeStep, TxnStatus, type ZapBuildTxnRequest, type ZapBuildTxnResponse, type ZapBundleAction, type ZapBundleRequest, type ZapBundleSrcToken, type ZapBvmTxnDetails, type ZapChains, type ZapEvmTxnDetails, type ZapFee, type ZapIntegratorConfig, type ZapPath, type ZapPathAction, type ZapPathAsset, type ZapPool, type ZapPoolDetails, type ZapPoolDetailsRequest, type ZapPoolsRequest, type ZapPoolsResponse, type ZapPosition, type ZapPositionsRequest, type ZapPositionsResponse, type ZapProviders, type ZapQuoteRequest, type ZapQuoteResponse, type ZapRouteRequestPoolDetails, type ZapRouteRequestPositionDetails, type ZapStatus, type ZapStatusAsset, type ZapStatusRequest, type ZapStatusResponse, type ZapStatusStep, type ZapStep, type ZapTransactionStep, type ZapTxnDetails, type ZapUnderlyingToken, type ZapUnderlyingTokenWithAmount, checkEIP2612PermitSupport, contractErrorActions, erc20Functions, formatToken, getTokensPairKey, zapPathAction, zapStepAction };
|
|
1963
|
+
export { type AllowanceType, AllowanceTypes, type ApiRpcResponse, type ApprovalMode, ApprovalModes, type BatchPermitCallbackParams, type BtcTxData, type Chain, type ChainData, type ContractErrorResponse, DZapClient, DZapPermitMode, type DZapTransactionResponse, type EvmTxData, type Fee, type FeeDetails, type GaslessTradeBuildTxnResponse, type HexString, OtherAbis, type ParamQuotes, type PermitMode, PermitTypes, type ProviderDetails, type PsbtInput, type PsbtOutput, type QuoteFilter, QuoteFilters, STATUS, type SVMTxnDetails, Services, type SignPermitResponse, type SignatureCallbackParams, SignatureExpiryInSecs, type SinglePermitCallbackParams, StatusCodes, type StepAction, type SvmTxData, type SwapInfo, SwapInputDataDecoder, type Token, type TokenInfo, type TokenPermitData, type TokenResponse, type TradeBuildTxnRequest, type TradeBuildTxnRequestData, type TradeBuildTxnResponse, type TradeGasBuildTxnResponse, type TradePath, type TradeQuotesRequest, type TradeQuotesRequestData, type TradeQuotesResponse, type TradeStatusResponse, type TradeStep, TxnStatus, type ZapBuildTxnRequest, type ZapBuildTxnResponse, type ZapBundleAction, type ZapBundleRequest, type ZapBundleSrcToken, type ZapBvmTxnDetails, type ZapChains, type ZapEvmTxnDetails, type ZapFee, type ZapIntegratorConfig, type ZapPath, type ZapPathAction, type ZapPathAsset, type ZapPool, type ZapPoolDetails, type ZapPoolDetailsRequest, type ZapPoolsRequest, type ZapPoolsResponse, type ZapPosition, type ZapPositionsRequest, type ZapPositionsResponse, type ZapProviders, type ZapQuoteRequest, type ZapQuoteResponse, type ZapRouteRequestPoolDetails, type ZapRouteRequestPositionDetails, type ZapStatus, type ZapStatusAsset, type ZapStatusRequest, type ZapStatusResponse, type ZapStatusStep, type ZapStep, type ZapTransactionStep, type ZapTxnDetails, type ZapUnderlyingToken, type ZapUnderlyingTokenWithAmount, checkEIP2612PermitSupport, contractErrorActions, erc20Functions, formatToken, getTokensPairKey, zapPathAction, zapStepAction };
|
package/dist/index.d.ts
CHANGED
|
@@ -144,6 +144,13 @@ type PsbtOutput = {
|
|
|
144
144
|
value: number;
|
|
145
145
|
};
|
|
146
146
|
|
|
147
|
+
declare const AllowanceTypes: {
|
|
148
|
+
readonly eip2612: "eip2612";
|
|
149
|
+
readonly permit2: "permit2";
|
|
150
|
+
readonly dzap: "dzap";
|
|
151
|
+
};
|
|
152
|
+
type AllowanceType = (typeof AllowanceTypes)[keyof typeof AllowanceTypes];
|
|
153
|
+
|
|
147
154
|
type HexString = `0x${string}`;
|
|
148
155
|
type StatusResponse = keyof typeof STATUS_RESPONSE;
|
|
149
156
|
type ChainData = {
|
|
@@ -1850,8 +1857,7 @@ declare class DZapClient {
|
|
|
1850
1857
|
data: {
|
|
1851
1858
|
[key: string]: {
|
|
1852
1859
|
allowance: bigint;
|
|
1853
|
-
|
|
1854
|
-
signatureNeeded: boolean;
|
|
1860
|
+
type: AllowanceType;
|
|
1855
1861
|
};
|
|
1856
1862
|
};
|
|
1857
1863
|
}>;
|
|
@@ -1954,4 +1960,4 @@ declare const checkEIP2612PermitSupport: ({ address, chainId, rpcUrls, owner, pe
|
|
|
1954
1960
|
|
|
1955
1961
|
declare const formatToken: <T extends HexString | string = string>(token: T, nativeTokenAddress?: T) => T;
|
|
1956
1962
|
|
|
1957
|
-
export { type ApiRpcResponse, type ApprovalMode, ApprovalModes, type BatchPermitCallbackParams, type BtcTxData, type Chain, type ChainData, type ContractErrorResponse, DZapClient, DZapPermitMode, type DZapTransactionResponse, type EvmTxData, type Fee, type FeeDetails, type GaslessTradeBuildTxnResponse, type HexString, OtherAbis, type ParamQuotes, type PermitMode, PermitTypes, type ProviderDetails, type PsbtInput, type PsbtOutput, type QuoteFilter, QuoteFilters, STATUS, type SVMTxnDetails, Services, type SignPermitResponse, type SignatureCallbackParams, SignatureExpiryInSecs, type SinglePermitCallbackParams, StatusCodes, type StepAction, type SvmTxData, type SwapInfo, SwapInputDataDecoder, type Token, type TokenInfo, type TokenPermitData, type TokenResponse, type TradeBuildTxnRequest, type TradeBuildTxnRequestData, type TradeBuildTxnResponse, type TradeGasBuildTxnResponse, type TradePath, type TradeQuotesRequest, type TradeQuotesRequestData, type TradeQuotesResponse, type TradeStatusResponse, type TradeStep, TxnStatus, type ZapBuildTxnRequest, type ZapBuildTxnResponse, type ZapBundleAction, type ZapBundleRequest, type ZapBundleSrcToken, type ZapBvmTxnDetails, type ZapChains, type ZapEvmTxnDetails, type ZapFee, type ZapIntegratorConfig, type ZapPath, type ZapPathAction, type ZapPathAsset, type ZapPool, type ZapPoolDetails, type ZapPoolDetailsRequest, type ZapPoolsRequest, type ZapPoolsResponse, type ZapPosition, type ZapPositionsRequest, type ZapPositionsResponse, type ZapProviders, type ZapQuoteRequest, type ZapQuoteResponse, type ZapRouteRequestPoolDetails, type ZapRouteRequestPositionDetails, type ZapStatus, type ZapStatusAsset, type ZapStatusRequest, type ZapStatusResponse, type ZapStatusStep, type ZapStep, type ZapTransactionStep, type ZapTxnDetails, type ZapUnderlyingToken, type ZapUnderlyingTokenWithAmount, checkEIP2612PermitSupport, contractErrorActions, erc20Functions, formatToken, getTokensPairKey, zapPathAction, zapStepAction };
|
|
1963
|
+
export { type AllowanceType, AllowanceTypes, type ApiRpcResponse, type ApprovalMode, ApprovalModes, type BatchPermitCallbackParams, type BtcTxData, type Chain, type ChainData, type ContractErrorResponse, DZapClient, DZapPermitMode, type DZapTransactionResponse, type EvmTxData, type Fee, type FeeDetails, type GaslessTradeBuildTxnResponse, type HexString, OtherAbis, type ParamQuotes, type PermitMode, PermitTypes, type ProviderDetails, type PsbtInput, type PsbtOutput, type QuoteFilter, QuoteFilters, STATUS, type SVMTxnDetails, Services, type SignPermitResponse, type SignatureCallbackParams, SignatureExpiryInSecs, type SinglePermitCallbackParams, StatusCodes, type StepAction, type SvmTxData, type SwapInfo, SwapInputDataDecoder, type Token, type TokenInfo, type TokenPermitData, type TokenResponse, type TradeBuildTxnRequest, type TradeBuildTxnRequestData, type TradeBuildTxnResponse, type TradeGasBuildTxnResponse, type TradePath, type TradeQuotesRequest, type TradeQuotesRequestData, type TradeQuotesResponse, type TradeStatusResponse, type TradeStep, TxnStatus, type ZapBuildTxnRequest, type ZapBuildTxnResponse, type ZapBundleAction, type ZapBundleRequest, type ZapBundleSrcToken, type ZapBvmTxnDetails, type ZapChains, type ZapEvmTxnDetails, type ZapFee, type ZapIntegratorConfig, type ZapPath, type ZapPathAction, type ZapPathAsset, type ZapPool, type ZapPoolDetails, type ZapPoolDetailsRequest, type ZapPoolsRequest, type ZapPoolsResponse, type ZapPosition, type ZapPositionsRequest, type ZapPositionsResponse, type ZapProviders, type ZapQuoteRequest, type ZapQuoteResponse, type ZapRouteRequestPoolDetails, type ZapRouteRequestPositionDetails, type ZapStatus, type ZapStatusAsset, type ZapStatusRequest, type ZapStatusResponse, type ZapStatusStep, type ZapStep, type ZapTransactionStep, type ZapTxnDetails, type ZapUnderlyingToken, type ZapUnderlyingTokenWithAmount, checkEIP2612PermitSupport, contractErrorActions, erc20Functions, formatToken, getTokensPairKey, zapPathAction, zapStepAction };
|
package/dist/index.js
CHANGED
|
@@ -12845,6 +12845,7 @@ var exclusiveChainIds = {
|
|
|
12845
12845
|
lens: 232,
|
|
12846
12846
|
citreaTestnet: 5115,
|
|
12847
12847
|
hyperLiquid: 998,
|
|
12848
|
+
citrea: 4114,
|
|
12848
12849
|
pushTestnet: 42101,
|
|
12849
12850
|
astralisTestnet: 71261
|
|
12850
12851
|
};
|
|
@@ -12855,6 +12856,7 @@ var exclusivePermit2Addresses = {
|
|
|
12855
12856
|
[exclusiveChainIds.arthera]: "0x5Aeec43fF96b9B6c5a1dC1DAdA662ACE3c236C49",
|
|
12856
12857
|
[exclusiveChainIds.bounceBit]: "0x08208a5f56696E7AA3eAF7a307fa63B37bd8e8A5",
|
|
12857
12858
|
[exclusiveChainIds.citreaTestnet]: "0x08208a5f56696E7AA3eAF7a307fa63B37bd8e8A5",
|
|
12859
|
+
[exclusiveChainIds.citrea]: "0x08208a5f56696E7AA3eAF7a307fa63B37bd8e8A5",
|
|
12858
12860
|
[exclusiveChainIds.biFrost]: "0x08208a5f56696E7AA3eAF7a307fa63B37bd8e8A5",
|
|
12859
12861
|
[exclusiveChainIds.flare]: "0x08208a5f56696E7AA3eAF7a307fa63B37bd8e8A5",
|
|
12860
12862
|
[exclusiveChainIds.iotaEvm]: "0x08208a5f56696E7AA3eAF7a307fa63B37bd8e8A5",
|
|
@@ -12919,6 +12921,11 @@ var BatchPermitAbiParams = [
|
|
|
12919
12921
|
},
|
|
12920
12922
|
{ name: "permitSignature", type: "bytes" }
|
|
12921
12923
|
];
|
|
12924
|
+
var AllowanceTypes = {
|
|
12925
|
+
eip2612: "eip2612",
|
|
12926
|
+
permit2: "permit2",
|
|
12927
|
+
dzap: "dzap"
|
|
12928
|
+
};
|
|
12922
12929
|
|
|
12923
12930
|
// src/utils/permit2/domain.ts
|
|
12924
12931
|
var PERMIT2_DOMAIN_NAME = "Permit2";
|
|
@@ -14536,7 +14543,7 @@ var getAllowance = async ({ chainId, sender, tokens, rpcUrls, multicallAddress,
|
|
|
14536
14543
|
const nativeTokens2 = tokens.filter(({ address }) => isDZapNativeToken(address));
|
|
14537
14544
|
const erc20Tokens = tokens.filter(({ address }) => !isDZapNativeToken(address));
|
|
14538
14545
|
const approvalData = await Promise.all(
|
|
14539
|
-
erc20Tokens.map(async ({ address,
|
|
14546
|
+
erc20Tokens.map(async ({ address, permit }) => {
|
|
14540
14547
|
if (mode === ApprovalModes.AutoPermit) {
|
|
14541
14548
|
const eip2612PermitData = await checkEIP2612PermitSupport({
|
|
14542
14549
|
address,
|
|
@@ -14545,30 +14552,26 @@ var getAllowance = async ({ chainId, sender, tokens, rpcUrls, multicallAddress,
|
|
|
14545
14552
|
owner: sender,
|
|
14546
14553
|
permit
|
|
14547
14554
|
});
|
|
14555
|
+
const allowanceType = eip2612PermitData.supportsPermit ? AllowanceTypes.eip2612 : AllowanceTypes.permit2;
|
|
14548
14556
|
return {
|
|
14549
14557
|
token: address,
|
|
14550
14558
|
spender: eip2612PermitData.supportsPermit ? spender : getPermit2Address(chainId),
|
|
14551
|
-
|
|
14552
|
-
amount,
|
|
14553
|
-
isEIP2612PermitSupported: eip2612PermitData.supportsPermit,
|
|
14554
|
-
isDefaultApprovalMode: false
|
|
14559
|
+
allowanceType
|
|
14555
14560
|
};
|
|
14556
14561
|
} else if (mode === ApprovalModes.Default) {
|
|
14557
14562
|
return {
|
|
14558
14563
|
token: address,
|
|
14559
14564
|
spender,
|
|
14560
|
-
|
|
14561
|
-
isEIP2612PermitSupported: false,
|
|
14562
|
-
isDefaultApprovalMode: true
|
|
14565
|
+
allowanceType: AllowanceTypes.dzap
|
|
14563
14566
|
};
|
|
14564
14567
|
} else {
|
|
14565
14568
|
const permit2Address = getPermit2Address(chainId);
|
|
14566
|
-
return { token: address, spender: permit2Address,
|
|
14569
|
+
return { token: address, spender: permit2Address, allowanceType: AllowanceTypes.permit2 };
|
|
14567
14570
|
}
|
|
14568
14571
|
})
|
|
14569
14572
|
);
|
|
14570
14573
|
for (const { address } of nativeTokens2) {
|
|
14571
|
-
data[address] = { allowance: viem.maxUint256,
|
|
14574
|
+
data[address] = { allowance: viem.maxUint256, type: AllowanceTypes.dzap };
|
|
14572
14575
|
}
|
|
14573
14576
|
if (erc20Tokens.length === 0) {
|
|
14574
14577
|
return { status: "success" /* success */, code: 200 /* Success */, data };
|
|
@@ -14582,11 +14585,9 @@ var getAllowance = async ({ chainId, sender, tokens, rpcUrls, multicallAddress,
|
|
|
14582
14585
|
rpcUrls
|
|
14583
14586
|
});
|
|
14584
14587
|
for (let i = 0; i < approvalData.length; i++) {
|
|
14585
|
-
const { token,
|
|
14586
|
-
const allowance =
|
|
14587
|
-
|
|
14588
|
-
const signatureNeeded = isDefaultApprovalMode ? false : true;
|
|
14589
|
-
data[token] = { allowance, approvalNeeded, signatureNeeded };
|
|
14588
|
+
const { token, allowanceType } = approvalData[i];
|
|
14589
|
+
const allowance = allowanceType === AllowanceTypes.eip2612 ? viem.maxUint256 : allowances[token];
|
|
14590
|
+
data[token] = { allowance, type: allowanceType };
|
|
14590
14591
|
}
|
|
14591
14592
|
return { status: "success" /* success */, code: 200 /* Success */, data };
|
|
14592
14593
|
} catch (error) {
|
|
@@ -14637,8 +14638,9 @@ async function generateApprovalBatchCalls({
|
|
|
14637
14638
|
rpcUrls
|
|
14638
14639
|
});
|
|
14639
14640
|
const tokensNeedingApproval = tokensToCheck.filter((token) => {
|
|
14640
|
-
|
|
14641
|
-
|
|
14641
|
+
const { allowance, type } = allowanceData[token.address] ?? {};
|
|
14642
|
+
if (type === AllowanceTypes.eip2612) return false;
|
|
14643
|
+
return allowance === void 0 || allowance < BigInt(token.amount);
|
|
14642
14644
|
});
|
|
14643
14645
|
return tokensNeedingApproval.map((token) => ({
|
|
14644
14646
|
to: token.address,
|
|
@@ -15848,17 +15850,8 @@ var _DZapClient = class _DZapClient {
|
|
|
15848
15850
|
*
|
|
15849
15851
|
* @example
|
|
15850
15852
|
* ```typescript
|
|
15851
|
-
* const
|
|
15852
|
-
*
|
|
15853
|
-
* sender: '0x...',
|
|
15854
|
-
* tokens: [
|
|
15855
|
-
* { address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', amount: '1000000' }
|
|
15856
|
-
* ],
|
|
15857
|
-
* service: 'swap',
|
|
15858
|
-
* mode: ApprovalModes.Permit2
|
|
15859
|
-
* });
|
|
15860
|
-
*
|
|
15861
|
-
* console.log('Approvals needed:', allowanceInfo.data.noOfApprovalsRequired);
|
|
15853
|
+
* const { status, data } = await client.getAllowance({ chainId, sender, tokens, service });
|
|
15854
|
+
* const { allowance, type } = data[token]!;
|
|
15862
15855
|
* ```
|
|
15863
15856
|
*/
|
|
15864
15857
|
async getAllowance({
|
|
@@ -16391,6 +16384,7 @@ var zapPathAction = {
|
|
|
16391
16384
|
harvest: "harvest"
|
|
16392
16385
|
};
|
|
16393
16386
|
|
|
16387
|
+
exports.AllowanceTypes = AllowanceTypes;
|
|
16394
16388
|
exports.ApprovalModes = ApprovalModes;
|
|
16395
16389
|
exports.DZapClient = dZapClient_default;
|
|
16396
16390
|
exports.DZapPermitMode = DZapPermitMode;
|
package/dist/index.mjs
CHANGED
|
@@ -12820,6 +12820,7 @@ var exclusiveChainIds = {
|
|
|
12820
12820
|
lens: 232,
|
|
12821
12821
|
citreaTestnet: 5115,
|
|
12822
12822
|
hyperLiquid: 998,
|
|
12823
|
+
citrea: 4114,
|
|
12823
12824
|
pushTestnet: 42101,
|
|
12824
12825
|
astralisTestnet: 71261
|
|
12825
12826
|
};
|
|
@@ -12830,6 +12831,7 @@ var exclusivePermit2Addresses = {
|
|
|
12830
12831
|
[exclusiveChainIds.arthera]: "0x5Aeec43fF96b9B6c5a1dC1DAdA662ACE3c236C49",
|
|
12831
12832
|
[exclusiveChainIds.bounceBit]: "0x08208a5f56696E7AA3eAF7a307fa63B37bd8e8A5",
|
|
12832
12833
|
[exclusiveChainIds.citreaTestnet]: "0x08208a5f56696E7AA3eAF7a307fa63B37bd8e8A5",
|
|
12834
|
+
[exclusiveChainIds.citrea]: "0x08208a5f56696E7AA3eAF7a307fa63B37bd8e8A5",
|
|
12833
12835
|
[exclusiveChainIds.biFrost]: "0x08208a5f56696E7AA3eAF7a307fa63B37bd8e8A5",
|
|
12834
12836
|
[exclusiveChainIds.flare]: "0x08208a5f56696E7AA3eAF7a307fa63B37bd8e8A5",
|
|
12835
12837
|
[exclusiveChainIds.iotaEvm]: "0x08208a5f56696E7AA3eAF7a307fa63B37bd8e8A5",
|
|
@@ -12894,6 +12896,11 @@ var BatchPermitAbiParams = [
|
|
|
12894
12896
|
},
|
|
12895
12897
|
{ name: "permitSignature", type: "bytes" }
|
|
12896
12898
|
];
|
|
12899
|
+
var AllowanceTypes = {
|
|
12900
|
+
eip2612: "eip2612",
|
|
12901
|
+
permit2: "permit2",
|
|
12902
|
+
dzap: "dzap"
|
|
12903
|
+
};
|
|
12897
12904
|
|
|
12898
12905
|
// src/utils/permit2/domain.ts
|
|
12899
12906
|
var PERMIT2_DOMAIN_NAME = "Permit2";
|
|
@@ -14511,7 +14518,7 @@ var getAllowance = async ({ chainId, sender, tokens, rpcUrls, multicallAddress,
|
|
|
14511
14518
|
const nativeTokens2 = tokens.filter(({ address }) => isDZapNativeToken(address));
|
|
14512
14519
|
const erc20Tokens = tokens.filter(({ address }) => !isDZapNativeToken(address));
|
|
14513
14520
|
const approvalData = await Promise.all(
|
|
14514
|
-
erc20Tokens.map(async ({ address,
|
|
14521
|
+
erc20Tokens.map(async ({ address, permit }) => {
|
|
14515
14522
|
if (mode === ApprovalModes.AutoPermit) {
|
|
14516
14523
|
const eip2612PermitData = await checkEIP2612PermitSupport({
|
|
14517
14524
|
address,
|
|
@@ -14520,30 +14527,26 @@ var getAllowance = async ({ chainId, sender, tokens, rpcUrls, multicallAddress,
|
|
|
14520
14527
|
owner: sender,
|
|
14521
14528
|
permit
|
|
14522
14529
|
});
|
|
14530
|
+
const allowanceType = eip2612PermitData.supportsPermit ? AllowanceTypes.eip2612 : AllowanceTypes.permit2;
|
|
14523
14531
|
return {
|
|
14524
14532
|
token: address,
|
|
14525
14533
|
spender: eip2612PermitData.supportsPermit ? spender : getPermit2Address(chainId),
|
|
14526
|
-
|
|
14527
|
-
amount,
|
|
14528
|
-
isEIP2612PermitSupported: eip2612PermitData.supportsPermit,
|
|
14529
|
-
isDefaultApprovalMode: false
|
|
14534
|
+
allowanceType
|
|
14530
14535
|
};
|
|
14531
14536
|
} else if (mode === ApprovalModes.Default) {
|
|
14532
14537
|
return {
|
|
14533
14538
|
token: address,
|
|
14534
14539
|
spender,
|
|
14535
|
-
|
|
14536
|
-
isEIP2612PermitSupported: false,
|
|
14537
|
-
isDefaultApprovalMode: true
|
|
14540
|
+
allowanceType: AllowanceTypes.dzap
|
|
14538
14541
|
};
|
|
14539
14542
|
} else {
|
|
14540
14543
|
const permit2Address = getPermit2Address(chainId);
|
|
14541
|
-
return { token: address, spender: permit2Address,
|
|
14544
|
+
return { token: address, spender: permit2Address, allowanceType: AllowanceTypes.permit2 };
|
|
14542
14545
|
}
|
|
14543
14546
|
})
|
|
14544
14547
|
);
|
|
14545
14548
|
for (const { address } of nativeTokens2) {
|
|
14546
|
-
data[address] = { allowance: maxUint256,
|
|
14549
|
+
data[address] = { allowance: maxUint256, type: AllowanceTypes.dzap };
|
|
14547
14550
|
}
|
|
14548
14551
|
if (erc20Tokens.length === 0) {
|
|
14549
14552
|
return { status: "success" /* success */, code: 200 /* Success */, data };
|
|
@@ -14557,11 +14560,9 @@ var getAllowance = async ({ chainId, sender, tokens, rpcUrls, multicallAddress,
|
|
|
14557
14560
|
rpcUrls
|
|
14558
14561
|
});
|
|
14559
14562
|
for (let i = 0; i < approvalData.length; i++) {
|
|
14560
|
-
const { token,
|
|
14561
|
-
const allowance =
|
|
14562
|
-
|
|
14563
|
-
const signatureNeeded = isDefaultApprovalMode ? false : true;
|
|
14564
|
-
data[token] = { allowance, approvalNeeded, signatureNeeded };
|
|
14563
|
+
const { token, allowanceType } = approvalData[i];
|
|
14564
|
+
const allowance = allowanceType === AllowanceTypes.eip2612 ? maxUint256 : allowances[token];
|
|
14565
|
+
data[token] = { allowance, type: allowanceType };
|
|
14565
14566
|
}
|
|
14566
14567
|
return { status: "success" /* success */, code: 200 /* Success */, data };
|
|
14567
14568
|
} catch (error) {
|
|
@@ -14612,8 +14613,9 @@ async function generateApprovalBatchCalls({
|
|
|
14612
14613
|
rpcUrls
|
|
14613
14614
|
});
|
|
14614
14615
|
const tokensNeedingApproval = tokensToCheck.filter((token) => {
|
|
14615
|
-
|
|
14616
|
-
|
|
14616
|
+
const { allowance, type } = allowanceData[token.address] ?? {};
|
|
14617
|
+
if (type === AllowanceTypes.eip2612) return false;
|
|
14618
|
+
return allowance === void 0 || allowance < BigInt(token.amount);
|
|
14617
14619
|
});
|
|
14618
14620
|
return tokensNeedingApproval.map((token) => ({
|
|
14619
14621
|
to: token.address,
|
|
@@ -15823,17 +15825,8 @@ var _DZapClient = class _DZapClient {
|
|
|
15823
15825
|
*
|
|
15824
15826
|
* @example
|
|
15825
15827
|
* ```typescript
|
|
15826
|
-
* const
|
|
15827
|
-
*
|
|
15828
|
-
* sender: '0x...',
|
|
15829
|
-
* tokens: [
|
|
15830
|
-
* { address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', amount: '1000000' }
|
|
15831
|
-
* ],
|
|
15832
|
-
* service: 'swap',
|
|
15833
|
-
* mode: ApprovalModes.Permit2
|
|
15834
|
-
* });
|
|
15835
|
-
*
|
|
15836
|
-
* console.log('Approvals needed:', allowanceInfo.data.noOfApprovalsRequired);
|
|
15828
|
+
* const { status, data } = await client.getAllowance({ chainId, sender, tokens, service });
|
|
15829
|
+
* const { allowance, type } = data[token]!;
|
|
15837
15830
|
* ```
|
|
15838
15831
|
*/
|
|
15839
15832
|
async getAllowance({
|
|
@@ -16366,4 +16359,4 @@ var zapPathAction = {
|
|
|
16366
16359
|
harvest: "harvest"
|
|
16367
16360
|
};
|
|
16368
16361
|
|
|
16369
|
-
export { ApprovalModes, dZapClient_default as DZapClient, DZapPermitMode, OtherAbis, PermitTypes, QuoteFilters, STATUS, Services, SignatureExpiryInSecs, StatusCodes, SwapInputDataDecoder, TxnStatus, checkEIP2612PermitSupport, contractErrorActions, erc20Functions, formatToken, getTokensPairKey, zapPathAction, zapStepAction };
|
|
16362
|
+
export { AllowanceTypes, ApprovalModes, dZapClient_default as DZapClient, DZapPermitMode, OtherAbis, PermitTypes, QuoteFilters, STATUS, Services, SignatureExpiryInSecs, StatusCodes, SwapInputDataDecoder, TxnStatus, checkEIP2612PermitSupport, contractErrorActions, erc20Functions, formatToken, getTokensPairKey, zapPathAction, zapStepAction };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dzapio/sdk",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.28",
|
|
4
4
|
"description": "A TypeScript/JavaScript SDK for interacting with the DZap protocol, providing utilities for DeFi operations including Swaps, Bridges, and Zaps.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"source": "src/index.ts",
|