@lombard.finance/sdk 3.1.0 → 3.2.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.
Files changed (72) hide show
  1. package/README.md +59 -1
  2. package/dist/index.cjs +1 -1
  3. package/dist/index.js +73 -62
  4. package/dist/index2.cjs +62 -52
  5. package/dist/index2.cjs.map +1 -1
  6. package/dist/index2.js +8680 -12363
  7. package/dist/index2.js.map +1 -1
  8. package/package.json +6 -6
  9. package/src/api-functions/generateDepositBtcAddress/generateDepositBtcAddress.ts +4 -4
  10. package/src/api-functions/getDepositBtcAddress/getDepositBtcAddress.stories.tsx +8 -0
  11. package/src/api-functions/getDepositBtcAddress/getDepositBtcAddress.ts +3 -3
  12. package/src/api-functions/getDepositsByAddress/getDepositsByAddress.ts +7 -7
  13. package/src/api-functions/getUnstakesByAddress/getUnstakesByAddress.ts +5 -5
  14. package/src/api-functions/getUserStakeAndBakeSignature/getUserStakeAndBakeSignature.stories.tsx +8 -0
  15. package/src/bridge/abi/CCIP_BRIDGE_ADAPTER_ABI.json +704 -0
  16. package/src/bridge/abi/OFT_BRIDGE_ADAPTER_ABI.json +912 -0
  17. package/src/bridge/index.ts +11 -0
  18. package/src/bridge/lib/bridge.stories.tsx +89 -0
  19. package/src/bridge/lib/bridge.ts +101 -0
  20. package/src/bridge/lib/ccip-bridge.stories.tsx +90 -0
  21. package/src/bridge/lib/ccip-bridge.ts +163 -0
  22. package/src/bridge/lib/config.ts +338 -0
  23. package/src/bridge/lib/oft-bridge.stories.tsx +89 -0
  24. package/src/bridge/lib/oft-bridge.ts +212 -0
  25. package/src/common/api-config.ts +8 -2
  26. package/src/common/blockchain-identifier.ts +32 -5
  27. package/src/common/chains.ts +13 -1
  28. package/src/common/contract-info.ts +8 -0
  29. package/src/contract-functions/approveLBTC/approveLBTC.stories.tsx +1 -1
  30. package/src/contract-functions/approveLBTC/approveLBTC.ts +3 -2
  31. package/src/contract-functions/claimLBTC/claimLBTC.ts +3 -2
  32. package/src/contract-functions/getBasculeDepositStatus/getBasculeDepositStatus.ts +10 -4
  33. package/src/contract-functions/getLBTCMintingFee/getLBTCMintingFee.tsx +14 -11
  34. package/src/contract-functions/getLBTCTotalSupply/getLBTCTotalSupply.ts +13 -9
  35. package/src/contract-functions/getPermitNonce/getPermitNonce.ts +16 -10
  36. package/src/contract-functions/getShareValue/getShareValue.stories.tsx +1 -1
  37. package/src/contract-functions/getShareValue/getShareValue.ts +1 -1
  38. package/src/contract-functions/getSharesByAddress/getSharesByAddress.stories.tsx +1 -1
  39. package/src/contract-functions/getSharesByAddress/getSharesByAddress.ts +1 -1
  40. package/src/contract-functions/getStakeAndBakeFee/getStakeAndBakeFee.stories.tsx +14 -1
  41. package/src/contract-functions/getStakeAndBakeFee/getStakeAndBakeFee.tsx +5 -1
  42. package/src/contract-functions/signNetworkFee/signNetworkFee.ts +3 -2
  43. package/src/contract-functions/signStakeAndBake/signStakeAndBake.stories.tsx +2 -1
  44. package/src/contract-functions/signStakeAndBake/signStakeAndBake.ts +8 -3
  45. package/src/contract-functions/unstakeLBTC/unstakeLBTC.ts +3 -2
  46. package/src/index.ts +26 -28
  47. package/src/metrics/get-lbtc-stats.stories.tsx +51 -0
  48. package/src/metrics/get-lbtc-stats.ts +38 -0
  49. package/src/tokens/abi/LBTC_ABI.json +1760 -1760
  50. package/src/tokens/abi/LBTC_ABI.ts +1761 -0
  51. package/src/tokens/lbtc-addresses.ts +1 -0
  52. package/src/tokens/token-addresses.ts +32 -0
  53. package/src/tokens/tokens.ts +59 -50
  54. package/src/utils/numbers.ts +3 -0
  55. package/src/vaults/index.ts +35 -176
  56. package/src/vaults/lib/config.ts +196 -0
  57. package/src/vaults/lib/metrics/get-vault-apy.stories.tsx +57 -0
  58. package/src/vaults/lib/metrics/get-vault-apy.ts +132 -0
  59. package/src/vaults/lib/{get-vault-points.stories.tsx → metrics/get-vault-points.stories.tsx} +8 -8
  60. package/src/vaults/lib/{get-vault-points.ts → metrics/get-vault-points.ts} +1 -1
  61. package/src/vaults/lib/metrics/get-vault-tvl.stories.tsx +57 -0
  62. package/src/vaults/lib/metrics/get-vault-tvl.ts +119 -0
  63. package/src/vaults/lib/{cancel-withdraw.stories.tsx → ops/cancel-withdraw.stories.tsx} +9 -9
  64. package/src/vaults/lib/{deposit.stories.tsx → ops/deposit.stories.tsx} +9 -9
  65. package/src/vaults/lib/{deposit.ts → ops/deposit.ts} +10 -10
  66. package/src/vaults/lib/{get-vault-deposits.stories.tsx → ops/get-vault-deposits.stories.tsx} +9 -9
  67. package/src/vaults/lib/{get-vault-deposits.ts → ops/get-vault-deposits.ts} +5 -5
  68. package/src/vaults/lib/{get-vault-withdrawals.stories.tsx → ops/get-vault-withdrawals.stories.tsx} +9 -9
  69. package/src/vaults/lib/{get-vault-withdrawals.ts → ops/get-vault-withdrawals.ts} +5 -5
  70. package/src/vaults/lib/{withdraw.stories.tsx → ops/withdraw.stories.tsx} +9 -9
  71. package/src/vaults/lib/{withdraw.ts → ops/withdraw.ts} +12 -12
  72. package/src/tokens/lbtc-contract.ts +0 -89
