@dzapio/sdk 2.0.25 → 2.0.27
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 +16 -5
- package/dist/index.d.ts +16 -5
- package/dist/index.js +20 -28
- package/dist/index.mjs +20 -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 = {
|
|
@@ -708,12 +715,17 @@ type ZapIntegratorConfig = {
|
|
|
708
715
|
wallet: string;
|
|
709
716
|
};
|
|
710
717
|
type ZapBuildTxnResponse = {
|
|
711
|
-
amountOut: string;
|
|
712
718
|
approvalData: {
|
|
713
719
|
callTo: HexString;
|
|
714
720
|
approveTo: HexString;
|
|
715
721
|
amount: string;
|
|
716
|
-
}
|
|
722
|
+
}[];
|
|
723
|
+
output: {
|
|
724
|
+
address: string;
|
|
725
|
+
amount: string;
|
|
726
|
+
chainId: number;
|
|
727
|
+
minAmount: string;
|
|
728
|
+
}[];
|
|
717
729
|
steps: ZapStep[];
|
|
718
730
|
path: ZapPath[];
|
|
719
731
|
};
|
|
@@ -1845,8 +1857,7 @@ declare class DZapClient {
|
|
|
1845
1857
|
data: {
|
|
1846
1858
|
[key: string]: {
|
|
1847
1859
|
allowance: bigint;
|
|
1848
|
-
|
|
1849
|
-
signatureNeeded: boolean;
|
|
1860
|
+
type: AllowanceType;
|
|
1850
1861
|
};
|
|
1851
1862
|
};
|
|
1852
1863
|
}>;
|
|
@@ -1949,4 +1960,4 @@ declare const checkEIP2612PermitSupport: ({ address, chainId, rpcUrls, owner, pe
|
|
|
1949
1960
|
|
|
1950
1961
|
declare const formatToken: <T extends HexString | string = string>(token: T, nativeTokenAddress?: T) => T;
|
|
1951
1962
|
|
|
1952
|
-
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 = {
|
|
@@ -708,12 +715,17 @@ type ZapIntegratorConfig = {
|
|
|
708
715
|
wallet: string;
|
|
709
716
|
};
|
|
710
717
|
type ZapBuildTxnResponse = {
|
|
711
|
-
amountOut: string;
|
|
712
718
|
approvalData: {
|
|
713
719
|
callTo: HexString;
|
|
714
720
|
approveTo: HexString;
|
|
715
721
|
amount: string;
|
|
716
|
-
}
|
|
722
|
+
}[];
|
|
723
|
+
output: {
|
|
724
|
+
address: string;
|
|
725
|
+
amount: string;
|
|
726
|
+
chainId: number;
|
|
727
|
+
minAmount: string;
|
|
728
|
+
}[];
|
|
717
729
|
steps: ZapStep[];
|
|
718
730
|
path: ZapPath[];
|
|
719
731
|
};
|
|
@@ -1845,8 +1857,7 @@ declare class DZapClient {
|
|
|
1845
1857
|
data: {
|
|
1846
1858
|
[key: string]: {
|
|
1847
1859
|
allowance: bigint;
|
|
1848
|
-
|
|
1849
|
-
signatureNeeded: boolean;
|
|
1860
|
+
type: AllowanceType;
|
|
1850
1861
|
};
|
|
1851
1862
|
};
|
|
1852
1863
|
}>;
|
|
@@ -1949,4 +1960,4 @@ declare const checkEIP2612PermitSupport: ({ address, chainId, rpcUrls, owner, pe
|
|
|
1949
1960
|
|
|
1950
1961
|
declare const formatToken: <T extends HexString | string = string>(token: T, nativeTokenAddress?: T) => T;
|
|
1951
1962
|
|
|
1952
|
-
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
|
@@ -12919,6 +12919,11 @@ var BatchPermitAbiParams = [
|
|
|
12919
12919
|
},
|
|
12920
12920
|
{ name: "permitSignature", type: "bytes" }
|
|
12921
12921
|
];
|
|
12922
|
+
var AllowanceTypes = {
|
|
12923
|
+
eip2612: "eip2612",
|
|
12924
|
+
permit2: "permit2",
|
|
12925
|
+
dzap: "dzap"
|
|
12926
|
+
};
|
|
12922
12927
|
|
|
12923
12928
|
// src/utils/permit2/domain.ts
|
|
12924
12929
|
var PERMIT2_DOMAIN_NAME = "Permit2";
|
|
@@ -14536,7 +14541,7 @@ var getAllowance = async ({ chainId, sender, tokens, rpcUrls, multicallAddress,
|
|
|
14536
14541
|
const nativeTokens2 = tokens.filter(({ address }) => isDZapNativeToken(address));
|
|
14537
14542
|
const erc20Tokens = tokens.filter(({ address }) => !isDZapNativeToken(address));
|
|
14538
14543
|
const approvalData = await Promise.all(
|
|
14539
|
-
erc20Tokens.map(async ({ address,
|
|
14544
|
+
erc20Tokens.map(async ({ address, permit }) => {
|
|
14540
14545
|
if (mode === ApprovalModes.AutoPermit) {
|
|
14541
14546
|
const eip2612PermitData = await checkEIP2612PermitSupport({
|
|
14542
14547
|
address,
|
|
@@ -14545,30 +14550,26 @@ var getAllowance = async ({ chainId, sender, tokens, rpcUrls, multicallAddress,
|
|
|
14545
14550
|
owner: sender,
|
|
14546
14551
|
permit
|
|
14547
14552
|
});
|
|
14553
|
+
const allowanceType = eip2612PermitData.supportsPermit ? AllowanceTypes.eip2612 : AllowanceTypes.permit2;
|
|
14548
14554
|
return {
|
|
14549
14555
|
token: address,
|
|
14550
14556
|
spender: eip2612PermitData.supportsPermit ? spender : getPermit2Address(chainId),
|
|
14551
|
-
|
|
14552
|
-
amount,
|
|
14553
|
-
isEIP2612PermitSupported: eip2612PermitData.supportsPermit,
|
|
14554
|
-
isDefaultApprovalMode: false
|
|
14557
|
+
allowanceType
|
|
14555
14558
|
};
|
|
14556
14559
|
} else if (mode === ApprovalModes.Default) {
|
|
14557
14560
|
return {
|
|
14558
14561
|
token: address,
|
|
14559
14562
|
spender,
|
|
14560
|
-
|
|
14561
|
-
isEIP2612PermitSupported: false,
|
|
14562
|
-
isDefaultApprovalMode: true
|
|
14563
|
+
allowanceType: AllowanceTypes.dzap
|
|
14563
14564
|
};
|
|
14564
14565
|
} else {
|
|
14565
14566
|
const permit2Address = getPermit2Address(chainId);
|
|
14566
|
-
return { token: address, spender: permit2Address,
|
|
14567
|
+
return { token: address, spender: permit2Address, allowanceType: AllowanceTypes.permit2 };
|
|
14567
14568
|
}
|
|
14568
14569
|
})
|
|
14569
14570
|
);
|
|
14570
14571
|
for (const { address } of nativeTokens2) {
|
|
14571
|
-
data[address] = { allowance: viem.maxUint256,
|
|
14572
|
+
data[address] = { allowance: viem.maxUint256, type: AllowanceTypes.dzap };
|
|
14572
14573
|
}
|
|
14573
14574
|
if (erc20Tokens.length === 0) {
|
|
14574
14575
|
return { status: "success" /* success */, code: 200 /* Success */, data };
|
|
@@ -14582,11 +14583,9 @@ var getAllowance = async ({ chainId, sender, tokens, rpcUrls, multicallAddress,
|
|
|
14582
14583
|
rpcUrls
|
|
14583
14584
|
});
|
|
14584
14585
|
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 };
|
|
14586
|
+
const { token, allowanceType } = approvalData[i];
|
|
14587
|
+
const allowance = allowanceType === AllowanceTypes.eip2612 ? viem.maxUint256 : allowances[token];
|
|
14588
|
+
data[token] = { allowance, type: allowanceType };
|
|
14590
14589
|
}
|
|
14591
14590
|
return { status: "success" /* success */, code: 200 /* Success */, data };
|
|
14592
14591
|
} catch (error) {
|
|
@@ -14637,8 +14636,9 @@ async function generateApprovalBatchCalls({
|
|
|
14637
14636
|
rpcUrls
|
|
14638
14637
|
});
|
|
14639
14638
|
const tokensNeedingApproval = tokensToCheck.filter((token) => {
|
|
14640
|
-
|
|
14641
|
-
|
|
14639
|
+
const { allowance, type } = allowanceData[token.address] ?? {};
|
|
14640
|
+
if (type === AllowanceTypes.eip2612) return false;
|
|
14641
|
+
return allowance === void 0 || allowance < BigInt(token.amount);
|
|
14642
14642
|
});
|
|
14643
14643
|
return tokensNeedingApproval.map((token) => ({
|
|
14644
14644
|
to: token.address,
|
|
@@ -15848,17 +15848,8 @@ var _DZapClient = class _DZapClient {
|
|
|
15848
15848
|
*
|
|
15849
15849
|
* @example
|
|
15850
15850
|
* ```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);
|
|
15851
|
+
* const { status, data } = await client.getAllowance({ chainId, sender, tokens, service });
|
|
15852
|
+
* const { allowance, type } = data[token]!;
|
|
15862
15853
|
* ```
|
|
15863
15854
|
*/
|
|
15864
15855
|
async getAllowance({
|
|
@@ -16391,6 +16382,7 @@ var zapPathAction = {
|
|
|
16391
16382
|
harvest: "harvest"
|
|
16392
16383
|
};
|
|
16393
16384
|
|
|
16385
|
+
exports.AllowanceTypes = AllowanceTypes;
|
|
16394
16386
|
exports.ApprovalModes = ApprovalModes;
|
|
16395
16387
|
exports.DZapClient = dZapClient_default;
|
|
16396
16388
|
exports.DZapPermitMode = DZapPermitMode;
|
package/dist/index.mjs
CHANGED
|
@@ -12894,6 +12894,11 @@ var BatchPermitAbiParams = [
|
|
|
12894
12894
|
},
|
|
12895
12895
|
{ name: "permitSignature", type: "bytes" }
|
|
12896
12896
|
];
|
|
12897
|
+
var AllowanceTypes = {
|
|
12898
|
+
eip2612: "eip2612",
|
|
12899
|
+
permit2: "permit2",
|
|
12900
|
+
dzap: "dzap"
|
|
12901
|
+
};
|
|
12897
12902
|
|
|
12898
12903
|
// src/utils/permit2/domain.ts
|
|
12899
12904
|
var PERMIT2_DOMAIN_NAME = "Permit2";
|
|
@@ -14511,7 +14516,7 @@ var getAllowance = async ({ chainId, sender, tokens, rpcUrls, multicallAddress,
|
|
|
14511
14516
|
const nativeTokens2 = tokens.filter(({ address }) => isDZapNativeToken(address));
|
|
14512
14517
|
const erc20Tokens = tokens.filter(({ address }) => !isDZapNativeToken(address));
|
|
14513
14518
|
const approvalData = await Promise.all(
|
|
14514
|
-
erc20Tokens.map(async ({ address,
|
|
14519
|
+
erc20Tokens.map(async ({ address, permit }) => {
|
|
14515
14520
|
if (mode === ApprovalModes.AutoPermit) {
|
|
14516
14521
|
const eip2612PermitData = await checkEIP2612PermitSupport({
|
|
14517
14522
|
address,
|
|
@@ -14520,30 +14525,26 @@ var getAllowance = async ({ chainId, sender, tokens, rpcUrls, multicallAddress,
|
|
|
14520
14525
|
owner: sender,
|
|
14521
14526
|
permit
|
|
14522
14527
|
});
|
|
14528
|
+
const allowanceType = eip2612PermitData.supportsPermit ? AllowanceTypes.eip2612 : AllowanceTypes.permit2;
|
|
14523
14529
|
return {
|
|
14524
14530
|
token: address,
|
|
14525
14531
|
spender: eip2612PermitData.supportsPermit ? spender : getPermit2Address(chainId),
|
|
14526
|
-
|
|
14527
|
-
amount,
|
|
14528
|
-
isEIP2612PermitSupported: eip2612PermitData.supportsPermit,
|
|
14529
|
-
isDefaultApprovalMode: false
|
|
14532
|
+
allowanceType
|
|
14530
14533
|
};
|
|
14531
14534
|
} else if (mode === ApprovalModes.Default) {
|
|
14532
14535
|
return {
|
|
14533
14536
|
token: address,
|
|
14534
14537
|
spender,
|
|
14535
|
-
|
|
14536
|
-
isEIP2612PermitSupported: false,
|
|
14537
|
-
isDefaultApprovalMode: true
|
|
14538
|
+
allowanceType: AllowanceTypes.dzap
|
|
14538
14539
|
};
|
|
14539
14540
|
} else {
|
|
14540
14541
|
const permit2Address = getPermit2Address(chainId);
|
|
14541
|
-
return { token: address, spender: permit2Address,
|
|
14542
|
+
return { token: address, spender: permit2Address, allowanceType: AllowanceTypes.permit2 };
|
|
14542
14543
|
}
|
|
14543
14544
|
})
|
|
14544
14545
|
);
|
|
14545
14546
|
for (const { address } of nativeTokens2) {
|
|
14546
|
-
data[address] = { allowance: maxUint256,
|
|
14547
|
+
data[address] = { allowance: maxUint256, type: AllowanceTypes.dzap };
|
|
14547
14548
|
}
|
|
14548
14549
|
if (erc20Tokens.length === 0) {
|
|
14549
14550
|
return { status: "success" /* success */, code: 200 /* Success */, data };
|
|
@@ -14557,11 +14558,9 @@ var getAllowance = async ({ chainId, sender, tokens, rpcUrls, multicallAddress,
|
|
|
14557
14558
|
rpcUrls
|
|
14558
14559
|
});
|
|
14559
14560
|
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 };
|
|
14561
|
+
const { token, allowanceType } = approvalData[i];
|
|
14562
|
+
const allowance = allowanceType === AllowanceTypes.eip2612 ? maxUint256 : allowances[token];
|
|
14563
|
+
data[token] = { allowance, type: allowanceType };
|
|
14565
14564
|
}
|
|
14566
14565
|
return { status: "success" /* success */, code: 200 /* Success */, data };
|
|
14567
14566
|
} catch (error) {
|
|
@@ -14612,8 +14611,9 @@ async function generateApprovalBatchCalls({
|
|
|
14612
14611
|
rpcUrls
|
|
14613
14612
|
});
|
|
14614
14613
|
const tokensNeedingApproval = tokensToCheck.filter((token) => {
|
|
14615
|
-
|
|
14616
|
-
|
|
14614
|
+
const { allowance, type } = allowanceData[token.address] ?? {};
|
|
14615
|
+
if (type === AllowanceTypes.eip2612) return false;
|
|
14616
|
+
return allowance === void 0 || allowance < BigInt(token.amount);
|
|
14617
14617
|
});
|
|
14618
14618
|
return tokensNeedingApproval.map((token) => ({
|
|
14619
14619
|
to: token.address,
|
|
@@ -15823,17 +15823,8 @@ var _DZapClient = class _DZapClient {
|
|
|
15823
15823
|
*
|
|
15824
15824
|
* @example
|
|
15825
15825
|
* ```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);
|
|
15826
|
+
* const { status, data } = await client.getAllowance({ chainId, sender, tokens, service });
|
|
15827
|
+
* const { allowance, type } = data[token]!;
|
|
15837
15828
|
* ```
|
|
15838
15829
|
*/
|
|
15839
15830
|
async getAllowance({
|
|
@@ -16366,4 +16357,4 @@ var zapPathAction = {
|
|
|
16366
16357
|
harvest: "harvest"
|
|
16367
16358
|
};
|
|
16368
16359
|
|
|
16369
|
-
export { ApprovalModes, dZapClient_default as DZapClient, DZapPermitMode, OtherAbis, PermitTypes, QuoteFilters, STATUS, Services, SignatureExpiryInSecs, StatusCodes, SwapInputDataDecoder, TxnStatus, checkEIP2612PermitSupport, contractErrorActions, erc20Functions, formatToken, getTokensPairKey, zapPathAction, zapStepAction };
|
|
16360
|
+
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.27",
|
|
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",
|