@paxoslabs/amplify-sdk 0.0.1-alpha.1

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.
Files changed (80) hide show
  1. package/CHANGELOG.md +112 -0
  2. package/LICENSE +28 -0
  3. package/README.md +533 -0
  4. package/dist/amplify-sdk-api-B5hBTGrB.d.ts +258 -0
  5. package/dist/amplify-sdk-api-DPrRhynk.d.mts +258 -0
  6. package/dist/chunk-3I3PYX2F.js +45 -0
  7. package/dist/chunk-3I3PYX2F.js.map +1 -0
  8. package/dist/chunk-7RWWVUHP.mjs +39 -0
  9. package/dist/chunk-7RWWVUHP.mjs.map +1 -0
  10. package/dist/chunk-AFWUOS3M.js +15 -0
  11. package/dist/chunk-AFWUOS3M.js.map +1 -0
  12. package/dist/chunk-BDXS57YH.js +828 -0
  13. package/dist/chunk-BDXS57YH.js.map +1 -0
  14. package/dist/chunk-FYNPQXCR.mjs +46 -0
  15. package/dist/chunk-FYNPQXCR.mjs.map +1 -0
  16. package/dist/chunk-GE2VQUPP.mjs +228 -0
  17. package/dist/chunk-GE2VQUPP.mjs.map +1 -0
  18. package/dist/chunk-ICKDAKVS.js +16 -0
  19. package/dist/chunk-ICKDAKVS.js.map +1 -0
  20. package/dist/chunk-ISO6Z7LD.mjs +809 -0
  21. package/dist/chunk-ISO6Z7LD.mjs.map +1 -0
  22. package/dist/chunk-ITB7FXG4.js +14 -0
  23. package/dist/chunk-ITB7FXG4.js.map +1 -0
  24. package/dist/chunk-J3662HYT.mjs +29 -0
  25. package/dist/chunk-J3662HYT.mjs.map +1 -0
  26. package/dist/chunk-JLXNOGZB.js +2061 -0
  27. package/dist/chunk-JLXNOGZB.js.map +1 -0
  28. package/dist/chunk-O5P6SP2O.js +233 -0
  29. package/dist/chunk-O5P6SP2O.js.map +1 -0
  30. package/dist/chunk-R663BFAZ.mjs +14 -0
  31. package/dist/chunk-R663BFAZ.mjs.map +1 -0
  32. package/dist/chunk-RUIAH5HY.js +32 -0
  33. package/dist/chunk-RUIAH5HY.js.map +1 -0
  34. package/dist/chunk-SIR2TCAR.mjs +13 -0
  35. package/dist/chunk-SIR2TCAR.mjs.map +1 -0
  36. package/dist/chunk-XXHRCCZS.mjs +11 -0
  37. package/dist/chunk-XXHRCCZS.mjs.map +1 -0
  38. package/dist/chunk-ZSFIOWWT.js +49 -0
  39. package/dist/chunk-ZSFIOWWT.js.map +1 -0
  40. package/dist/chunk-ZZBZIDZP.mjs +2050 -0
  41. package/dist/chunk-ZZBZIDZP.mjs.map +1 -0
  42. package/dist/config-B-u3VqEX.d.mts +21 -0
  43. package/dist/config-B-u3VqEX.d.ts +21 -0
  44. package/dist/config-BQynVNDC.d.mts +101 -0
  45. package/dist/config-BQynVNDC.d.ts +101 -0
  46. package/dist/core.d.mts +152 -0
  47. package/dist/core.d.ts +152 -0
  48. package/dist/core.js +187 -0
  49. package/dist/core.js.map +1 -0
  50. package/dist/core.mjs +150 -0
  51. package/dist/core.mjs.map +1 -0
  52. package/dist/display.d.mts +25 -0
  53. package/dist/display.d.ts +25 -0
  54. package/dist/display.js +124 -0
  55. package/dist/display.js.map +1 -0
  56. package/dist/display.mjs +105 -0
  57. package/dist/display.mjs.map +1 -0
  58. package/dist/exchange-rate-CRA_CMaX.d.mts +65 -0
  59. package/dist/exchange-rate-D3_FVgqa.d.ts +65 -0
  60. package/dist/index.d.mts +3236 -0
  61. package/dist/index.d.ts +3236 -0
  62. package/dist/index.js +1115 -0
  63. package/dist/index.js.map +1 -0
  64. package/dist/index.mjs +1047 -0
  65. package/dist/index.mjs.map +1 -0
  66. package/dist/utils.d.mts +111 -0
  67. package/dist/utils.d.ts +111 -0
  68. package/dist/utils.js +51 -0
  69. package/dist/utils.js.map +1 -0
  70. package/dist/utils.mjs +17 -0
  71. package/dist/utils.mjs.map +1 -0
  72. package/dist/vault-config-BNzhv3QV.d.ts +15 -0
  73. package/dist/vault-config-BjSE7oL8.d.mts +15 -0
  74. package/dist/vaults.d.mts +6 -0
  75. package/dist/vaults.d.ts +6 -0
  76. package/dist/vaults.js +13 -0
  77. package/dist/vaults.js.map +1 -0
  78. package/dist/vaults.mjs +4 -0
  79. package/dist/vaults.mjs.map +1 -0
  80. package/package.json +142 -0
