@paxoslabs/amplify-sdk 0.2.3-alpha.1 → 0.2.3-alpha.2
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/dist/{chunk-WDPR2NKT.mjs → chunk-B55AAGKF.mjs} +6 -6
- package/dist/chunk-B55AAGKF.mjs.map +1 -0
- package/dist/{chunk-IJBG5TTI.js → chunk-GRRN4KON.js} +6 -6
- package/dist/chunk-GRRN4KON.js.map +1 -0
- package/dist/display.js +5 -5
- package/dist/display.mjs +1 -1
- package/dist/index.d.mts +26 -5
- package/dist/index.d.ts +26 -5
- package/dist/index.js +18 -36
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15 -33
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-IJBG5TTI.js.map +0 -1
- package/dist/chunk-WDPR2NKT.mjs.map +0 -1
|
@@ -26,10 +26,10 @@ var isDepositSpendApproved = async ({
|
|
|
26
26
|
}
|
|
27
27
|
);
|
|
28
28
|
}
|
|
29
|
-
const
|
|
30
|
-
if (!
|
|
29
|
+
const communityCodeDepositorAddress = config.vault.communityCodeDepositorAddress;
|
|
30
|
+
if (!communityCodeDepositorAddress) {
|
|
31
31
|
throw new APIError(
|
|
32
|
-
`
|
|
32
|
+
`Community code depositor contract address not configured for vault ${config.id}`,
|
|
33
33
|
{
|
|
34
34
|
endpoint: "isDepositSpendApproved"
|
|
35
35
|
}
|
|
@@ -47,7 +47,7 @@ var isDepositSpendApproved = async ({
|
|
|
47
47
|
chainId: normalizedChainId,
|
|
48
48
|
tokenAddress: depositAssetAddress,
|
|
49
49
|
owner: recipientAddress,
|
|
50
|
-
spender:
|
|
50
|
+
spender: communityCodeDepositorAddress
|
|
51
51
|
});
|
|
52
52
|
return {
|
|
53
53
|
isApproved: allowance > 0n,
|
|
@@ -229,5 +229,5 @@ var getWithdrawExchangeRate = async ({
|
|
|
229
229
|
};
|
|
230
230
|
|
|
231
231
|
export { getDepositExchangeRate, getWithdrawExchangeRate, isDepositSpendApproved, isWithdrawalSpendApproved };
|
|
232
|
-
//# sourceMappingURL=chunk-
|
|
233
|
-
//# sourceMappingURL=chunk-
|
|
232
|
+
//# sourceMappingURL=chunk-B55AAGKF.mjs.map
|
|
233
|
+
//# sourceMappingURL=chunk-B55AAGKF.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/display/approvals.ts","../src/display/exchange-rate.ts"],"names":[],"mappings":";;;;;;;AAWO,IAAM,yBAAyB,OAAO;AAAA,EAC3C,SAAA;AAAA,EACA,OAAA;AAAA,EACA,mBAAA;AAAA,EACA;AACF,CAAA,KAKM;AACJ,EAAA,IAAI;AACF,IAAA,MAAM,iBAAA,GAAoB,UAAU,OAAO,CAAA;AAC3C,IAAA,MAAM,MAAA,GAAS,MAAM,iBAAA,CAAkB;AAAA,MACrC,SAAA;AAAA,MACA,OAAA,EAAS,iBAAA;AAAA,MACT,YAAA,EAAc;AAAA,KACf,CAAA;AAED,IAAA,IAAI,CAAC,MAAA,EAAQ;AACX,MAAA,MAAM,IAAI,QAAA;AAAA,QACR,CAAA,oBAAA,EAAuB,SAAS,CAAA,UAAA,EAAa,iBAAiB,CAAA,CAAA;AAAA,QAC9D;AAAA,UACE,QAAA,EAAU;AAAA;AACZ,OACF;AAAA,IACF;AAEA,IAAA,MAAM,6BAAA,GACJ,OAAO,KAAA,CAAM,6BAAA;AACf,IAAA,IAAI,CAAC,6BAAA,EAA+B;AAClC,MAAA,MAAM,IAAI,QAAA;AAAA,QACR,CAAA,mEAAA,EAAsE,OAAO,EAAE,CAAA,CAAA;AAAA,QAC/E;AAAA,UACE,QAAA,EAAU;AAAA;AACZ,OACF;AAAA,IACF;AAEA,IAAA,MAAM;AAAA,MACJ,QAAA;AAAA,MACA,SAAA;AAAA,MACA,cAAA;AAAA,MACA,KAAA;AAAA,MACA,eAAA;AAAA,MACA,SAAA;AAAA,MACA;AAAA,KACF,GAAI,MAAM,+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AA,IAAI,CAAC,SAAA,EAAW;AACd,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,WAAA,EAAc,eAAe,CAAA,qBAAA,EAAwB,kBAAkB,CAAA;AAAA,KACzE;AAAA,EACF;AAEA,EAAA,MAAM,eAAe,SAAA,CAAU,OAAA;AAC/B,EAAA,IAAI,CAAC,YAAA,EAAc;AACjB,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,4BAAA,EAA+B,eAAe,CAAA,CAAE,CAAA;AAAA,EAClE;AAEA,EAAA,MAAM,CAAC,QAAA,EAAU,IAAI,CAAA,GAAI,MAAM,+BAAA,CAAgC;AAAA,IAC7D,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,OAAO,sBAAA,CAAuB,KAAK,MAAA,EAAQ;AAAA,IACzC,UAAU,QAAA,CAAS,MAAA;AAAA,IACnB,qBAAA;AAAA,IACA;AAAA,GACD,CAAA;AACH","file":"chunk-B55AAGKF.mjs","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 communityCodeDepositorAddress =\n config.vault.communityCodeDepositorAddress;\n if (!communityCodeDepositorAddress) {\n throw new APIError(\n `Community code depositor 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: communityCodeDepositorAddress,\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"]}
|
|
@@ -28,10 +28,10 @@ var isDepositSpendApproved = async ({
|
|
|
28
28
|
}
|
|
29
29
|
);
|
|
30
30
|
}
|
|
31
|
-
const
|
|
32
|
-
if (!
|
|
31
|
+
const communityCodeDepositorAddress = config.vault.communityCodeDepositorAddress;
|
|
32
|
+
if (!communityCodeDepositorAddress) {
|
|
33
33
|
throw new chunkCK3BIPWI_js.APIError(
|
|
34
|
-
`
|
|
34
|
+
`Community code depositor contract address not configured for vault ${config.id}`,
|
|
35
35
|
{
|
|
36
36
|
endpoint: "isDepositSpendApproved"
|
|
37
37
|
}
|
|
@@ -49,7 +49,7 @@ var isDepositSpendApproved = async ({
|
|
|
49
49
|
chainId: normalizedChainId,
|
|
50
50
|
tokenAddress: depositAssetAddress,
|
|
51
51
|
owner: recipientAddress,
|
|
52
|
-
spender:
|
|
52
|
+
spender: communityCodeDepositorAddress
|
|
53
53
|
});
|
|
54
54
|
return {
|
|
55
55
|
isApproved: allowance > 0n,
|
|
@@ -234,5 +234,5 @@ exports.getDepositExchangeRate = getDepositExchangeRate;
|
|
|
234
234
|
exports.getWithdrawExchangeRate = getWithdrawExchangeRate;
|
|
235
235
|
exports.isDepositSpendApproved = isDepositSpendApproved;
|
|
236
236
|
exports.isWithdrawalSpendApproved = isWithdrawalSpendApproved;
|
|
237
|
-
//# sourceMappingURL=chunk-
|
|
238
|
-
//# sourceMappingURL=chunk-
|
|
237
|
+
//# sourceMappingURL=chunk-GRRN4KON.js.map
|
|
238
|
+
//# sourceMappingURL=chunk-GRRN4KON.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,IAAA,MAAM,iBAAA,GAAoBA,2BAAU,OAAO,CAAA;AAC3C,IAAA,MAAM,MAAA,GAAS,MAAMC,kCAAA,CAAkB;AAAA,MACrC,SAAA;AAAA,MACA,OAAA,EAAS,iBAAA;AAAA,MACT,YAAA,EAAc;AAAA,KACf,CAAA;AAED,IAAA,IAAI,CAAC,MAAA,EAAQ;AACX,MAAA,MAAM,IAAIC,yBAAA;AAAA,QACR,CAAA,oBAAA,EAAuB,SAAS,CAAA,UAAA,EAAa,iBAAiB,CAAA,CAAA;AAAA,QAC9D;AAAA,UACE,QAAA,EAAU;AAAA;AACZ,OACF;AAAA,IACF;AAEA,IAAA,MAAM,6BAAA,GACJ,OAAO,KAAA,CAAM,6BAAA;AACf,IAAA,IAAI,CAAC,6BAAA,EAA+B;AAClC,MAAA,MAAM,IAAI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AAU,QAAA,CAAS,MAAA;AAAA,IACnB,qBAAA;AAAA,IACA;AAAA,GACD,CAAA;AACH","file":"chunk-GRRN4KON.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 communityCodeDepositorAddress =\n config.vault.communityCodeDepositorAddress;\n if (!communityCodeDepositorAddress) {\n throw new APIError(\n `Community code depositor 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: communityCodeDepositorAddress,\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"]}
|
package/dist/display.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkGRRN4KON_js = require('./chunk-GRRN4KON.js');
|
|
4
4
|
var chunkZRI7KBQ6_js = require('./chunk-ZRI7KBQ6.js');
|
|
5
5
|
require('./chunk-4ZYCWOFI.js');
|
|
6
6
|
var chunkICKDAKVS_js = require('./chunk-ICKDAKVS.js');
|
|
@@ -104,19 +104,19 @@ var getVaultStatus = async ({ vaultKey, chainId }) => {
|
|
|
104
104
|
|
|
105
105
|
Object.defineProperty(exports, "getDepositExchangeRate", {
|
|
106
106
|
enumerable: true,
|
|
107
|
-
get: function () { return
|
|
107
|
+
get: function () { return chunkGRRN4KON_js.getDepositExchangeRate; }
|
|
108
108
|
});
|
|
109
109
|
Object.defineProperty(exports, "getWithdrawExchangeRate", {
|
|
110
110
|
enumerable: true,
|
|
111
|
-
get: function () { return
|
|
111
|
+
get: function () { return chunkGRRN4KON_js.getWithdrawExchangeRate; }
|
|
112
112
|
});
|
|
113
113
|
Object.defineProperty(exports, "isDepositSpendApproved", {
|
|
114
114
|
enumerable: true,
|
|
115
|
-
get: function () { return
|
|
115
|
+
get: function () { return chunkGRRN4KON_js.isDepositSpendApproved; }
|
|
116
116
|
});
|
|
117
117
|
Object.defineProperty(exports, "isWithdrawalSpendApproved", {
|
|
118
118
|
enumerable: true,
|
|
119
|
-
get: function () { return
|
|
119
|
+
get: function () { return chunkGRRN4KON_js.isWithdrawalSpendApproved; }
|
|
120
120
|
});
|
|
121
121
|
exports.getBridgeFee = getBridgeFee;
|
|
122
122
|
exports.getVaultStatus = getVaultStatus;
|
package/dist/display.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { getDepositExchangeRate, getWithdrawExchangeRate, isDepositSpendApproved, isWithdrawalSpendApproved } from './chunk-
|
|
1
|
+
export { getDepositExchangeRate, getWithdrawExchangeRate, isDepositSpendApproved, isWithdrawalSpendApproved } from './chunk-B55AAGKF.mjs';
|
|
2
2
|
import { getPreviewFee, getPausedStates } from './chunk-RZN7S23Z.mjs';
|
|
3
3
|
import './chunk-VZ3D7CNR.mjs';
|
|
4
4
|
import { getVaultByKey } from './chunk-R663BFAZ.mjs';
|
package/dist/index.d.mts
CHANGED
|
@@ -1126,10 +1126,31 @@ declare const PERMIT_TYPES: {
|
|
|
1126
1126
|
* T009: Complete EIP-712 typed data for permit signature
|
|
1127
1127
|
* Returned by prepareDepositPermitSignature() ready for wallet signing
|
|
1128
1128
|
*
|
|
1129
|
+
* Compatible with viem's signTypedData(), wagmi's signTypedDataAsync(),
|
|
1130
|
+
* and Privy's signTypedData(). Pass this object directly to the signing function.
|
|
1131
|
+
*
|
|
1129
1132
|
* @property domain - EIP-712 domain separator with numeric chainId
|
|
1130
|
-
* @property types - EIP-2612 Permit type structure
|
|
1131
|
-
* @property message - Permit message fields
|
|
1133
|
+
* @property types - EIP-2612 Permit type structure
|
|
1134
|
+
* @property message - Permit message fields with uint256 values as decimal strings
|
|
1132
1135
|
* @property primaryType - Always "Permit" for EIP-2612
|
|
1136
|
+
*
|
|
1137
|
+
* @remarks
|
|
1138
|
+
* The message uses decimal string representations for uint256 values to ensure:
|
|
1139
|
+
* 1. JSON serialization compatibility (required for Privy embedded wallets)
|
|
1140
|
+
* 2. Compatibility with viem, wagmi, and Privy signing functions
|
|
1141
|
+
* 3. Compliance with EIP-712 JSON schema specification
|
|
1142
|
+
*
|
|
1143
|
+
* @example
|
|
1144
|
+
* ```typescript
|
|
1145
|
+
* // With wagmi
|
|
1146
|
+
* const signature = await signTypedDataAsync(permitData);
|
|
1147
|
+
*
|
|
1148
|
+
* // With viem
|
|
1149
|
+
* const signature = await walletClient.signTypedData(permitData);
|
|
1150
|
+
*
|
|
1151
|
+
* // With Privy
|
|
1152
|
+
* const signature = await wallet.signTypedData(permitData);
|
|
1153
|
+
* ```
|
|
1133
1154
|
*/
|
|
1134
1155
|
interface PermitSignatureData {
|
|
1135
1156
|
domain: EIP712Domain;
|
|
@@ -1142,9 +1163,9 @@ interface PermitSignatureData {
|
|
|
1142
1163
|
message: {
|
|
1143
1164
|
owner: Address;
|
|
1144
1165
|
spender: Address;
|
|
1145
|
-
value:
|
|
1146
|
-
nonce:
|
|
1147
|
-
deadline:
|
|
1166
|
+
value: string;
|
|
1167
|
+
nonce: string;
|
|
1168
|
+
deadline: string;
|
|
1148
1169
|
};
|
|
1149
1170
|
primaryType: "Permit";
|
|
1150
1171
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1126,10 +1126,31 @@ declare const PERMIT_TYPES: {
|
|
|
1126
1126
|
* T009: Complete EIP-712 typed data for permit signature
|
|
1127
1127
|
* Returned by prepareDepositPermitSignature() ready for wallet signing
|
|
1128
1128
|
*
|
|
1129
|
+
* Compatible with viem's signTypedData(), wagmi's signTypedDataAsync(),
|
|
1130
|
+
* and Privy's signTypedData(). Pass this object directly to the signing function.
|
|
1131
|
+
*
|
|
1129
1132
|
* @property domain - EIP-712 domain separator with numeric chainId
|
|
1130
|
-
* @property types - EIP-2612 Permit type structure
|
|
1131
|
-
* @property message - Permit message fields
|
|
1133
|
+
* @property types - EIP-2612 Permit type structure
|
|
1134
|
+
* @property message - Permit message fields with uint256 values as decimal strings
|
|
1132
1135
|
* @property primaryType - Always "Permit" for EIP-2612
|
|
1136
|
+
*
|
|
1137
|
+
* @remarks
|
|
1138
|
+
* The message uses decimal string representations for uint256 values to ensure:
|
|
1139
|
+
* 1. JSON serialization compatibility (required for Privy embedded wallets)
|
|
1140
|
+
* 2. Compatibility with viem, wagmi, and Privy signing functions
|
|
1141
|
+
* 3. Compliance with EIP-712 JSON schema specification
|
|
1142
|
+
*
|
|
1143
|
+
* @example
|
|
1144
|
+
* ```typescript
|
|
1145
|
+
* // With wagmi
|
|
1146
|
+
* const signature = await signTypedDataAsync(permitData);
|
|
1147
|
+
*
|
|
1148
|
+
* // With viem
|
|
1149
|
+
* const signature = await walletClient.signTypedData(permitData);
|
|
1150
|
+
*
|
|
1151
|
+
* // With Privy
|
|
1152
|
+
* const signature = await wallet.signTypedData(permitData);
|
|
1153
|
+
* ```
|
|
1133
1154
|
*/
|
|
1134
1155
|
interface PermitSignatureData {
|
|
1135
1156
|
domain: EIP712Domain;
|
|
@@ -1142,9 +1163,9 @@ interface PermitSignatureData {
|
|
|
1142
1163
|
message: {
|
|
1143
1164
|
owner: Address;
|
|
1144
1165
|
spender: Address;
|
|
1145
|
-
value:
|
|
1146
|
-
nonce:
|
|
1147
|
-
deadline:
|
|
1166
|
+
value: string;
|
|
1167
|
+
nonce: string;
|
|
1168
|
+
deadline: string;
|
|
1148
1169
|
};
|
|
1149
1170
|
primaryType: "Permit";
|
|
1150
1171
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var chunkOJOKPBK7_js = require('./chunk-OJOKPBK7.js');
|
|
4
|
-
var
|
|
4
|
+
var chunkGRRN4KON_js = require('./chunk-GRRN4KON.js');
|
|
5
5
|
var chunk4ZYCWOFI_js = require('./chunk-4ZYCWOFI.js');
|
|
6
6
|
require('./chunk-ICKDAKVS.js');
|
|
7
7
|
var chunkRUIAH5HY_js = require('./chunk-RUIAH5HY.js');
|
|
@@ -398,15 +398,6 @@ async function prepareDepositTxData(params) {
|
|
|
398
398
|
depositAmount,
|
|
399
399
|
depositAssetDecimalsResult.result
|
|
400
400
|
);
|
|
401
|
-
const vaultSharesAssets = await chunkCK3BIPWI_js.fetchSupportedAssets({
|
|
402
|
-
address: vault.vault.boringVaultAddress
|
|
403
|
-
});
|
|
404
|
-
if (vaultSharesAssets.length === 0) {
|
|
405
|
-
throw new chunkCK3BIPWI_js.APIError(
|
|
406
|
-
`Vault shares token not found in supported assets: ${vault.vault.boringVaultAddress}`,
|
|
407
|
-
{ endpoint: "prepareDepositTransactionData" }
|
|
408
|
-
);
|
|
409
|
-
}
|
|
410
401
|
const minimumMint = calculateMinimumMint(
|
|
411
402
|
depositAmountAsBigInt,
|
|
412
403
|
rateInQuoteResult.result,
|
|
@@ -582,7 +573,7 @@ async function prepareDepositPermitSignature(params) {
|
|
|
582
573
|
if (prefetchedDecimals !== void 0) {
|
|
583
574
|
resolvedDecimals = prefetchedDecimals;
|
|
584
575
|
} else {
|
|
585
|
-
const assets = await chunkCK3BIPWI_js.
|
|
576
|
+
const assets = await chunkCK3BIPWI_js.getAssetsFromCache({ address: depositToken });
|
|
586
577
|
if (assets.length === 0) {
|
|
587
578
|
throw new chunkCK3BIPWI_js.APIError(
|
|
588
579
|
`Asset metadata not found for token ${depositToken}`,
|
|
@@ -603,9 +594,9 @@ async function prepareDepositPermitSignature(params) {
|
|
|
603
594
|
const message = {
|
|
604
595
|
owner: recipientAddress,
|
|
605
596
|
spender: communityCodeDepositorAddress,
|
|
606
|
-
value,
|
|
607
|
-
nonce: resolvedNonce,
|
|
608
|
-
deadline: permitDeadline
|
|
597
|
+
value: value.toString(),
|
|
598
|
+
nonce: resolvedNonce.toString(),
|
|
599
|
+
deadline: permitDeadline.toString()
|
|
609
600
|
};
|
|
610
601
|
return {
|
|
611
602
|
domain,
|
|
@@ -700,7 +691,7 @@ async function prepareDepositWithPermitTxData(params) {
|
|
|
700
691
|
);
|
|
701
692
|
}
|
|
702
693
|
let asset = null;
|
|
703
|
-
const assets = await chunkCK3BIPWI_js.
|
|
694
|
+
const assets = await chunkCK3BIPWI_js.getAssetsFromCache({ address: depositToken });
|
|
704
695
|
if (assets.length > 0) {
|
|
705
696
|
asset = assets.find((a) => a.chains.includes(normalizedChainId)) || assets[0] || null;
|
|
706
697
|
}
|
|
@@ -722,7 +713,7 @@ async function prepareDepositWithPermitTxData(params) {
|
|
|
722
713
|
}
|
|
723
714
|
const communityCodeDepositorAddress = vault.vault.communityCodeDepositorAddress;
|
|
724
715
|
const accountantAddress = vault.vault.accountantAddress;
|
|
725
|
-
const depositAssetAddress =
|
|
716
|
+
const depositAssetAddress = depositToken;
|
|
726
717
|
if (!communityCodeDepositorAddress) {
|
|
727
718
|
throw new chunkCK3BIPWI_js.APIError(
|
|
728
719
|
`CommunityCodeDepositor contract address not found for vault ${vault.id}`,
|
|
@@ -753,19 +744,10 @@ async function prepareDepositWithPermitTxData(params) {
|
|
|
753
744
|
);
|
|
754
745
|
}
|
|
755
746
|
const depositAmountAsBigInt = viem.parseUnits(depositAmount, asset.decimals);
|
|
756
|
-
const vaultSharesAssets = await chunkCK3BIPWI_js.fetchSupportedAssets({
|
|
757
|
-
address: vault.vault.boringVaultAddress
|
|
758
|
-
});
|
|
759
|
-
if (vaultSharesAssets.length === 0) {
|
|
760
|
-
throw new chunkCK3BIPWI_js.APIError(
|
|
761
|
-
`Vault shares token not found in supported assets: ${vault.vault.boringVaultAddress}`,
|
|
762
|
-
{ endpoint: "prepareDepositWithPermitTxData" }
|
|
763
|
-
);
|
|
764
|
-
}
|
|
765
747
|
const minimumMint = calculateMinimumMint(
|
|
766
748
|
depositAmountAsBigInt,
|
|
767
749
|
rateInQuoteResult.result,
|
|
768
|
-
|
|
750
|
+
asset.decimals,
|
|
769
751
|
slippage
|
|
770
752
|
);
|
|
771
753
|
return {
|
|
@@ -828,7 +810,7 @@ async function prepareDepositAuthorization(params) {
|
|
|
828
810
|
{ endpoint: "prepareDepositAuthorization" }
|
|
829
811
|
);
|
|
830
812
|
}
|
|
831
|
-
const tokenInfo = await
|
|
813
|
+
const tokenInfo = await chunkGRRN4KON_js.isDepositSpendApproved({
|
|
832
814
|
yieldType,
|
|
833
815
|
chainId: normalizedChainId,
|
|
834
816
|
depositAssetAddress: depositToken,
|
|
@@ -1016,16 +998,16 @@ async function prepareApproveWithdrawTxData({
|
|
|
1016
998
|
);
|
|
1017
999
|
}
|
|
1018
1000
|
const boringVaultAddress = config.vault.boringVaultAddress;
|
|
1019
|
-
const
|
|
1020
|
-
address:
|
|
1001
|
+
const asset = await chunkCK3BIPWI_js.getAssetsFromCache({
|
|
1002
|
+
address: wantAssetAddress
|
|
1021
1003
|
});
|
|
1022
|
-
if (
|
|
1004
|
+
if (!asset) {
|
|
1023
1005
|
throw new chunkCK3BIPWI_js.APIError(
|
|
1024
|
-
`
|
|
1006
|
+
`Asset not found in supported assets: ${wantAssetAddress}`,
|
|
1025
1007
|
{ endpoint: "prepareApproveWithdrawToken" }
|
|
1026
1008
|
);
|
|
1027
1009
|
}
|
|
1028
|
-
const withdrawAmountAsBigInt = withdrawAmount ? viem.parseUnits(withdrawAmount,
|
|
1010
|
+
const withdrawAmountAsBigInt = withdrawAmount ? viem.parseUnits(withdrawAmount, asset[0].decimals) : chunkCK3BIPWI_js.DEFAULT_APPROVAL_AMOUNT;
|
|
1029
1011
|
return {
|
|
1030
1012
|
abi: chunk4ZYCWOFI_js.BoringVaultAbi,
|
|
1031
1013
|
address: boringVaultAddress,
|
|
@@ -1492,19 +1474,19 @@ Object.defineProperty(exports, "YieldType", {
|
|
|
1492
1474
|
});
|
|
1493
1475
|
Object.defineProperty(exports, "getDepositExchangeRate", {
|
|
1494
1476
|
enumerable: true,
|
|
1495
|
-
get: function () { return
|
|
1477
|
+
get: function () { return chunkGRRN4KON_js.getDepositExchangeRate; }
|
|
1496
1478
|
});
|
|
1497
1479
|
Object.defineProperty(exports, "getWithdrawExchangeRate", {
|
|
1498
1480
|
enumerable: true,
|
|
1499
|
-
get: function () { return
|
|
1481
|
+
get: function () { return chunkGRRN4KON_js.getWithdrawExchangeRate; }
|
|
1500
1482
|
});
|
|
1501
1483
|
Object.defineProperty(exports, "isDepositSpendApproved", {
|
|
1502
1484
|
enumerable: true,
|
|
1503
|
-
get: function () { return
|
|
1485
|
+
get: function () { return chunkGRRN4KON_js.isDepositSpendApproved; }
|
|
1504
1486
|
});
|
|
1505
1487
|
Object.defineProperty(exports, "isWithdrawalSpendApproved", {
|
|
1506
1488
|
enumerable: true,
|
|
1507
|
-
get: function () { return
|
|
1489
|
+
get: function () { return chunkGRRN4KON_js.isWithdrawalSpendApproved; }
|
|
1508
1490
|
});
|
|
1509
1491
|
Object.defineProperty(exports, "APIError", {
|
|
1510
1492
|
enumerable: true,
|