@paxoslabs/amplify-sdk 0.1.1-beta.1 → 0.2.0-alpha.0
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 +42 -0
- package/dist/{chunk-DTFLXAZJ.js → chunk-4NQCOMCZ.js} +147 -5
- package/dist/chunk-4NQCOMCZ.js.map +1 -0
- package/dist/{chunk-KYR6BFAE.js → chunk-5VOI4WPL.js} +38 -33
- package/dist/chunk-5VOI4WPL.js.map +1 -0
- package/dist/{chunk-ZILA73XN.mjs → chunk-5Y7M43XN.mjs} +144 -4
- package/dist/chunk-5Y7M43XN.mjs.map +1 -0
- package/dist/{chunk-VIULRHK6.mjs → chunk-7PCUTZF6.mjs} +3 -3
- package/dist/{chunk-VIULRHK6.mjs.map → chunk-7PCUTZF6.mjs.map} +1 -1
- package/dist/{chunk-XXHRCCZS.mjs → chunk-AQFFMJX7.mjs} +3 -3
- package/dist/chunk-AQFFMJX7.mjs.map +1 -0
- package/dist/{chunk-REKEQLQA.mjs → chunk-BOW2QPQC.mjs} +3 -3
- package/dist/{chunk-REKEQLQA.mjs.map → chunk-BOW2QPQC.mjs.map} +1 -1
- package/dist/{chunk-HI44AMLC.mjs → chunk-E7R7TL7J.mjs} +24 -19
- package/dist/chunk-E7R7TL7J.mjs.map +1 -0
- package/dist/{chunk-CUGK4ZBJ.mjs → chunk-IMS2HBJ7.mjs} +305 -30
- package/dist/chunk-IMS2HBJ7.mjs.map +1 -0
- package/dist/{chunk-LSNRG5Z2.js → chunk-KB4EPCK2.js} +4 -4
- package/dist/{chunk-LSNRG5Z2.js.map → chunk-KB4EPCK2.js.map} +1 -1
- package/dist/{chunk-ITB7FXG4.js → chunk-OJOKPBK7.js} +3 -3
- package/dist/chunk-OJOKPBK7.js.map +1 -0
- package/dist/{chunk-B2QCI6ET.js → chunk-UMRTU75Q.js} +309 -30
- package/dist/chunk-UMRTU75Q.js.map +1 -0
- package/dist/{chunk-GS7TDQXA.js → chunk-XUS6KI3G.js} +8 -8
- package/dist/{chunk-GS7TDQXA.js.map → chunk-XUS6KI3G.js.map} +1 -1
- package/dist/core.js +16 -16
- package/dist/core.js.map +1 -1
- package/dist/core.mjs +6 -6
- package/dist/core.mjs.map +1 -1
- package/dist/display.d.mts +1 -1
- package/dist/display.d.ts +1 -1
- package/dist/display.js +12 -12
- package/dist/display.mjs +4 -4
- package/dist/{exchange-rate-BfPH_fQt.d.mts → exchange-rate-DCB2CY9v.d.mts} +5 -0
- package/dist/{exchange-rate-Cp1ddpw4.d.ts → exchange-rate-DOmoqut9.d.ts} +5 -0
- package/dist/index.d.mts +455 -8
- package/dist/index.d.ts +455 -8
- package/dist/index.js +402 -215
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +292 -123
- package/dist/index.mjs.map +1 -1
- package/dist/utils.js +5 -5
- package/dist/utils.mjs +2 -2
- package/package.json +2 -1
- package/dist/chunk-B2QCI6ET.js.map +0 -1
- package/dist/chunk-CUGK4ZBJ.mjs.map +0 -1
- package/dist/chunk-DTFLXAZJ.js.map +0 -1
- package/dist/chunk-HI44AMLC.mjs.map +0 -1
- package/dist/chunk-ITB7FXG4.js.map +0 -1
- package/dist/chunk-KYR6BFAE.js.map +0 -1
- package/dist/chunk-XXHRCCZS.mjs.map +0 -1
- package/dist/chunk-ZILA73XN.mjs.map +0 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunk4NQCOMCZ_js = require('./chunk-4NQCOMCZ.js');
|
|
4
4
|
var chunkICKDAKVS_js = require('./chunk-ICKDAKVS.js');
|
|
5
5
|
var chunkRUIAH5HY_js = require('./chunk-RUIAH5HY.js');
|
|
6
6
|
var chunk3I3PYX2F_js = require('./chunk-3I3PYX2F.js');
|
|
7
|
-
var
|
|
7
|
+
var chunkUMRTU75Q_js = require('./chunk-UMRTU75Q.js');
|
|
8
8
|
var viem = require('viem');
|
|
9
9
|
|
|
10
10
|
var isDepositSpendApproved = async ({
|
|
@@ -15,13 +15,13 @@ var isDepositSpendApproved = async ({
|
|
|
15
15
|
}) => {
|
|
16
16
|
try {
|
|
17
17
|
const normalizedChainId = chunkRUIAH5HY_js.toChainId(chainId);
|
|
18
|
-
const config = await
|
|
18
|
+
const config = await chunkUMRTU75Q_js.findVaultByConfig({
|
|
19
19
|
yieldType,
|
|
20
20
|
chainId: normalizedChainId,
|
|
21
21
|
assetAddress: depositAssetAddress
|
|
22
22
|
});
|
|
23
23
|
if (!config) {
|
|
24
|
-
throw new
|
|
24
|
+
throw new chunkUMRTU75Q_js.APIError(
|
|
25
25
|
`Vault not found for ${yieldType} on chain ${normalizedChainId}`,
|
|
26
26
|
{
|
|
27
27
|
endpoint: "isDepositSpendApproved"
|
|
@@ -30,39 +30,44 @@ var isDepositSpendApproved = async ({
|
|
|
30
30
|
}
|
|
31
31
|
const boringVaultAddress = config.vault.boringVaultAddress;
|
|
32
32
|
if (!boringVaultAddress) {
|
|
33
|
-
throw new
|
|
33
|
+
throw new chunkUMRTU75Q_js.APIError(
|
|
34
34
|
`BoringVault contract address not configured for vault ${config.id}`,
|
|
35
35
|
{
|
|
36
36
|
endpoint: "isDepositSpendApproved"
|
|
37
37
|
}
|
|
38
38
|
);
|
|
39
39
|
}
|
|
40
|
-
const
|
|
40
|
+
const {
|
|
41
|
+
decimals,
|
|
42
|
+
allowance,
|
|
43
|
+
supportsPermit,
|
|
44
|
+
nonce,
|
|
45
|
+
domainSeparator,
|
|
46
|
+
tokenName,
|
|
47
|
+
tokenVersion
|
|
48
|
+
} = await chunk4NQCOMCZ_js.getTokenPermitInfoWithAllowance({
|
|
41
49
|
chainId: normalizedChainId,
|
|
42
50
|
tokenAddress: depositAssetAddress,
|
|
43
|
-
recipientAddress,
|
|
44
|
-
|
|
51
|
+
owner: recipientAddress,
|
|
52
|
+
spender: boringVaultAddress
|
|
45
53
|
});
|
|
46
|
-
if (allowance.status === "failure" || decimals.status === "failure") {
|
|
47
|
-
throw new chunkB2QCI6ET_js.APIError(
|
|
48
|
-
`Failed to get allowance: ${allowance.error || decimals.error}`,
|
|
49
|
-
{
|
|
50
|
-
endpoint: "isDepositSpendApproved"
|
|
51
|
-
}
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
54
|
return {
|
|
55
|
-
isApproved: allowance
|
|
56
|
-
allowance: viem.formatUnits(allowance
|
|
57
|
-
allowanceAsBigInt: allowance.
|
|
58
|
-
decimals
|
|
55
|
+
isApproved: allowance > 0n,
|
|
56
|
+
allowance: viem.formatUnits(allowance, decimals),
|
|
57
|
+
allowanceAsBigInt: allowance.toString(),
|
|
58
|
+
decimals,
|
|
59
|
+
supportsPermit,
|
|
60
|
+
nonce,
|
|
61
|
+
domainSeparator,
|
|
62
|
+
tokenName,
|
|
63
|
+
tokenVersion,
|
|
59
64
|
error: null
|
|
60
65
|
};
|
|
61
66
|
} catch (error) {
|
|
62
|
-
if (error instanceof
|
|
67
|
+
if (error instanceof chunkUMRTU75Q_js.APIError) {
|
|
63
68
|
throw error;
|
|
64
69
|
}
|
|
65
|
-
throw new
|
|
70
|
+
throw new chunkUMRTU75Q_js.APIError(
|
|
66
71
|
`Failed to check deposit approval: ${error instanceof Error ? error.message : String(error)}`,
|
|
67
72
|
{
|
|
68
73
|
endpoint: "isDepositSpendApproved",
|
|
@@ -79,13 +84,13 @@ var isWithdrawalSpendApproved = async ({
|
|
|
79
84
|
}) => {
|
|
80
85
|
try {
|
|
81
86
|
const normalizedChainId = chunkRUIAH5HY_js.toChainId(chainId);
|
|
82
|
-
const config = await
|
|
87
|
+
const config = await chunkUMRTU75Q_js.findVaultByConfig({
|
|
83
88
|
yieldType,
|
|
84
89
|
chainId: normalizedChainId,
|
|
85
90
|
assetAddress: wantAssetAddress
|
|
86
91
|
});
|
|
87
92
|
if (!config) {
|
|
88
|
-
throw new
|
|
93
|
+
throw new chunkUMRTU75Q_js.APIError(
|
|
89
94
|
`Vault not found for ${yieldType} on chain ${normalizedChainId}`,
|
|
90
95
|
{
|
|
91
96
|
endpoint: "isWithdrawalSpendApproved"
|
|
@@ -94,18 +99,18 @@ var isWithdrawalSpendApproved = async ({
|
|
|
94
99
|
}
|
|
95
100
|
const boringVaultAddress = config.vault.boringVaultAddress;
|
|
96
101
|
if (!boringVaultAddress) {
|
|
97
|
-
throw new
|
|
102
|
+
throw new chunkUMRTU75Q_js.APIError(
|
|
98
103
|
`BoringVault contract address not configured for vault ${config.id}`,
|
|
99
104
|
{
|
|
100
105
|
endpoint: "isWithdrawalSpendApproved"
|
|
101
106
|
}
|
|
102
107
|
);
|
|
103
108
|
}
|
|
104
|
-
const [allowance, decimals] = await
|
|
109
|
+
const [allowance, decimals] = await chunk4NQCOMCZ_js.getErc20AllowanceWithDecimals({
|
|
105
110
|
chainId: normalizedChainId,
|
|
106
111
|
tokenAddress: boringVaultAddress,
|
|
107
112
|
recipientAddress,
|
|
108
|
-
spenderAddress:
|
|
113
|
+
spenderAddress: chunkUMRTU75Q_js.ATOMIC_QUEUE_CONTRACT_ADDRESS
|
|
109
114
|
});
|
|
110
115
|
if (allowance.status === "failure" || decimals.status === "failure") {
|
|
111
116
|
return {
|
|
@@ -124,10 +129,10 @@ var isWithdrawalSpendApproved = async ({
|
|
|
124
129
|
error: null
|
|
125
130
|
};
|
|
126
131
|
} catch (error) {
|
|
127
|
-
if (error instanceof
|
|
132
|
+
if (error instanceof chunkUMRTU75Q_js.APIError) {
|
|
128
133
|
throw error;
|
|
129
134
|
}
|
|
130
|
-
throw new
|
|
135
|
+
throw new chunkUMRTU75Q_js.APIError(
|
|
131
136
|
`Failed to check withdrawal approval: ${error instanceof Error ? error.message : String(error)}`,
|
|
132
137
|
{ endpoint: "isWithdrawalSpendApproved", cause: error }
|
|
133
138
|
);
|
|
@@ -159,7 +164,7 @@ var getDepositExchangeRate = async ({
|
|
|
159
164
|
if (!tokenAddress) {
|
|
160
165
|
throw new Error(`Token address not found for ${depositTokenSymbol}`);
|
|
161
166
|
}
|
|
162
|
-
const [decimals, rate] = await
|
|
167
|
+
const [decimals, rate] = await chunk4NQCOMCZ_js.getRateInQuoteWithAssetDecimals({
|
|
163
168
|
assetAddress: tokenAddress,
|
|
164
169
|
accountantAddress: vault.contracts.accountant,
|
|
165
170
|
chainId: sourceChainId
|
|
@@ -207,7 +212,7 @@ var getWithdrawExchangeRate = async ({
|
|
|
207
212
|
if (!tokenAddress) {
|
|
208
213
|
throw new Error(`Token address not found for ${wantTokenSymbol}`);
|
|
209
214
|
}
|
|
210
|
-
const [decimals, rate] = await
|
|
215
|
+
const [decimals, rate] = await chunk4NQCOMCZ_js.getRateInQuoteWithAssetDecimals({
|
|
211
216
|
assetAddress: tokenAddress,
|
|
212
217
|
accountantAddress: vault.contracts.accountant,
|
|
213
218
|
chainId: sourceChainId
|
|
@@ -229,5 +234,5 @@ exports.getDepositExchangeRate = getDepositExchangeRate;
|
|
|
229
234
|
exports.getWithdrawExchangeRate = getWithdrawExchangeRate;
|
|
230
235
|
exports.isDepositSpendApproved = isDepositSpendApproved;
|
|
231
236
|
exports.isWithdrawalSpendApproved = isWithdrawalSpendApproved;
|
|
232
|
-
//# sourceMappingURL=chunk-
|
|
233
|
-
//# sourceMappingURL=chunk-
|
|
237
|
+
//# sourceMappingURL=chunk-5VOI4WPL.js.map
|
|
238
|
+
//# sourceMappingURL=chunk-5VOI4WPL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/display/approvals.ts","../src/display/exchange-rate.ts"],"names":["toChainId","findVaultByConfig","APIError","getTokenPermitInfoWithAllowance","formatUnits","getErc20AllowanceWithDecimals","ATOMIC_QUEUE_CONTRACT_ADDRESS","getVaultByKey","getRateInQuoteWithAssetDecimals","bigIntToNumberAsString"],"mappings":";;;;;;;;;AAWO,IAAM,yBAAyB,OAAO;AAAA,EAC3C,SAAA;AAAA,EACA,OAAA;AAAA,EACA,mBAAA;AAAA,EACA;AACF,CAAA,KAKM;AACJ,EAAA,IAAI;AACF,IAA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C7D,YAAA,EAAc,YAAA;AAAA,IACd,iBAAA,EAAmB,MAAM,SAAA,CAAU,UAAA;AAAA,IACnC,OAAA,EAAS;AAAA,GACV,CAAA;AAED,EAAA,IAAI,IAAA,CAAK,WAAW,SAAA,EAAW;AAC7B,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,oBAAA,EAAuB,IAAA,CAAK,KAAA,CAAM,OAAO,CAAA,CAAE,CAAA;AAAA,EAC7D;AACA,EAAA,IAAI,QAAA,CAAS,WAAW,SAAA,EAAW;AACjC,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,wBAAA,EAA2B,QAAA,CAAS,KAAA,CAAM,OAAO,CAAA,CAAE,CAAA;AAAA,EACrE;AAEA,EAAA,OAAOC,uCAAA,CAAuB,KAAK,MAAA,EAAQ;AAAA,IACzC,UAAU,QAAA,CAAS,MAAA;AAAA,IACnB,qBAAA;AAAA,IACA;AAAA,GACD,CAAA;AACH","file":"chunk-5VOI4WPL.js","sourcesContent":["import type { Address } from \"viem\";\nimport { formatUnits } from \"viem\";\nimport { findVaultByConfig } from \"../api/amplify-sdk-client\";\nimport {\n getErc20AllowanceWithDecimals,\n getTokenPermitInfoWithAllowance,\n} from \"../api/erc20\";\nimport { type ChainId, toChainId } from \"../api/vault-config\";\nimport { ATOMIC_QUEUE_CONTRACT_ADDRESS } from \"../constants\";\nimport { APIError, type YieldType } from \"../types/amplify-sdk-api\";\n\nexport const isDepositSpendApproved = async ({\n yieldType,\n chainId,\n depositAssetAddress,\n recipientAddress,\n}: {\n yieldType: YieldType;\n chainId: ChainId;\n depositAssetAddress: Address;\n recipientAddress: Address;\n}) => {\n try {\n const normalizedChainId = toChainId(chainId);\n const config = await findVaultByConfig({\n yieldType,\n chainId: normalizedChainId,\n assetAddress: depositAssetAddress,\n });\n\n if (!config) {\n throw new APIError(\n `Vault not found for ${yieldType} on chain ${normalizedChainId}`,\n {\n endpoint: \"isDepositSpendApproved\",\n }\n );\n }\n\n const boringVaultAddress = config.vault.boringVaultAddress;\n if (!boringVaultAddress) {\n throw new APIError(\n `BoringVault contract address not configured for vault ${config.id}`,\n {\n endpoint: \"isDepositSpendApproved\",\n }\n );\n }\n\n const {\n decimals,\n allowance,\n supportsPermit,\n nonce,\n domainSeparator,\n tokenName,\n tokenVersion,\n } = await getTokenPermitInfoWithAllowance({\n chainId: normalizedChainId,\n tokenAddress: depositAssetAddress,\n owner: recipientAddress,\n spender: boringVaultAddress,\n });\n\n return {\n isApproved: allowance > 0n,\n allowance: formatUnits(allowance, decimals),\n allowanceAsBigInt: allowance.toString(),\n decimals,\n supportsPermit,\n nonce,\n domainSeparator,\n tokenName,\n tokenVersion,\n error: null,\n };\n } catch (error) {\n if (error instanceof APIError) {\n throw error;\n }\n\n // Wrap other errors\n throw new APIError(\n `Failed to check deposit approval: ${\n error instanceof Error ? error.message : String(error)\n }`,\n {\n endpoint: \"isDepositSpendApproved\",\n cause: error,\n }\n );\n }\n};\n\nexport const isWithdrawalSpendApproved = async ({\n yieldType,\n chainId,\n wantAssetAddress,\n recipientAddress,\n}: {\n yieldType: YieldType;\n chainId: ChainId;\n wantAssetAddress: Address;\n recipientAddress: Address;\n}) => {\n try {\n const normalizedChainId = toChainId(chainId);\n\n const config = await findVaultByConfig({\n yieldType,\n chainId: normalizedChainId,\n assetAddress: wantAssetAddress,\n });\n\n if (!config) {\n throw new APIError(\n `Vault not found for ${yieldType} on chain ${normalizedChainId}`,\n {\n endpoint: \"isWithdrawalSpendApproved\",\n }\n );\n }\n\n const boringVaultAddress = config.vault.boringVaultAddress;\n\n if (!boringVaultAddress) {\n throw new APIError(\n `BoringVault contract address not configured for vault ${config.id}`,\n {\n endpoint: \"isWithdrawalSpendApproved\",\n }\n );\n }\n\n const [allowance, decimals] = await getErc20AllowanceWithDecimals({\n chainId: normalizedChainId,\n tokenAddress: boringVaultAddress,\n recipientAddress: recipientAddress,\n spenderAddress: ATOMIC_QUEUE_CONTRACT_ADDRESS,\n });\n\n if (allowance.status === \"failure\" || decimals.status === \"failure\") {\n return {\n isApproved: false,\n allowance: \"0\",\n allowanceAsBigInt: \"0\",\n decimals: \"0\",\n error: allowance.error || decimals.error,\n };\n }\n\n return {\n isApproved: allowance.result > 0n,\n allowance: formatUnits(allowance.result, decimals.result),\n allowanceAsBigInt: allowance.result.toString(),\n decimals: decimals.result,\n error: null,\n };\n } catch (error) {\n if (error instanceof APIError) {\n throw error;\n }\n\n throw new APIError(\n `Failed to check withdrawal approval: ${\n error instanceof Error ? error.message : String(error)\n }`,\n { endpoint: \"isWithdrawalSpendApproved\", cause: error }\n );\n }\n};\n","import { getRateInQuoteWithAssetDecimals } from \"../api/accountant\";\nimport type { ChainId } from \"../api/vault-config\";\nimport { bigIntToNumberAsString } from \"../utils/bigint\";\nimport { getVaultByKey } from \"../vaults\";\nimport type { VaultKey } from \"../vaults/config\";\n\ninterface GetDepositExchangeRateParams {\n vaultKey: VaultKey;\n sourceChainId: ChainId;\n depositTokenSymbol: string;\n minimumFractionDigits?: number;\n maximumFractionDigits?: number;\n}\n\n/**\n * Gets the deposit exchange rate for a vault (tokens per share)\n * @throws {Error} If the token address is not found or if there's an error fetching the rate\n * @returns Promise<string> The exchange rate as a formatted string representing how many deposit tokens are worth 1 share\n */\nconst getDepositExchangeRate = async ({\n vaultKey,\n sourceChainId,\n depositTokenSymbol,\n minimumFractionDigits,\n maximumFractionDigits = 3,\n}: GetDepositExchangeRateParams) => {\n const vault = await getVaultByKey(vaultKey);\n\n const sourceChain = vault.deposit.sourceChains[sourceChainId];\n if (!sourceChain) {\n throw new Error(\n `Source chain ${sourceChainId} not found for vault ${vaultKey}`\n );\n }\n\n const depositToken = sourceChain.depositTokens?.[depositTokenSymbol];\n if (!depositToken) {\n throw new Error(\n `Deposit token ${depositTokenSymbol} not found for chain ${sourceChainId}`\n );\n }\n\n const tokenAddress = depositToken.address;\n if (!tokenAddress) {\n throw new Error(`Token address not found for ${depositTokenSymbol}`);\n }\n\n const [decimals, rate] = await getRateInQuoteWithAssetDecimals({\n assetAddress: tokenAddress,\n accountantAddress: vault.contracts.accountant,\n chainId: sourceChainId,\n });\n\n if (rate.status === \"failure\") {\n throw new Error(`Failed to get rate: ${rate.error.message}`);\n }\n if (decimals.status === \"failure\") {\n throw new Error(`Failed to get decimals: ${decimals.error.message}`);\n }\n\n return bigIntToNumberAsString(rate.result, {\n decimals: decimals.result,\n minimumFractionDigits,\n maximumFractionDigits,\n });\n};\n\ninterface GetWithdrawExchangeRateParams {\n vaultKey: VaultKey;\n sourceChainId: ChainId;\n destinationChainId: ChainId;\n wantTokenSymbol: string;\n minimumFractionDigits?: number;\n maximumFractionDigits?: number;\n}\n\n/**\n * Gets the withdraw exchange rate for a vault (tokens per share)\n * @throws {Error} If the token address is not found or if there's an error fetching the rate\n * @returns Promise<string> The exchange rate as a formatted string representing how many want tokens are worth 1 share\n */\nconst getWithdrawExchangeRate = async ({\n vaultKey,\n sourceChainId,\n destinationChainId,\n wantTokenSymbol,\n minimumFractionDigits,\n maximumFractionDigits = 3,\n}: GetWithdrawExchangeRateParams) => {\n const vault = await getVaultByKey(vaultKey);\n\n const sourceChain = vault.withdraw.sourceChains[sourceChainId];\n if (!sourceChain) {\n throw new Error(\n `Source chain ${sourceChainId} not found for vault ${vaultKey}`\n );\n }\n\n const destinationChain = sourceChain.destinationChains[destinationChainId];\n if (!destinationChain) {\n throw new Error(\n `Destination chain ${destinationChainId} not found for source chain ${sourceChainId}`\n );\n }\n\n const wantToken = destinationChain.wantTokens?.[wantTokenSymbol];\n if (!wantToken) {\n throw new Error(\n `Want token ${wantTokenSymbol} not found for chain ${destinationChainId}`\n );\n }\n\n const tokenAddress = wantToken.address;\n if (!tokenAddress) {\n throw new Error(`Token address not found for ${wantTokenSymbol}`);\n }\n\n const [decimals, rate] = await getRateInQuoteWithAssetDecimals({\n assetAddress: tokenAddress,\n accountantAddress: vault.contracts.accountant,\n chainId: sourceChainId,\n });\n\n if (rate.status === \"failure\") {\n throw new Error(`Failed to get rate: ${rate.error.message}`);\n }\n if (decimals.status === \"failure\") {\n throw new Error(`Failed to get decimals: ${decimals.error.message}`);\n }\n\n return bigIntToNumberAsString(rate.result, {\n decimals: decimals.result,\n minimumFractionDigits,\n maximumFractionDigits,\n });\n};\n\nexport { getDepositExchangeRate, getWithdrawExchangeRate };\n"]}
|
|
@@ -1,7 +1,54 @@
|
|
|
1
1
|
import { toChainId } from './chunk-J3662HYT.mjs';
|
|
2
|
-
import { getChainFromConfig, fetchVaults } from './chunk-
|
|
2
|
+
import { getChainFromConfig, fetchVaults, APIError } from './chunk-IMS2HBJ7.mjs';
|
|
3
3
|
import { createPublicClient, http, erc20Abi } from 'viem';
|
|
4
4
|
|
|
5
|
+
// src/abi/erc2612-abi.ts
|
|
6
|
+
var erc2612Abi = [
|
|
7
|
+
// Standard ERC20 functions (subset needed for permit flow)
|
|
8
|
+
{
|
|
9
|
+
constant: true,
|
|
10
|
+
inputs: [{ name: "_owner", type: "address" }],
|
|
11
|
+
name: "nonces",
|
|
12
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
13
|
+
type: "function"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
constant: true,
|
|
17
|
+
inputs: [],
|
|
18
|
+
name: "DOMAIN_SEPARATOR",
|
|
19
|
+
outputs: [{ name: "", type: "bytes32" }],
|
|
20
|
+
type: "function"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
constant: false,
|
|
24
|
+
inputs: [
|
|
25
|
+
{ name: "owner", type: "address" },
|
|
26
|
+
{ name: "spender", type: "address" },
|
|
27
|
+
{ name: "value", type: "uint256" },
|
|
28
|
+
{ name: "deadline", type: "uint256" },
|
|
29
|
+
{ name: "v", type: "uint8" },
|
|
30
|
+
{ name: "r", type: "bytes32" },
|
|
31
|
+
{ name: "s", type: "bytes32" }
|
|
32
|
+
],
|
|
33
|
+
name: "permit",
|
|
34
|
+
outputs: [],
|
|
35
|
+
type: "function"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
constant: true,
|
|
39
|
+
inputs: [],
|
|
40
|
+
name: "name",
|
|
41
|
+
outputs: [{ name: "", type: "string" }],
|
|
42
|
+
type: "function"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
constant: true,
|
|
46
|
+
inputs: [],
|
|
47
|
+
name: "version",
|
|
48
|
+
outputs: [{ name: "", type: "string" }],
|
|
49
|
+
type: "function"
|
|
50
|
+
}
|
|
51
|
+
];
|
|
5
52
|
var clients = /* @__PURE__ */ new Map();
|
|
6
53
|
var getClient = async (chainId) => {
|
|
7
54
|
if (!chainId) {
|
|
@@ -91,6 +138,99 @@ var getErc20AllowanceWithDecimals = async ({
|
|
|
91
138
|
});
|
|
92
139
|
return allowance;
|
|
93
140
|
};
|
|
141
|
+
var getTokenPermitInfoWithAllowance = async ({
|
|
142
|
+
chainId,
|
|
143
|
+
tokenAddress,
|
|
144
|
+
owner,
|
|
145
|
+
spender
|
|
146
|
+
}) => {
|
|
147
|
+
const client = await getClient(chainId);
|
|
148
|
+
const results = await client.multicall({
|
|
149
|
+
contracts: [
|
|
150
|
+
{
|
|
151
|
+
abi: erc20Abi,
|
|
152
|
+
address: tokenAddress,
|
|
153
|
+
functionName: "decimals"
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
abi: erc20Abi,
|
|
157
|
+
address: tokenAddress,
|
|
158
|
+
functionName: "allowance",
|
|
159
|
+
args: [owner, spender]
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
abi: erc2612Abi,
|
|
163
|
+
address: tokenAddress,
|
|
164
|
+
functionName: "nonces",
|
|
165
|
+
args: [owner]
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
abi: erc2612Abi,
|
|
169
|
+
address: tokenAddress,
|
|
170
|
+
functionName: "DOMAIN_SEPARATOR"
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
abi: erc20Abi,
|
|
174
|
+
address: tokenAddress,
|
|
175
|
+
functionName: "name"
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
abi: erc2612Abi,
|
|
179
|
+
address: tokenAddress,
|
|
180
|
+
functionName: "version"
|
|
181
|
+
}
|
|
182
|
+
],
|
|
183
|
+
allowFailure: true
|
|
184
|
+
});
|
|
185
|
+
const [
|
|
186
|
+
decimalsResult,
|
|
187
|
+
allowanceResult,
|
|
188
|
+
nonceResult,
|
|
189
|
+
domainSeparatorResult,
|
|
190
|
+
nameResult,
|
|
191
|
+
versionResult
|
|
192
|
+
] = results;
|
|
193
|
+
if (decimalsResult.status === "failure") {
|
|
194
|
+
throw new APIError(
|
|
195
|
+
`Failed to read decimals from token ${tokenAddress}: ${decimalsResult.error?.message || "Unknown error"}`,
|
|
196
|
+
{
|
|
197
|
+
endpoint: "getTokenPermitInfoWithAllowance",
|
|
198
|
+
cause: decimalsResult.error
|
|
199
|
+
}
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
if (allowanceResult.status === "failure") {
|
|
203
|
+
throw new APIError(
|
|
204
|
+
`Failed to read allowance from token ${tokenAddress}: ${allowanceResult.error?.message || "Unknown error"}`,
|
|
205
|
+
{
|
|
206
|
+
endpoint: "getTokenPermitInfoWithAllowance",
|
|
207
|
+
cause: allowanceResult.error
|
|
208
|
+
}
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
if (nameResult.status === "failure") {
|
|
212
|
+
throw new APIError(
|
|
213
|
+
`Failed to read name from token ${tokenAddress}: ${nameResult.error?.message || "Unknown error"}`,
|
|
214
|
+
{
|
|
215
|
+
endpoint: "getTokenPermitInfoWithAllowance",
|
|
216
|
+
cause: nameResult.error
|
|
217
|
+
}
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
const nonce = nonceResult.status === "success" ? nonceResult.result : null;
|
|
221
|
+
const domainSeparator = domainSeparatorResult.status === "success" ? domainSeparatorResult.result : null;
|
|
222
|
+
const supportsPermit = nonce !== null && domainSeparator !== null;
|
|
223
|
+
const tokenVersion = versionResult.status === "success" ? versionResult.result : "1";
|
|
224
|
+
return {
|
|
225
|
+
decimals: decimalsResult.result,
|
|
226
|
+
allowance: allowanceResult.result,
|
|
227
|
+
supportsPermit,
|
|
228
|
+
nonce,
|
|
229
|
+
domainSeparator,
|
|
230
|
+
tokenName: nameResult.result,
|
|
231
|
+
tokenVersion
|
|
232
|
+
};
|
|
233
|
+
};
|
|
94
234
|
|
|
95
235
|
// src/abi/accountant-abi.ts
|
|
96
236
|
var AccountantAbi = [
|
|
@@ -2045,6 +2185,6 @@ var TellerAbi = [
|
|
|
2045
2185
|
}
|
|
2046
2186
|
];
|
|
2047
2187
|
|
|
2048
|
-
export { AccountantAbi, BoringVaultAbi, TellerAbi, getClient, getErc20Allowance, getErc20AllowanceWithDecimals, getErc20Balance, getErc20Decimals, getRateInQuoteAndSharesAndWantAssetDecimals, getRateInQuoteWithAssetDecimals };
|
|
2049
|
-
//# sourceMappingURL=chunk-
|
|
2050
|
-
//# sourceMappingURL=chunk-
|
|
2188
|
+
export { AccountantAbi, BoringVaultAbi, TellerAbi, erc2612Abi, getClient, getErc20Allowance, getErc20AllowanceWithDecimals, getErc20Balance, getErc20Decimals, getRateInQuoteAndSharesAndWantAssetDecimals, getRateInQuoteWithAssetDecimals, getTokenPermitInfoWithAllowance };
|
|
2189
|
+
//# sourceMappingURL=chunk-5Y7M43XN.mjs.map
|
|
2190
|
+
//# sourceMappingURL=chunk-5Y7M43XN.mjs.map
|