@@ -0,0 +1,152 @@
1
+ import { Address } from 'viem';
2
+ export { Address } from 'viem';
3
+ import { C as ChainId } from './vault-config-BjSE7oL8.mjs';
4
+ export { f as fetchVaultConfig, t as toChainId } from './vault-config-BjSE7oL8.mjs';
5
+ import './config-BQynVNDC.mjs';
6
+
7
+ type AccountantBaseProps = {
8
+ accountantAddress: Address;
9
+ chainId: ChainId;
10
+ };
11
+ type RateInQuoteWithAssetDecimalsProps = AccountantBaseProps & {
12
+ assetAddress: Address;
13
+ };
14
+ declare const getRateInQuoteWithAssetDecimals: ({ assetAddress, accountantAddress, chainId, }: RateInQuoteWithAssetDecimalsProps) => Promise<[{
15
+ error: Error;
16
+ result?: undefined;
17
+ status: "failure";
18
+ } | {
19
+ error?: undefined;
20
+ result: number;
21
+ status: "success";
22
+ }, {
23
+ error?: undefined;
24
+ result: bigint;
25
+ status: "success";
26
+ } | {
27
+ error: Error;
28
+ result?: undefined;
29
+ status: "failure";
30
+ }]>;
31
+
32
+ type AllowanceProps = {
33
+ tokenAddress: Address;
34
+ spenderAddress: Address;
35
+ userAddress: Address;
36
+ chainId: ChainId;
37
+ };
38
+ declare function getVaultAllowance({ tokenAddress, spenderAddress, userAddress, chainId, }: AllowanceProps): Promise<bigint>;
39
+ type TotalSupplyProps = {
40
+ tokenAddress: Address;
41
+ chainId: ChainId;
42
+ };
43
+ declare function getTotalSupply({ tokenAddress, chainId, }: TotalSupplyProps): Promise<bigint>;
44
+
45
+ interface GetEthPriceProps {
46
+ chainId: ChainId;
47
+ }
48
+ declare function getEthPrice({ chainId, }: GetEthPriceProps): Promise<bigint>;
49
+
50
+ interface GetErc20BalanceParams {
51
+ chainId: ChainId;
52
+ tokenAddress: Address;
53
+ userAddress: Address;
54
+ }
55
+ declare const getErc20Balance: ({ chainId, tokenAddress, userAddress, }: GetErc20BalanceParams) => Promise<bigint>;
56
+ interface GetErc20DecimalsParams {
57
+ chainId: ChainId;
58
+ tokenAddress: Address;
59
+ }
60
+ declare const getErc20Decimals: ({ chainId, tokenAddress, }: GetErc20DecimalsParams) => Promise<number>;
61
+ interface GetErc20AllowanceParams {
62
+ chainId: ChainId;
63
+ tokenAddress: Address;
64
+ userAddress: Address;
65
+ spenderAddress: Address;
66
+ }
67
+ declare const getErc20Allowance: ({ chainId, tokenAddress, userAddress, spenderAddress, }: GetErc20AllowanceParams) => Promise<bigint>;
68
+
69
+ type PausedStatusProps = {
70
+ accountantAddress: Address;
71
+ tellerAddress: Address;
72
+ chainId: ChainId;
73
+ };
74
+ declare const getPausedStates: ({ accountantAddress, tellerAddress, chainId, }: PausedStatusProps) => Promise<[{
75
+ error: Error;
76
+ result?: undefined;
77
+ status: "failure";
78
+ } | {
79
+ error?: undefined;
80
+ result: boolean;
81
+ status: "success";
82
+ }, {
83
+ error: Error;
84
+ result?: undefined;
85
+ status: "failure";
86
+ } | {
87
+ error?: undefined;
88
+ result: readonly [`0x${string}`, bigint, bigint, bigint, number, number, bigint, boolean, number, number];
89
+ status: "success";
90
+ }]>;
91
+
92
+ /**
93
+ * Gets the slippage value for a specific asset in a vault
94
+ * @param chainId The chain ID
95
+ * @param vaultAddress The boring vault address
96
+ * @param tokenAddress The token address
97
+ * @param defaultSlippage Optional default slippage value if none is found (defaults to 0)
98
+ * @returns Promise<number> The slippage value
99
+ * @throws {AssetSlippageError} If there's an error fetching or processing the slippage data
100
+ */
101
+ declare function getAssetSlippage(chainId: ChainId, vaultAddress: Address, tokenAddress: Address, defaultSlippage?: number): Promise<number>;
102
+
103
+ /**
104
+ * @fileoverview Functions for interacting with the Teller contract
105
+ */
106
+
107
+ /**
108
+ * Arguments required by the bridge contract for cross-chain transfers
109
+ * @interface BridgeData
110
+ * @property {number} chainSelector - Unique identifier for the destination chain
111
+ * @property {Address} destinationChainReceiver - Address that will receive the bridged tokens
112
+ * @property {Address} bridgeFeeToken - Token used to pay the bridge fee
113
+ * @property {bigint} messageGas - Amount of gas allocated for the cross-chain message
114
+ * @property {`0x${string}`} data - Additional data required for the bridge operation (hex encoded)
115
+ */
116
+ type BridgeData = {
117
+ chainSelector: number;
118
+ destinationChainReceiver: Address;
119
+ bridgeFeeToken: Address;
120
+ messageGas: bigint;
121
+ data: `0x${string}`;
122
+ };
123
+ type GetPreviewFeeProps = {
124
+ shareAmount: bigint;
125
+ bridgeData: BridgeData;
126
+ contractAddress: Address;
127
+ chainId: ChainId;
128
+ };
129
+ declare const getPreviewFee: ({ shareAmount, bridgeData, contractAddress, chainId, }: GetPreviewFeeProps) => Promise<bigint>;
130
+
131
+ interface WithdrawAssetsResponse {
132
+ [chainId: string]: {
133
+ [vaultAddress: string]: {
134
+ [tokenAddress: string]: number;
135
+ };
136
+ };
137
+ }
138
+ /**
139
+ * Interface for optional parameters when fetching withdraw assets
140
+ */
141
+ interface FetchWithdrawAssetsParams {
142
+ chainId?: ChainId;
143
+ vaultAddress?: Address;
144
+ }
145
+ /**
146
+ * Fetches withdraw assets configuration from the API
147
+ * @param params Optional parameters for chainId and vaultAddress
148
+ * @returns Promise<WithdrawAssetsResponse>
149
+ */
150
+ declare function fetchWithdrawAssets(params?: FetchWithdrawAssetsParams): Promise<WithdrawAssetsResponse>;
151
+
152
+ export { type BridgeData, ChainId, fetchWithdrawAssets, getAssetSlippage, getErc20Allowance, getErc20Balance, getErc20Decimals, getEthPrice, getPausedStates, getPreviewFee, getRateInQuoteWithAssetDecimals, getTotalSupply, getVaultAllowance };
package/dist/core.d.ts ADDED
@@ -0,0 +1,152 @@
1
+ import { Address } from 'viem';
2
+ export { Address } from 'viem';
3
+ import { C as ChainId } from './vault-config-BNzhv3QV.js';
4
+ export { f as fetchVaultConfig, t as toChainId } from './vault-config-BNzhv3QV.js';
5
+ import './config-BQynVNDC.js';
6
+
7
+ type AccountantBaseProps = {
8
+ accountantAddress: Address;
9
+ chainId: ChainId;
10
+ };
11
+ type RateInQuoteWithAssetDecimalsProps = AccountantBaseProps & {
12
+ assetAddress: Address;
13
+ };
14
+ declare const getRateInQuoteWithAssetDecimals: ({ assetAddress, accountantAddress, chainId, }: RateInQuoteWithAssetDecimalsProps) => Promise<[{
15
+ error: Error;
16
+ result?: undefined;
17
+ status: "failure";
18
+ } | {
19
+ error?: undefined;
20
+ result: number;
21
+ status: "success";
22
+ }, {
23
+ error?: undefined;
24
+ result: bigint;
25
+ status: "success";
26
+ } | {
27
+ error: Error;
28
+ result?: undefined;
29
+ status: "failure";
30
+ }]>;
31
+
32
+ type AllowanceProps = {
33
+ tokenAddress: Address;
34
+ spenderAddress: Address;
35
+ userAddress: Address;
36
+ chainId: ChainId;
37
+ };
38
+ declare function getVaultAllowance({ tokenAddress, spenderAddress, userAddress, chainId, }: AllowanceProps): Promise<bigint>;
39
+ type TotalSupplyProps = {
40
+ tokenAddress: Address;
41
+ chainId: ChainId;
42
+ };
43
+ declare function getTotalSupply({ tokenAddress, chainId, }: TotalSupplyProps): Promise<bigint>;
44
+
45
+ interface GetEthPriceProps {
46
+ chainId: ChainId;
47
+ }
48
+ declare function getEthPrice({ chainId, }: GetEthPriceProps): Promise<bigint>;
49
+
50
+ interface GetErc20BalanceParams {
51
+ chainId: ChainId;
52
+ tokenAddress: Address;
53
+ userAddress: Address;
54
+ }
55
+ declare const getErc20Balance: ({ chainId, tokenAddress, userAddress, }: GetErc20BalanceParams) => Promise<bigint>;
56
+ interface GetErc20DecimalsParams {
57
+ chainId: ChainId;
58
+ tokenAddress: Address;
59
+ }
60
+ declare const getErc20Decimals: ({ chainId, tokenAddress, }: GetErc20DecimalsParams) => Promise<number>;
61
+ interface GetErc20AllowanceParams {
62
+ chainId: ChainId;
63
+ tokenAddress: Address;
64
+ userAddress: Address;
65
+ spenderAddress: Address;
66
+ }
67
+ declare const getErc20Allowance: ({ chainId, tokenAddress, userAddress, spenderAddress, }: GetErc20AllowanceParams) => Promise<bigint>;
68
+
69
+ type PausedStatusProps = {
70
+ accountantAddress: Address;
71
+ tellerAddress: Address;
72
+ chainId: ChainId;
73
+ };
74
+ declare const getPausedStates: ({ accountantAddress, tellerAddress, chainId, }: PausedStatusProps) => Promise<[{
75
+ error: Error;
76
+ result?: undefined;
77
+ status: "failure";
78
+ } | {
79
+ error?: undefined;
80
+ result: boolean;
81
+ status: "success";
82
+ }, {
83
+ error: Error;
84
+ result?: undefined;
85
+ status: "failure";
86
+ } | {
87
+ error?: undefined;
88
+ result: readonly [`0x${string}`, bigint, bigint, bigint, number, number, bigint, boolean, number, number];
89
+ status: "success";
90
+ }]>;
91
+
92
+ /**
93
+ * Gets the slippage value for a specific asset in a vault
94
+ * @param chainId The chain ID
95
+ * @param vaultAddress The boring vault address
96
+ * @param tokenAddress The token address
97
+ * @param defaultSlippage Optional default slippage value if none is found (defaults to 0)
98
+ * @returns Promise<number> The slippage value
99
+ * @throws {AssetSlippageError} If there's an error fetching or processing the slippage data
100
+ */
101
+ declare function getAssetSlippage(chainId: ChainId, vaultAddress: Address, tokenAddress: Address, defaultSlippage?: number): Promise<number>;
102
+
103
+ /**
104
+ * @fileoverview Functions for interacting with the Teller contract
105
+ */
106
+
107
+ /**
108
+ * Arguments required by the bridge contract for cross-chain transfers
109
+ * @interface BridgeData
110
+ * @property {number} chainSelector - Unique identifier for the destination chain
111
+ * @property {Address} destinationChainReceiver - Address that will receive the bridged tokens
112
+ * @property {Address} bridgeFeeToken - Token used to pay the bridge fee
113
+ * @property {bigint} messageGas - Amount of gas allocated for the cross-chain message
114
+ * @property {`0x${string}`} data - Additional data required for the bridge operation (hex encoded)
115
+ */
116
+ type BridgeData = {
117
+ chainSelector: number;
118
+ destinationChainReceiver: Address;
119
+ bridgeFeeToken: Address;
120
+ messageGas: bigint;
121
+ data: `0x${string}`;
122
+ };
123
+ type GetPreviewFeeProps = {
124
+ shareAmount: bigint;
125
+ bridgeData: BridgeData;
126
+ contractAddress: Address;
127
+ chainId: ChainId;
128
+ };
129
+ declare const getPreviewFee: ({ shareAmount, bridgeData, contractAddress, chainId, }: GetPreviewFeeProps) => Promise<bigint>;
130
+
131
+ interface WithdrawAssetsResponse {
132
+ [chainId: string]: {
133
+ [vaultAddress: string]: {
134
+ [tokenAddress: string]: number;
135
+ };
136
+ };
137
+ }
138
+ /**
139
+ * Interface for optional parameters when fetching withdraw assets
140
+ */
141
+ interface FetchWithdrawAssetsParams {
142
+ chainId?: ChainId;
143
+ vaultAddress?: Address;
144
+ }
145
+ /**
146
+ * Fetches withdraw assets configuration from the API
147
+ * @param params Optional parameters for chainId and vaultAddress
148
+ * @returns Promise<WithdrawAssetsResponse>
149
+ */
150
+ declare function fetchWithdrawAssets(params?: FetchWithdrawAssetsParams): Promise<WithdrawAssetsResponse>;
151
+
152
+ export { type BridgeData, ChainId, fetchWithdrawAssets, getAssetSlippage, getErc20Allowance, getErc20Balance, getErc20Decimals, getEthPrice, getPausedStates, getPreviewFee, getRateInQuoteWithAssetDecimals, getTotalSupply, getVaultAllowance };
package/dist/core.js ADDED
@@ -0,0 +1,187 @@
1
+ 'use strict';
2
+
3
+ var chunkITB7FXG4_js = require('./chunk-ITB7FXG4.js');
4
+ var chunkZSFIOWWT_js = require('./chunk-ZSFIOWWT.js');
5
+ var chunkJLXNOGZB_js = require('./chunk-JLXNOGZB.js');
6
+ var chunkRUIAH5HY_js = require('./chunk-RUIAH5HY.js');
7
+ var chunkBDXS57YH_js = require('./chunk-BDXS57YH.js');
8
+ var viem = require('viem');
9
+
10
+ async function getVaultAllowance({
11
+ tokenAddress,
12
+ spenderAddress,
13
+ userAddress,
14
+ chainId
15
+ }) {
16
+ const client = await chunkJLXNOGZB_js.getClient(chainId);
17
+ const allowance = await client.readContract({
18
+ abi: viem.erc20Abi,
19
+ address: tokenAddress,
20
+ functionName: "allowance",
21
+ args: [userAddress, spenderAddress]
22
+ });
23
+ return allowance;
24
+ }
25
+ async function getTotalSupply({
26
+ tokenAddress,
27
+ chainId
28
+ }) {
29
+ const client = await chunkJLXNOGZB_js.getClient(chainId);
30
+ const totalSupply = await client.readContract({
31
+ abi: viem.erc20Abi,
32
+ address: tokenAddress,
33
+ functionName: "totalSupply"
34
+ });
35
+ return totalSupply;
36
+ }
37
+
38
+ // src/abi/chainlink-abi.ts
39
+ var ChainlinkAbi = [
40
+ {
41
+ type: "function",
42
+ name: "latestRoundData",
43
+ inputs: [],
44
+ outputs: [
45
+ {
46
+ name: "roundId",
47
+ type: "uint80",
48
+ internalType: "uint80"
49
+ },
50
+ {
51
+ name: "answer",
52
+ type: "int256",
53
+ internalType: "int256"
54
+ },
55
+ {
56
+ name: "startedAt",
57
+ type: "uint256",
58
+ internalType: "uint256"
59
+ },
60
+ {
61
+ name: "updatedAt",
62
+ type: "uint256",
63
+ internalType: "uint256"
64
+ },
65
+ {
66
+ name: "answeredInRound",
67
+ type: "uint80",
68
+ internalType: "uint80"
69
+ }
70
+ ],
71
+ stateMutability: "view"
72
+ }
73
+ ];
74
+
75
+ // src/api/chainlink.ts
76
+ async function getEthPrice({
77
+ chainId
78
+ }) {
79
+ const client = await chunkJLXNOGZB_js.getClient(chainId);
80
+ const priceData = await client.readContract({
81
+ abi: ChainlinkAbi,
82
+ address: chunkBDXS57YH_js.CHAINLINK_ADDRESS,
83
+ functionName: "latestRoundData",
84
+ args: []
85
+ });
86
+ if (!priceData || !priceData[1]) {
87
+ throw new Error("Failed to fetch ETH price from Chainlink");
88
+ }
89
+ return priceData[1];
90
+ }
91
+
92
+ // src/api/withdraw-assets.ts
93
+ var assetsCache = null;
94
+ function constructUrl(params) {
95
+ const withdrawAssetsUrl = `${chunkBDXS57YH_js.NUCLEUS_BASE_URL}/withdraw-assets`;
96
+ if (!params) return withdrawAssetsUrl;
97
+ const queryParams = new URLSearchParams();
98
+ if (params.chainId) queryParams.append("chainId", params.chainId.toString());
99
+ if (params.vaultAddress)
100
+ queryParams.append("vaultAddress", params.vaultAddress.toLowerCase());
101
+ return `${withdrawAssetsUrl}?${queryParams.toString()}`;
102
+ }
103
+ async function fetchWithdrawAssets(params) {
104
+ if (!params && assetsCache) {
105
+ return assetsCache;
106
+ }
107
+ try {
108
+ const url = constructUrl(params);
109
+ const response = await fetch(url);
110
+ if (!response.ok) {
111
+ throw new Error(`HTTP error! status: ${response.status}`);
112
+ }
113
+ const data = await response.json();
114
+ if (!params) {
115
+ assetsCache = data;
116
+ }
117
+ return data;
118
+ } catch (error) {
119
+ throw new Error(
120
+ `An unknown error occurred while fetching withdraw assets: ${error instanceof Error ? error.message : String(error)}`
121
+ );
122
+ }
123
+ }
124
+
125
+ // src/api/solver-slippage.ts
126
+ async function getAssetSlippage(chainId, vaultAddress, tokenAddress, defaultSlippage = chunkITB7FXG4_js.DEFAULT_SLIPPAGE_BPS) {
127
+ try {
128
+ const withdrawAssets = await fetchWithdrawAssets();
129
+ if (!withdrawAssets) {
130
+ return defaultSlippage;
131
+ }
132
+ if (!withdrawAssets[chainId.toString()]) {
133
+ return defaultSlippage;
134
+ }
135
+ if (!withdrawAssets[chainId.toString()][vaultAddress.toLowerCase()]) {
136
+ return defaultSlippage;
137
+ }
138
+ if (!withdrawAssets[chainId.toString()][vaultAddress.toLowerCase()][tokenAddress.toLowerCase()]) {
139
+ return defaultSlippage;
140
+ }
141
+ return withdrawAssets[chainId.toString()][vaultAddress.toLowerCase()][tokenAddress.toLowerCase()];
142
+ } catch (error) {
143
+ throw new Error(
144
+ `Error fetching asset slippage for chain ${chainId}: ${error instanceof Error ? error.message : String(error)}`
145
+ );
146
+ }
147
+ }
148
+
149
+ Object.defineProperty(exports, "getPausedStates", {
150
+ enumerable: true,
151
+ get: function () { return chunkZSFIOWWT_js.getPausedStates; }
152
+ });
153
+ Object.defineProperty(exports, "getPreviewFee", {
154
+ enumerable: true,
155
+ get: function () { return chunkZSFIOWWT_js.getPreviewFee; }
156
+ });
157
+ Object.defineProperty(exports, "getErc20Allowance", {
158
+ enumerable: true,
159
+ get: function () { return chunkJLXNOGZB_js.getErc20Allowance; }
160
+ });
161
+ Object.defineProperty(exports, "getErc20Balance", {
162
+ enumerable: true,
163
+ get: function () { return chunkJLXNOGZB_js.getErc20Balance; }
164
+ });
165
+ Object.defineProperty(exports, "getErc20Decimals", {
166
+ enumerable: true,
167
+ get: function () { return chunkJLXNOGZB_js.getErc20Decimals; }
168
+ });
169
+ Object.defineProperty(exports, "getRateInQuoteWithAssetDecimals", {
170
+ enumerable: true,
171
+ get: function () { return chunkJLXNOGZB_js.getRateInQuoteWithAssetDecimals; }
172
+ });
173
+ Object.defineProperty(exports, "fetchVaultConfig", {
174
+ enumerable: true,
175
+ get: function () { return chunkRUIAH5HY_js.fetchVaultConfig; }
176
+ });
177
+ Object.defineProperty(exports, "toChainId", {
178
+ enumerable: true,
179
+ get: function () { return chunkRUIAH5HY_js.toChainId; }
180
+ });
181
+ exports.fetchWithdrawAssets = fetchWithdrawAssets;
182
+ exports.getAssetSlippage = getAssetSlippage;
183
+ exports.getEthPrice = getEthPrice;
184
+ exports.getTotalSupply = getTotalSupply;
185
+ exports.getVaultAllowance = getVaultAllowance;
186
+ //# sourceMappingURL=core.js.map
187
+ //# sourceMappingURL=core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/api/boring-vault.ts","../src/abi/chainlink-abi.ts","../src/api/chainlink.ts","../src/api/withdraw-assets.ts","../src/api/solver-slippage.ts"],"names":["getClient","erc20Abi","CHAINLINK_ADDRESS","NUCLEUS_BASE_URL","DEFAULT_SLIPPAGE_BPS"],"mappings":";;;;;;;;;AAWA,eAAsB,iBAAA,CAAkB;AAAA,EACtC,YAAA;AAAA,EACA,cAAA;AAAA,EACA,WAAA;AAAA,EACA;AACF,CAAA,EAAoC;AAClC,EAAA,MAAM,MAAA,GAAS,MAAMA,0BAAA,CAAU,OAAO,CAAA;AACtC,EAAA,MAAM,SAAA,GAAY,MAAM,MAAA,CAAO,YAAA,CAAa;AAAA,IAC1C,GAAA,EAAKC,aAAA;AAAA,IACL,OAAA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f,CAAA;AAAA,EACF,SAAS,KAAA,EAAO;AAEd,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,wCAAA,EAA2C,OAAO,CAAA,EAAA,EAChD,KAAA,YAAiB,QAAQ,KAAA,CAAM,OAAA,GAAU,MAAA,CAAO,KAAK,CACvD,CAAA;AAAA,KACF;AAAA,EACF;AACF","file":"core.js","sourcesContent":["import { type Address, erc20Abi } from \"viem\";\nimport { getClient } from \"../lib/viem/client\";\nimport type { ChainId } from \"./vault-config\";\n\ntype AllowanceProps = {\n tokenAddress: Address;\n spenderAddress: Address;\n userAddress: Address;\n chainId: ChainId;\n};\n\nexport async function getVaultAllowance({\n tokenAddress,\n spenderAddress,\n userAddress,\n chainId,\n}: AllowanceProps): Promise<bigint> {\n const client = await getClient(chainId);\n const allowance = await client.readContract({\n abi: erc20Abi,\n address: tokenAddress,\n functionName: \"allowance\",\n args: [userAddress, spenderAddress],\n });\n\n return allowance;\n}\n\ntype TotalSupplyProps = {\n tokenAddress: Address;\n chainId: ChainId;\n};\n\nexport async function getTotalSupply({\n tokenAddress,\n chainId,\n}: TotalSupplyProps): Promise<bigint> {\n const client = await getClient(chainId);\n const totalSupply = await client.readContract({\n abi: erc20Abi,\n address: tokenAddress,\n functionName: \"totalSupply\",\n });\n\n return totalSupply;\n}\n","export const ChainlinkAbi = [\n {\n type: \"function\",\n name: \"latestRoundData\",\n inputs: [],\n outputs: [\n {\n name: \"roundId\",\n type: \"uint80\",\n internalType: \"uint80\",\n },\n {\n name: \"answer\",\n type: \"int256\",\n internalType: \"int256\",\n },\n {\n name: \"startedAt\",\n type: \"uint256\",\n internalType: \"uint256\",\n },\n {\n name: \"updatedAt\",\n type: \"uint256\",\n internalType: \"uint256\",\n },\n {\n name: \"answeredInRound\",\n type: \"uint80\",\n internalType: \"uint80\",\n },\n ],\n stateMutability: \"view\",\n },\n];\n","import { ChainlinkAbi } from \"../abi/chainlink-abi\";\nimport { CHAINLINK_ADDRESS } from \"../constants\";\nimport { getClient } from \"../lib/viem/client\";\nimport type { ChainId } from \"./vault-config\";\n\ninterface GetEthPriceProps {\n chainId: ChainId;\n}\n\nexport async function getEthPrice({\n chainId,\n}: GetEthPriceProps): Promise<bigint> {\n const client = await getClient(chainId);\n const priceData = (await client.readContract({\n abi: ChainlinkAbi,\n address: CHAINLINK_ADDRESS,\n functionName: \"latestRoundData\",\n args: [],\n })) as Array<bigint>;\n\n if (!priceData || !priceData[1]) {\n throw new Error(\"Failed to fetch ETH price from Chainlink\");\n }\n\n return priceData[1];\n}\n","import type { Address } from \"viem\";\nimport { NUCLEUS_BASE_URL } from \"../constants\";\nimport type { ChainId } from \"./vault-config\";\n\nexport interface WithdrawAssetsResponse {\n [chainId: string]: {\n [vaultAddress: string]: {\n [tokenAddress: string]: number;\n };\n };\n}\n\nlet assetsCache: WithdrawAssetsResponse | null = null;\n\n/**\n * Interface for optional parameters when fetching withdraw assets\n */\ninterface FetchWithdrawAssetsParams {\n chainId?: ChainId;\n vaultAddress?: Address;\n}\n\n/**\n * Constructs the URL with optional query parameters\n */\nfunction constructUrl(params?: FetchWithdrawAssetsParams): string {\n const withdrawAssetsUrl = `${NUCLEUS_BASE_URL}/withdraw-assets`;\n if (!params) return withdrawAssetsUrl;\n\n const queryParams = new URLSearchParams();\n if (params.chainId) queryParams.append(\"chainId\", params.chainId.toString());\n if (params.vaultAddress)\n queryParams.append(\"vaultAddress\", params.vaultAddress.toLowerCase());\n\n return `${withdrawAssetsUrl}?${queryParams.toString()}`;\n}\n\n/**\n * Fetches withdraw assets configuration from the API\n * @param params Optional parameters for chainId and vaultAddress\n * @returns Promise<WithdrawAssetsResponse>\n */\nasync function fetchWithdrawAssets(\n params?: FetchWithdrawAssetsParams\n): Promise<WithdrawAssetsResponse> {\n // If no specific params are provided and we have cached data, return it\n if (!params && assetsCache) {\n return assetsCache;\n }\n\n try {\n const url = constructUrl(params);\n const response = await fetch(url);\n\n if (!response.ok) {\n throw new Error(`HTTP error! status: ${response.status}`);\n }\n\n const data: WithdrawAssetsResponse = await response.json();\n\n // Only cache the full response (when no params are provided)\n if (!params) {\n assetsCache = data;\n }\n\n return data;\n } catch (error: unknown) {\n throw new Error(\n `An unknown error occurred while fetching withdraw assets: ${\n error instanceof Error ? error.message : String(error)\n }`\n );\n }\n}\n\n/**\n * Fetches withdraw assets for a specific chain\n * @param chainId The chain ID to fetch assets for\n * @returns Promise<WithdrawAssetsResponse[string]>\n */\nasync function fetchChainWithdrawAssets(\n chainId: ChainId\n): Promise<WithdrawAssetsResponse[string]> {\n const assets = await fetchWithdrawAssets({ chainId });\n return assets[chainId.toString()];\n}\n\n/**\n * Fetches withdraw assets for a specific vault on a chain\n * @param chainId The chain ID\n * @param vaultAddress The vault address\n * @returns Promise<WithdrawAssetsResponse[string][string]>\n */\nasync function fetchVaultWithdrawAssets(\n chainId: ChainId,\n vaultAddress: Address\n): Promise<WithdrawAssetsResponse[string][string]> {\n const assets = await fetchWithdrawAssets({ chainId, vaultAddress });\n return assets[chainId.toString()]?.[vaultAddress.toLowerCase()];\n}\n\n/**\n * Clears the assets cache\n */\nfunction clearAssetsCache(): void {\n assetsCache = null;\n}\n\nexport {\n clearAssetsCache,\n fetchChainWithdrawAssets,\n fetchVaultWithdrawAssets,\n fetchWithdrawAssets,\n type FetchWithdrawAssetsParams,\n};\n","import type { Address } from \"viem\";\nimport { DEFAULT_SLIPPAGE_BPS } from \"../constants/config\";\nimport type { ChainId } from \"./vault-config\";\nimport { fetchWithdrawAssets } from \"./withdraw-assets\";\n\n/**\n * Gets the slippage value for a specific asset in a vault\n * @param chainId The chain ID\n * @param vaultAddress The boring vault address\n * @param tokenAddress The token address\n * @param defaultSlippage Optional default slippage value if none is found (defaults to 0)\n * @returns Promise<number> The slippage value\n * @throws {AssetSlippageError} If there's an error fetching or processing the slippage data\n */\nexport async function getAssetSlippage(\n chainId: ChainId,\n vaultAddress: Address,\n tokenAddress: Address,\n defaultSlippage: number = DEFAULT_SLIPPAGE_BPS\n) {\n try {\n // Fetch withdraw assets data, using cache if available\n const withdrawAssets = await fetchWithdrawAssets();\n if (!withdrawAssets) {\n return defaultSlippage;\n }\n if (!withdrawAssets[chainId.toString()]) {\n return defaultSlippage;\n }\n if (!withdrawAssets[chainId.toString()][vaultAddress.toLowerCase()]) {\n return defaultSlippage;\n }\n if (\n !withdrawAssets[chainId.toString()][vaultAddress.toLowerCase()][\n tokenAddress.toLowerCase()\n ]\n ) {\n return defaultSlippage;\n }\n\n return withdrawAssets[chainId.toString()][vaultAddress.toLowerCase()][\n tokenAddress.toLowerCase()\n ];\n } catch (error) {\n // Re-throw with contextual information\n throw new Error(\n `Error fetching asset slippage for chain ${chainId}: ${\n error instanceof Error ? error.message : String(error)\n }`\n );\n }\n}\n"]}
package/dist/core.mjs ADDED
@@ -0,0 +1,150 @@
1
+ import { DEFAULT_SLIPPAGE_BPS } from './chunk-XXHRCCZS.mjs';
2
+ export { getPausedStates, getPreviewFee } from './chunk-FYNPQXCR.mjs';
3
+ import { getClient } from './chunk-ZZBZIDZP.mjs';
4
+ export { getErc20Allowance, getErc20Balance, getErc20Decimals, getRateInQuoteWithAssetDecimals } from './chunk-ZZBZIDZP.mjs';
5
+ export { fetchVaultConfig, toChainId } from './chunk-J3662HYT.mjs';
6
+ import { CHAINLINK_ADDRESS, NUCLEUS_BASE_URL } from './chunk-ISO6Z7LD.mjs';
7
+ import { erc20Abi } from 'viem';
8
+
9
+ async function getVaultAllowance({
10
+ tokenAddress,
11
+ spenderAddress,
12
+ userAddress,
13
+ chainId
14
+ }) {
15
+ const client = await getClient(chainId);
16
+ const allowance = await client.readContract({
17
+ abi: erc20Abi,
18
+ address: tokenAddress,
19
+ functionName: "allowance",
20
+ args: [userAddress, spenderAddress]
21
+ });
22
+ return allowance;
23
+ }
24
+ async function getTotalSupply({
25
+ tokenAddress,
26
+ chainId
27
+ }) {
28
+ const client = await getClient(chainId);
29
+ const totalSupply = await client.readContract({
30
+ abi: erc20Abi,
31
+ address: tokenAddress,
32
+ functionName: "totalSupply"
33
+ });
34
+ return totalSupply;
35
+ }
36
+
37
+ // src/abi/chainlink-abi.ts
38
+ var ChainlinkAbi = [
39
+ {
40
+ type: "function",
41
+ name: "latestRoundData",
42
+ inputs: [],
43
+ outputs: [
44
+ {
45
+ name: "roundId",
46
+ type: "uint80",
47
+ internalType: "uint80"
48
+ },
49
+ {
50
+ name: "answer",
51
+ type: "int256",
52
+ internalType: "int256"
53
+ },
54
+ {
55
+ name: "startedAt",
56
+ type: "uint256",
57
+ internalType: "uint256"
58
+ },
59
+ {
60
+ name: "updatedAt",
61
+ type: "uint256",
62
+ internalType: "uint256"
63
+ },
64
+ {
65
+ name: "answeredInRound",
66
+ type: "uint80",
67
+ internalType: "uint80"
68
+ }
69
+ ],
70
+ stateMutability: "view"
71
+ }
72
+ ];
73
+
74
+ // src/api/chainlink.ts
75
+ async function getEthPrice({
76
+ chainId
77
+ }) {
78
+ const client = await getClient(chainId);
79
+ const priceData = await client.readContract({
80
+ abi: ChainlinkAbi,
81
+ address: CHAINLINK_ADDRESS,
82
+ functionName: "latestRoundData",
83
+ args: []
84
+ });
85
+ if (!priceData || !priceData[1]) {
86
+ throw new Error("Failed to fetch ETH price from Chainlink");
87
+ }
88
+ return priceData[1];
89
+ }
90
+
91
+ // src/api/withdraw-assets.ts
92
+ var assetsCache = null;
93
+ function constructUrl(params) {
94
+ const withdrawAssetsUrl = `${NUCLEUS_BASE_URL}/withdraw-assets`;
95
+ if (!params) return withdrawAssetsUrl;
96
+ const queryParams = new URLSearchParams();
97
+ if (params.chainId) queryParams.append("chainId", params.chainId.toString());
98
+ if (params.vaultAddress)
99
+ queryParams.append("vaultAddress", params.vaultAddress.toLowerCase());
100
+ return `${withdrawAssetsUrl}?${queryParams.toString()}`;
101
+ }
102
+ async function fetchWithdrawAssets(params) {
103
+ if (!params && assetsCache) {
104
+ return assetsCache;
105
+ }
106
+ try {
107
+ const url = constructUrl(params);
108
+ const response = await fetch(url);
109
+ if (!response.ok) {
110
+ throw new Error(`HTTP error! status: ${response.status}`);
111
+ }
112
+ const data = await response.json();
113
+ if (!params) {
114
+ assetsCache = data;
115
+ }
116
+ return data;
117
+ } catch (error) {
118
+ throw new Error(
119
+ `An unknown error occurred while fetching withdraw assets: ${error instanceof Error ? error.message : String(error)}`
120
+ );
121
+ }
122
+ }
123
+
124
+ // src/api/solver-slippage.ts
125
+ async function getAssetSlippage(chainId, vaultAddress, tokenAddress, defaultSlippage = DEFAULT_SLIPPAGE_BPS) {
126
+ try {
127
+ const withdrawAssets = await fetchWithdrawAssets();
128
+ if (!withdrawAssets) {
129
+ return defaultSlippage;
130
+ }
131
+ if (!withdrawAssets[chainId.toString()]) {
132
+ return defaultSlippage;
133
+ }
134
+ if (!withdrawAssets[chainId.toString()][vaultAddress.toLowerCase()]) {
135
+ return defaultSlippage;
136
+ }
137
+ if (!withdrawAssets[chainId.toString()][vaultAddress.toLowerCase()][tokenAddress.toLowerCase()]) {
138
+ return defaultSlippage;
139
+ }
140
+ return withdrawAssets[chainId.toString()][vaultAddress.toLowerCase()][tokenAddress.toLowerCase()];
141
+ } catch (error) {
142
+ throw new Error(
143
+ `Error fetching asset slippage for chain ${chainId}: ${error instanceof Error ? error.message : String(error)}`
144
+ );
145
+ }
146
+ }
147
+
148
+ export { fetchWithdrawAssets, getAssetSlippage, getEthPrice, getTotalSupply, getVaultAllowance };
149
+ //# sourceMappingURL=core.mjs.map
150
+ //# sourceMappingURL=core.mjs.map