@@ -46,6 +46,7 @@ export function getLbtcContractAddresses(
46
46
  switch (env) {
47
47
  case Env.testnet:
48
48
  return TESTNET_LBTC_CONTRACTS;
49
+ case Env.dev:
49
50
  case Env.stage:
50
51
  return STAGE_LBTC_CONTRACTS;
51
52
  case Env.prod:
@@ -0,0 +1,32 @@
1
+ import { Address } from 'viem';
2
+ import { ChainId } from '../common/chains';
3
+
4
+ export enum Token {
5
+ LBTC = 'LBTC',
6
+ BTCB = 'BTCB',
7
+ cbBTC = 'cbBTC',
8
+ eBTC = 'eBTC',
9
+ wBTC = 'wBTC',
10
+ wBTCN = 'wBTCN',
11
+ }
12
+
13
+ export const TOKEN_ADDRESSES: Partial<
14
+ Record<Token, Partial<Record<ChainId, Address>>>
15
+ > = {
16
+ [Token.BTCB]: {
17
+ [ChainId.binanceSmartChain]: '0x7130d2a12b9bcbfae4f2634d864a1ee1ce3ead9c',
18
+ },
19
+ [Token.cbBTC]: {
20
+ [ChainId.ethereum]: '0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf',
21
+ [ChainId.base]: '0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf',
22
+ },
23
+ [Token.eBTC]: {
24
+ [ChainId.ethereum]: '0x657e8c867d8b37dcc18fa4caead9c45eb088c642',
25
+ },
26
+ [Token.wBTC]: {
27
+ [ChainId.ethereum]: '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599',
28
+ },
29
+ [Token.wBTCN]: {
30
+ [ChainId.corn]: '0xda5dDd7270381A7C2717aD10D1c0ecB19e3CDFb2',
31
+ },
32
+ };
@@ -1,11 +1,11 @@
1
1
  import { Env } from '@lombard.finance/sdk-common';
2
- import { getLBTCContractInfo } from './lbtc-contract';
3
2
  import { ChainId } from '../common/chains';
4
3
  import { makePublicClient } from '../clients/public-client';
5
4
  import BigNumber from 'bignumber.js';
6
- import { Abi, Address, erc20Abi } from 'viem';
7
-
8
- export type Token = 'LBTC';
5
+ import { Abi, Address, erc20Abi, PublicClient } from 'viem';
6
+ import { TOKEN_ADDRESSES, Token } from './token-addresses';
7
+ import { getLbtcContractAddresses } from './lbtc-addresses';
8
+ import { LBTC_ABI } from './abi/LBTC_ABI';
9
9
 
10
10
  export type TokenInfo = {
11
11
  address: Address;
@@ -19,21 +19,35 @@ export function getTokenContractInfo(
19
19
  chainId: ChainId,
20
20
  env?: Env,
21
21
  ) {
22
- if (token === 'LBTC') {
23
- return getLBTCContractInfo(chainId, env);
22
+ if (token === Token.LBTC) {
23
+ const addresses = getLbtcContractAddresses(env);
24
+ const contractAddress = addresses[chainId];
25
+ if (!contractAddress) {
26
+ throw new Error(
27
+ `Could not determine the LBTC contract address for given chain id: ${chainId} (env: ${env})`,
28
+ );
29
+ }
30
+ return { abi: LBTC_ABI, address: contractAddress, chainId };
24
31
  }
25
- }
26
32
 
27
- export async function getTokenInfo(
28
- token: Token,
29
- chainId: ChainId,
30
- env?: Env,
31
- rpcUrl?: string,
32
- ): Promise<TokenInfo | undefined> {
33
- const tokenContractInfo = getTokenContractInfo(token, chainId, env);
34
- if (!tokenContractInfo) return;
33
+ const address = TOKEN_ADDRESSES[token]?.[chainId];
34
+ if (!address) {
35
+ throw new Error(
36
+ `Could not determine the ${token} contract address for given chain id: ${chainId}`,
37
+ );
38
+ }
35
39
 
36
- const publicClient = makePublicClient({ chainId, rpcUrl });
40
+ return {
41
+ abi: erc20Abi,
42
+ address,
43
+ chainId,
44
+ };
45
+ }
46
+
47
+ export const retrieveTokenProperties = async (
48
+ publicClient: PublicClient,
49
+ tokenContractInfo: { abi: Abi; address: Address; chainId: ChainId },
50
+ ) => {
37
51
  const [symbolResult, decimalsResult] = await publicClient.multicall({
38
52
  contracts: [
39
53
  {
@@ -58,8 +72,37 @@ export async function getTokenInfo(
58
72
  decimals: Number(decimalsResult.result),
59
73
  };
60
74
  }
75
+ };
76
+
77
+ export async function getTokenInfo(
78
+ token: Token,
79
+ chainId: ChainId,
80
+ env?: Env,
81
+ rpcUrl?: string,
82
+ ): Promise<TokenInfo | undefined> {
83
+ const tokenContractInfo = getTokenContractInfo(token, chainId, env);
84
+ if (!tokenContractInfo) return;
85
+
86
+ const publicClient = makePublicClient({ chainId, rpcUrl });
87
+ return retrieveTokenProperties(publicClient, tokenContractInfo);
88
+ }
89
+
90
+ export async function getAssetInfo(
91
+ address: Address,
92
+ chainId: ChainId,
93
+ rpcUrl?: string,
94
+ ): Promise<TokenInfo | undefined> {
95
+ const publicClient = makePublicClient({ chainId, rpcUrl });
96
+ return retrieveTokenProperties(publicClient, {
97
+ abi: erc20Abi,
98
+ address,
99
+ chainId,
100
+ });
61
101
  }
62
102
 
103
+ // Utils:
104
+ // TODO: Move to utils
105
+
63
106
  export function toBaseDenomination(
64
107
  input: BigNumber.Value,
65
108
  decimalPlaces: number,
@@ -75,37 +118,3 @@ export function fromBaseDenomination(
75
118
  ) {
76
119
  return BigNumber(input).dividedBy(BigNumber(10).pow(decimalPlaces));
77
120
  }
78
-
79
- export async function getAssetInfo(
80
- address: Address,
81
- chainId: ChainId,
82
- rpcUrl?: string,
83
- ): Promise<TokenInfo | undefined> {
84
- const publicClient = makePublicClient({ chainId, rpcUrl });
85
- const [symbolResult, decimalsResult] = await publicClient.multicall({
86
- contracts: [
87
- {
88
- address,
89
- abi: erc20Abi,
90
- functionName: 'symbol',
91
- },
92
- {
93
- address,
94
- abi: erc20Abi,
95
- functionName: 'decimals',
96
- },
97
- ],
98
- });
99
-
100
- if (
101
- symbolResult.status === 'success' &&
102
- decimalsResult.status === 'success'
103
- ) {
104
- return {
105
- address,
106
- abi: erc20Abi,
107
- symbol: String(symbolResult.result),
108
- decimals: Number(decimalsResult.result),
109
- };
110
- }
111
- }
@@ -1,5 +1,8 @@
1
1
  import BigNumber from 'bignumber.js';
2
2
 
3
+ export const ZERO = BigNumber(0);
4
+ export const ONE = BigNumber(1);
5
+
3
6
  export default function toBigInt(input: BigNumber.Value) {
4
7
  return BigInt(BigNumber(input).toFixed());
5
8
  }
@@ -1,187 +1,46 @@
1
- import { ChainId } from '../common/chains';
2
- import VEDA_VAULT_ABI from './abi/VEDA_VAULT_ABI.json';
3
- import VEDA_VAULT_ACCOUNTANT_ABI from './abi/VEDA_VAULT_ACCOUNTANT_ABI.json';
4
- import VEDA_VAULT_LENS_ABI from './abi/VEDA_VAULT_LENS_ABI.json';
5
- import VEDA_VAULT_BASE_ASSET_ABI from './abi/VEDA_VAULT_BASE_ASSET_ABI.json';
6
- import VEDA_VAULT_SPENDER_ABI from './abi/VEDA_VAULT_SPENDER_ABI.json';
7
- import VEDA_VAULT_TELLER_ABI from './abi/VEDA_VAULT_TELLER_ABI.json';
8
- import VEDA_VAULT_BORING_WITHDRAW_QUEUE_ABI from './abi/VEDA_VAULT_BORING_WITHDRAW_QUEUE_ABI.json';
9
- import { Abi, Address } from 'viem';
1
+ // Config:
10
2
 
11
- type ContractInfo = {
12
- abi: Abi;
13
- address: Address;
14
- chainId: ChainId;
15
- };
3
+ export { Vault } from './lib/config';
16
4
 
17
- export const VEDA_VAULT_CHAINS = [
18
- ChainId.ethereum,
19
- ChainId.base,
20
- ChainId.binanceSmartChain,
21
- ChainId.corn,
22
- ] as const;
5
+ // Ops - Deposit:
23
6
 
24
- export type VedaVaultChain = (typeof VEDA_VAULT_CHAINS)[number];
25
- export const isVedaVaultChain = (chainId: number): chainId is VedaVaultChain =>
26
- VEDA_VAULT_CHAINS.includes(chainId as VedaVaultChain);
7
+ export {
8
+ deposit,
9
+ type DepositParameters,
10
+ } from './lib/ops/deposit';
27
11
 
28
- export const VEDA_VAULT_CHAIN_TO_NETWORK_MAP: Record<VedaVaultChain, string> = {
29
- [ChainId.ethereum]: 'ethereum',
30
- [ChainId.base]: 'base',
31
- [ChainId.corn]: 'corn',
32
- [ChainId.binanceSmartChain]: 'bnb',
33
- };
12
+ export {
13
+ getVaultDeposits,
14
+ type GetVaultDepositsParameters,
15
+ } from './lib/ops/get-vault-deposits';
34
16
 
35
- export const NETWORK_TO_VEDA_VAULT_CHAIN_MAP: Record<string, VedaVaultChain> = {
36
- ethereum: ChainId.ethereum,
37
- base: ChainId.base,
38
- corn: ChainId.corn,
39
- bnb: ChainId.binanceSmartChain,
40
- };
17
+ // Ops - Withdraw:
41
18
 
42
- /** A list of chains where stake and bake is enabled */
43
- export const VEDA_VAULT_STAKE_AND_BAKE_CHAINS = [
44
- ChainId.ethereum,
45
- ChainId.binanceSmartChain,
46
- // Testnets:
47
- ChainId.binanceSmartChainTestnet,
48
- ChainId.holesky,
49
- ];
50
- export type VedaVaultStakeAndBakeChain =
51
- (typeof VEDA_VAULT_STAKE_AND_BAKE_CHAINS)[number];
52
- export const isVedaVaultStakeAndBakeChain = (
53
- chainId: number,
54
- ): chainId is VedaVaultStakeAndBakeChain =>
55
- VEDA_VAULT_STAKE_AND_BAKE_CHAINS.includes(
56
- chainId as VedaVaultStakeAndBakeChain,
57
- );
19
+ export {
20
+ queueWithdraw,
21
+ type QueueWithdrawParameters,
22
+ cancelWithdraw,
23
+ type CancelWithdrawParameters,
24
+ } from './lib/ops/withdraw';
58
25
 
59
- export const VEDA_VAULT_DEFAULT_CHAIN_ID: VedaVaultChain = ChainId.ethereum;
26
+ export {
27
+ getVaultWithdrawals,
28
+ type GetVaultWithdrawalsParameters,
29
+ } from './lib/ops/get-vault-withdrawals';
60
30
 
61
- export const VEDA_VAULT_CONTRACT = '0x5401b8620E5FB570064CA9114fd1e135fd77D57c';
62
- export const VEDA_VAULT_ACCOUNTANT_CONTRACT =
63
- '0x28634D0c5edC67CF2450E74deA49B90a4FF93dCE';
64
- export const VEDA_VAULT_LENS_CONTRACT =
65
- '0x5232bc0F5999f8dA604c42E1748A13a170F94A1B';
31
+ // Metrics - Vault points:
66
32
 
67
- export const VEDA_VAULT_TELLER_CONTRACTS: Record<VedaVaultChain, ContractInfo> =
68
- {
69
- [ChainId.ethereum]: {
70
- abi: VEDA_VAULT_TELLER_ABI as Abi,
71
- address: '0x4E8f5128F473C6948127f9Cbca474a6700F99bab',
72
- chainId: ChainId.ethereum,
73
- },
74
- [ChainId.base]: {
75
- abi: VEDA_VAULT_TELLER_ABI as Abi,
76
- address: '0x2eA43384F1A98765257bc6Cb26c7131dEbdEB9B3',
77
- chainId: ChainId.base,
78
- },
79
- [ChainId.binanceSmartChain]: {
80
- abi: VEDA_VAULT_TELLER_ABI as Abi,
81
- address: '0x2eA43384F1A98765257bc6Cb26c7131dEbdEB9B3',
82
- chainId: ChainId.binanceSmartChain,
83
- },
84
- [ChainId.corn]: {
85
- abi: VEDA_VAULT_TELLER_ABI as Abi,
86
- address: '0x2eA43384F1A98765257bc6Cb26c7131dEbdEB9B3',
87
- chainId: ChainId.corn,
88
- },
89
- } as const;
33
+ export {
34
+ getVaultPoints,
35
+ type GetVaultPointsParameters,
36
+ } from './lib/metrics/get-vault-points';
90
37
 
91
- /** Stake and bake contracts */
92
- export const VEDA_VAULT_SPENDER_CONTRACTS: Record<
93
- VedaVaultStakeAndBakeChain,
94
- ContractInfo
95
- > = {
96
- [ChainId.ethereum]: {
97
- abi: VEDA_VAULT_SPENDER_ABI as Abi,
98
- address: '0xC8bbF6153D7Ba105f1399D992ebd32B0541996ef',
99
- chainId: ChainId.ethereum,
100
- },
38
+ export {
39
+ getVaultTVL,
40
+ type GetVaultTVLParameters,
41
+ } from './lib/metrics/get-vault-tvl';
101
42
 
102
- [ChainId.binanceSmartChain]: {
103
- abi: VEDA_VAULT_SPENDER_ABI as Abi,
104
- address: '0xC8bbF6153D7Ba105f1399D992ebd32B0541996ef',
105
- chainId: ChainId.binanceSmartChain,
106
- },
107
- // Testnets:
108
- [ChainId.holesky]: {
109
- abi: VEDA_VAULT_SPENDER_ABI as Abi,
110
- address: '0x4A3cD83CEbb91E0Cd31EdA2Ee0F4AebfcCFCbBb6',
111
- chainId: ChainId.holesky,
112
- },
113
- [ChainId.binanceSmartChainTestnet]: {
114
- abi: VEDA_VAULT_SPENDER_ABI as Abi,
115
- address: '0x72143309A662bDB4aad5cA65Ab59eD8977D047C5',
116
- chainId: ChainId.binanceSmartChainTestnet,
117
- },
118
- } as const;
119
-
120
- export const VEDA_VAULT_WITHDRAW_QUEUE_CONTRACTS: Record<
121
- VedaVaultChain,
122
- ContractInfo
123
- > = {
124
- [ChainId.ethereum]: {
125
- abi: VEDA_VAULT_BORING_WITHDRAW_QUEUE_ABI as Abi,
126
- address: '0x3b4aCd8879fb60586cCd74bC2F831A4C5E7DbBf8',
127
- chainId: ChainId.ethereum,
128
- },
129
- [ChainId.base]: {
130
- abi: VEDA_VAULT_BORING_WITHDRAW_QUEUE_ABI as Abi,
131
- address: '0x3b4aCd8879fb60586cCd74bC2F831A4C5E7DbBf8',
132
- chainId: ChainId.ethereum,
133
- },
134
- [ChainId.binanceSmartChain]: {
135
- abi: VEDA_VAULT_BORING_WITHDRAW_QUEUE_ABI as Abi,
136
- address: '0x3b4aCd8879fb60586cCd74bC2F831A4C5E7DbBf8',
137
- chainId: ChainId.ethereum,
138
- },
139
- [ChainId.corn]: {
140
- abi: VEDA_VAULT_BORING_WITHDRAW_QUEUE_ABI as Abi,
141
- address: '0x3b4aCd8879fb60586cCd74bC2F831A4C5E7DbBf8',
142
- chainId: ChainId.ethereum,
143
- },
144
- };
145
-
146
- export const VEDA_VAULT_BASE_ASSET = {
147
- abi: VEDA_VAULT_BASE_ASSET_ABI,
148
- symbol: 'WBTC',
149
- displayName: 'wBTC',
150
- address: '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599',
151
- decimals: 8,
152
- };
153
-
154
- export enum Vault {
155
- Veda = 'veda',
156
- }
157
-
158
- export const VaultNameMap = {
159
- [Vault.Veda]: 'Veda / Lombard DeFi Vault',
160
- } as const;
161
-
162
- export const VAULTS = {
163
- [Vault.Veda]: {
164
- defaultChainId: VEDA_VAULT_DEFAULT_CHAIN_ID,
165
- chains: VEDA_VAULT_CHAINS,
166
- stakeAndBakeChains: VEDA_VAULT_STAKE_AND_BAKE_CHAINS,
167
- decimals: 8,
168
- vaultContract: {
169
- abi: VEDA_VAULT_ABI,
170
- address: VEDA_VAULT_CONTRACT,
171
- },
172
- accountantContract: {
173
- abi: VEDA_VAULT_ACCOUNTANT_ABI,
174
- address: VEDA_VAULT_ACCOUNTANT_CONTRACT,
175
- },
176
- lensContract: {
177
- abi: VEDA_VAULT_LENS_ABI,
178
- address: VEDA_VAULT_LENS_CONTRACT,
179
- },
180
- spenderContracts: VEDA_VAULT_SPENDER_CONTRACTS,
181
- tellerContracts: VEDA_VAULT_TELLER_CONTRACTS,
182
- withdrawQueueContracts: VEDA_VAULT_WITHDRAW_QUEUE_CONTRACTS,
183
-
184
- queueWithdrawDiscountPercent: '0.01',
185
- queueWithdrawDaysValid: '3',
186
- },
187
- } as const;
43
+ export {
44
+ getVaultApy,
45
+ type GetVaultApyParameters,
46
+ } from './lib/metrics/get-vault-apy';
@@ -0,0 +1,196 @@
1
+ import { ChainId } from '../../common/chains';
2
+ import VEDA_VAULT_ABI from '../abi/VEDA_VAULT_ABI.json';
3
+ import VEDA_VAULT_ACCOUNTANT_ABI from '../abi/VEDA_VAULT_ACCOUNTANT_ABI.json';
4
+ import VEDA_VAULT_LENS_ABI from '../abi/VEDA_VAULT_LENS_ABI.json';
5
+ import VEDA_VAULT_BASE_ASSET_ABI from '../abi/VEDA_VAULT_BASE_ASSET_ABI.json';
6
+ import VEDA_VAULT_SPENDER_ABI from '../abi/VEDA_VAULT_SPENDER_ABI.json';
7
+ import VEDA_VAULT_TELLER_ABI from '../abi/VEDA_VAULT_TELLER_ABI.json';
8
+ import VEDA_VAULT_BORING_WITHDRAW_QUEUE_ABI from '../abi/VEDA_VAULT_BORING_WITHDRAW_QUEUE_ABI.json';
9
+ import { Abi, Address } from 'viem';
10
+ import { Token } from '../../tokens/token-addresses';
11
+
12
+ type ContractInfo = {
13
+ abi: Abi;
14
+ address: Address;
15
+ chainId: ChainId;
16
+ };
17
+
18
+ export const VEDA_VAULT_CHAINS = [
19
+ ChainId.ethereum,
20
+ ChainId.base,
21
+ ChainId.binanceSmartChain,
22
+ ChainId.corn,
23
+ ] as const;
24
+
25
+ export type VedaVaultChain = (typeof VEDA_VAULT_CHAINS)[number];
26
+ export const isVedaVaultChain = (chainId: number): chainId is VedaVaultChain =>
27
+ VEDA_VAULT_CHAINS.includes(chainId as VedaVaultChain);
28
+
29
+ export const VEDA_VAULT_CHAIN_TO_NETWORK_MAP: Record<VedaVaultChain, string> = {
30
+ [ChainId.ethereum]: 'ethereum',
31
+ [ChainId.base]: 'base',
32
+ [ChainId.corn]: 'corn',
33
+ [ChainId.binanceSmartChain]: 'bnb',
34
+ };
35
+
36
+ export const NETWORK_TO_VEDA_VAULT_CHAIN_MAP: Record<string, VedaVaultChain> = {
37
+ ethereum: ChainId.ethereum,
38
+ base: ChainId.base,
39
+ corn: ChainId.corn,
40
+ bnb: ChainId.binanceSmartChain,
41
+ };
42
+
43
+ /** A list of chains where stake and bake is enabled */
44
+ export const VEDA_VAULT_STAKE_AND_BAKE_CHAINS = [
45
+ ChainId.ethereum,
46
+ ChainId.binanceSmartChain,
47
+ // Testnets:
48
+ ChainId.binanceSmartChainTestnet,
49
+ ChainId.holesky,
50
+ ];
51
+ export type VedaVaultStakeAndBakeChain =
52
+ (typeof VEDA_VAULT_STAKE_AND_BAKE_CHAINS)[number];
53
+ export const isVedaVaultStakeAndBakeChain = (
54
+ chainId: number,
55
+ ): chainId is VedaVaultStakeAndBakeChain =>
56
+ VEDA_VAULT_STAKE_AND_BAKE_CHAINS.includes(
57
+ chainId as VedaVaultStakeAndBakeChain,
58
+ );
59
+
60
+ export const VEDA_VAULT_DEFAULT_CHAIN_ID: VedaVaultChain = ChainId.ethereum;
61
+
62
+ export const VEDA_VAULT_CONTRACT = '0x5401b8620E5FB570064CA9114fd1e135fd77D57c';
63
+ export const VEDA_VAULT_ACCOUNTANT_CONTRACT =
64
+ '0x28634D0c5edC67CF2450E74deA49B90a4FF93dCE';
65
+ export const VEDA_VAULT_LENS_CONTRACT =
66
+ '0x5232bc0F5999f8dA604c42E1748A13a170F94A1B';
67
+
68
+ export const VEDA_VAULT_TELLER_CONTRACTS: Record<VedaVaultChain, ContractInfo> =
69
+ {
70
+ [ChainId.ethereum]: {
71
+ abi: VEDA_VAULT_TELLER_ABI as Abi,
72
+ address: '0x4E8f5128F473C6948127f9Cbca474a6700F99bab',
73
+ chainId: ChainId.ethereum,
74
+ },
75
+ [ChainId.base]: {
76
+ abi: VEDA_VAULT_TELLER_ABI as Abi,
77
+ address: '0x2eA43384F1A98765257bc6Cb26c7131dEbdEB9B3',
78
+ chainId: ChainId.base,
79
+ },
80
+ [ChainId.binanceSmartChain]: {
81
+ abi: VEDA_VAULT_TELLER_ABI as Abi,
82
+ address: '0x2eA43384F1A98765257bc6Cb26c7131dEbdEB9B3',
83
+ chainId: ChainId.binanceSmartChain,
84
+ },
85
+ [ChainId.corn]: {
86
+ abi: VEDA_VAULT_TELLER_ABI as Abi,
87
+ address: '0x2eA43384F1A98765257bc6Cb26c7131dEbdEB9B3',
88
+ chainId: ChainId.corn,
89
+ },
90
+ } as const;
91
+
92
+ /** Stake and bake contracts */
93
+ export const VEDA_VAULT_SPENDER_CONTRACTS: Record<
94
+ VedaVaultStakeAndBakeChain,
95
+ ContractInfo
96
+ > = {
97
+ [ChainId.ethereum]: {
98
+ abi: VEDA_VAULT_SPENDER_ABI as Abi,
99
+ address: '0xC8bbF6153D7Ba105f1399D992ebd32B0541996ef',
100
+ chainId: ChainId.ethereum,
101
+ },
102
+
103
+ [ChainId.binanceSmartChain]: {
104
+ abi: VEDA_VAULT_SPENDER_ABI as Abi,
105
+ address: '0xC8bbF6153D7Ba105f1399D992ebd32B0541996ef',
106
+ chainId: ChainId.binanceSmartChain,
107
+ },
108
+ // Testnets:
109
+ [ChainId.holesky]: {
110
+ abi: VEDA_VAULT_SPENDER_ABI as Abi,
111
+ address: '0x4A3cD83CEbb91E0Cd31EdA2Ee0F4AebfcCFCbBb6',
112
+ chainId: ChainId.holesky,
113
+ },
114
+ [ChainId.binanceSmartChainTestnet]: {
115
+ abi: VEDA_VAULT_SPENDER_ABI as Abi,
116
+ address: '0x72143309A662bDB4aad5cA65Ab59eD8977D047C5',
117
+ chainId: ChainId.binanceSmartChainTestnet,
118
+ },
119
+ } as const;
120
+
121
+ export const VEDA_VAULT_WITHDRAW_QUEUE_CONTRACTS: Record<
122
+ VedaVaultChain,
123
+ ContractInfo
124
+ > = {
125
+ [ChainId.ethereum]: {
126
+ abi: VEDA_VAULT_BORING_WITHDRAW_QUEUE_ABI as Abi,
127
+ address: '0x3b4aCd8879fb60586cCd74bC2F831A4C5E7DbBf8',
128
+ chainId: ChainId.ethereum,
129
+ },
130
+ [ChainId.base]: {
131
+ abi: VEDA_VAULT_BORING_WITHDRAW_QUEUE_ABI as Abi,
132
+ address: '0x3b4aCd8879fb60586cCd74bC2F831A4C5E7DbBf8',
133
+ chainId: ChainId.ethereum,
134
+ },
135
+ [ChainId.binanceSmartChain]: {
136
+ abi: VEDA_VAULT_BORING_WITHDRAW_QUEUE_ABI as Abi,
137
+ address: '0x3b4aCd8879fb60586cCd74bC2F831A4C5E7DbBf8',
138
+ chainId: ChainId.ethereum,
139
+ },
140
+ [ChainId.corn]: {
141
+ abi: VEDA_VAULT_BORING_WITHDRAW_QUEUE_ABI as Abi,
142
+ address: '0x3b4aCd8879fb60586cCd74bC2F831A4C5E7DbBf8',
143
+ chainId: ChainId.ethereum,
144
+ },
145
+ };
146
+
147
+ export const VEDA_VAULT_BASE_ASSET = {
148
+ abi: VEDA_VAULT_BASE_ASSET_ABI,
149
+ symbol: 'WBTC',
150
+ displayName: 'wBTC',
151
+ address: '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599',
152
+ decimals: 8,
153
+ };
154
+
155
+ export enum Vault {
156
+ Veda = 'veda',
157
+ }
158
+
159
+ export const VaultNameMap = {
160
+ [Vault.Veda]: 'Veda / Lombard DeFi Vault',
161
+ } as const;
162
+
163
+ export const VAULTS = {
164
+ [Vault.Veda]: {
165
+ defaultChainId: VEDA_VAULT_DEFAULT_CHAIN_ID,
166
+ chains: VEDA_VAULT_CHAINS,
167
+ tokens: {
168
+ [Token.LBTC]: VEDA_VAULT_CHAINS,
169
+ [Token.BTCB]: [ChainId.binanceSmartChain],
170
+ [Token.cbBTC]: [ChainId.ethereum, ChainId.base],
171
+ [Token.eBTC]: [ChainId.ethereum],
172
+ [Token.wBTC]: [ChainId.ethereum],
173
+ [Token.wBTCN]: [ChainId.corn],
174
+ },
175
+ stakeAndBakeChains: VEDA_VAULT_STAKE_AND_BAKE_CHAINS,
176
+ decimals: 8,
177
+ vaultContract: {
178
+ abi: VEDA_VAULT_ABI,
179
+ address: VEDA_VAULT_CONTRACT,
180
+ },
181
+ accountantContract: {
182
+ abi: VEDA_VAULT_ACCOUNTANT_ABI,
183
+ address: VEDA_VAULT_ACCOUNTANT_CONTRACT,
184
+ },
185
+ lensContract: {
186
+ abi: VEDA_VAULT_LENS_ABI,
187
+ address: VEDA_VAULT_LENS_CONTRACT,
188
+ },
189
+ spenderContracts: VEDA_VAULT_SPENDER_CONTRACTS,
190
+ tellerContracts: VEDA_VAULT_TELLER_CONTRACTS,
191
+ withdrawQueueContracts: VEDA_VAULT_WITHDRAW_QUEUE_CONTRACTS,
192
+
193
+ queueWithdrawDiscountPercent: '0.01',
194
+ queueWithdrawDaysValid: '3',
195
+ },
196
+ } as const;
@@ -0,0 +1,57 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ import { Button } from '../../../stories/components/Button';
3
+ import { CodeBlock } from '../../../stories/components/CodeBlock';
4
+ import useQuery from '../../../stories/hooks/useQuery';
5
+ import {
6
+ functionType,
7
+ wagmiDecorator,
8
+ } from '../../../stories/components/decorators';
9
+ import { Vault } from '../config';
10
+ import { ErrorBlock } from '../../../stories/components/error-block';
11
+ import { getVaultApy, GetVaultApyParameters } from './get-vault-apy';
12
+
13
+ const meta = {
14
+ title: 'vault/metrics/getVaultApy',
15
+ component: StoryView,
16
+ tags: ['autodocs'],
17
+ decorators: [wagmiDecorator, functionType('api-get')],
18
+ } satisfies Meta<typeof StoryView>;
19
+
20
+ export default meta;
21
+
22
+ type Story = StoryObj<typeof meta>;
23
+
24
+ export const WithParams: Story = {
25
+ args: {
26
+ vaultKey: Vault.Veda,
27
+ },
28
+ };
29
+
30
+ type SignNetworkFeeProps = GetVaultApyParameters;
31
+
32
+ export function StoryView(props: SignNetworkFeeProps) {
33
+ const request = async () => {
34
+ return getVaultApy({
35
+ ...props,
36
+ });
37
+ };
38
+
39
+ const { data, error, isLoading, refetch } = useQuery(request, [], false);
40
+
41
+ return (
42
+ <>
43
+ <p>This function gets the APY entries of the DeFi vault.</p>
44
+
45
+ <Button
46
+ onClick={refetch}
47
+ disabled={isLoading}
48
+ isLoading={isLoading}
49
+ actionName={getVaultApy.name}
50
+ />
51
+
52
+ <ErrorBlock>{error}</ErrorBlock>
53
+
54
+ <CodeBlock text={data} />
55
+ </>
56
+ );
57
+ }