@lombard.finance/sdk 3.7.1 → 3.7.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.
Files changed (204) hide show
  1. package/CHANGELOG.md +102 -98
  2. package/README.md +164 -160
  3. package/dist/api-functions/generateDepositBtcAddress/generateDepositBtcAddress.d.ts.map +1 -1
  4. package/dist/api-functions/get-badges-by-address/get-badges-by-address.d.ts +1 -1
  5. package/dist/api-functions/get-badges-by-address/get-badges-by-address.d.ts.map +1 -1
  6. package/dist/api-functions/getDepositBtcAddress/getDepositBtcAddress.d.ts +1 -1
  7. package/dist/api-functions/getDepositBtcAddress/getDepositBtcAddress.d.ts.map +1 -1
  8. package/dist/api-functions/getDepositBtcAddress/make-request.d.ts.map +1 -1
  9. package/dist/api-functions/getDepositsByAddress/getDepositsByAddress.d.ts.map +1 -1
  10. package/dist/api-functions/getLBTCExchangeRate/get-exchange-ratio.d.ts.map +1 -1
  11. package/dist/api-functions/getLBTCExchangeRate/getLBTCExchangeRate.d.ts.map +1 -1
  12. package/dist/api-functions/getLBTCExchangeRate/index.d.ts +1 -1
  13. package/dist/api-functions/getLBTCExchangeRate/index.d.ts.map +1 -1
  14. package/dist/api-functions/getPointsByAddress/getPointsByAddress.d.ts.map +1 -1
  15. package/dist/api-functions/getUnstakesByAddress/getUnstakesByAddress.d.ts.map +1 -1
  16. package/dist/api-functions/getUserStakeAndBakeSignature/getUserStakeAndBakeSignature.d.ts.map +1 -1
  17. package/dist/api-functions/setReferral/setReferral.d.ts.map +1 -1
  18. package/dist/api-functions/storeNetworkFeeSignature/storeNetworkFeeSignature.d.ts.map +1 -1
  19. package/dist/api-functions/storeStakeAndBakeSignature/storeStakeAndBakeSignature.d.ts.map +1 -1
  20. package/dist/bridge/index.d.ts +2 -2
  21. package/dist/bridge/index.d.ts.map +1 -1
  22. package/dist/bridge/lib/bridge.d.ts.map +1 -1
  23. package/dist/bridge/lib/ccip-bridge.d.ts.map +1 -1
  24. package/dist/bridge/lib/ccip-config.d.ts +1 -1
  25. package/dist/bridge/lib/ccip-config.d.ts.map +1 -1
  26. package/dist/bridge/lib/config.d.ts.map +1 -1
  27. package/dist/bridge/lib/oft-bridge.d.ts.map +1 -1
  28. package/dist/clients/evm-signer-adapter.d.ts.map +1 -1
  29. package/dist/clients/public-client.d.ts.map +1 -1
  30. package/dist/clients/rpc-url-config.d.ts.map +1 -1
  31. package/dist/clients/wallet-client.d.ts.map +1 -1
  32. package/dist/common/blockchain-identifier.d.ts +2 -0
  33. package/dist/common/blockchain-identifier.d.ts.map +1 -1
  34. package/dist/common/chains.d.ts +191 -97
  35. package/dist/common/chains.d.ts.map +1 -1
  36. package/dist/common/chains.stories.d.ts.map +1 -1
  37. package/dist/common/contract-info.d.ts.map +1 -1
  38. package/dist/common/parameters.d.ts.map +1 -1
  39. package/dist/contract-functions/approveLBTC/approveLBTC.d.ts.map +1 -1
  40. package/dist/contract-functions/approveToken/approveToken.d.ts +1 -1
  41. package/dist/contract-functions/approveToken/approveToken.d.ts.map +1 -1
  42. package/dist/contract-functions/claimLBTC/claimLBTC.d.ts.map +1 -1
  43. package/dist/contract-functions/claimUnstakeRedeem/claimUnstakeRedeem.d.ts.map +1 -1
  44. package/dist/contract-functions/deposit/depositToken.d.ts.map +1 -1
  45. package/dist/contract-functions/getBasculeDepositStatus/getBasculeDepositStatus.d.ts.map +1 -1
  46. package/dist/contract-functions/getBasculeDepositStatus/getBasculeDepositStatus.stories.d.ts.map +1 -1
  47. package/dist/contract-functions/getBasculeDepositStatus/index.d.ts +1 -1
  48. package/dist/contract-functions/getBasculeDepositStatus/index.d.ts.map +1 -1
  49. package/dist/contract-functions/getLBTCMintingFee/getLBTCMintingFee.d.ts.map +1 -1
  50. package/dist/contract-functions/getLBTCMintingFee/getLBTCMintingFee.stories.d.ts.map +1 -1
  51. package/dist/contract-functions/getLBTCTotalSupply/getLBTCTotalSupply.d.ts.map +1 -1
  52. package/dist/contract-functions/getPermitNonce/getPermitNonce.d.ts.map +1 -1
  53. package/dist/contract-functions/getShareValue/getShareValue.d.ts.map +1 -1
  54. package/dist/contract-functions/getSharesByAddress/getSharesByAddress.d.ts.map +1 -1
  55. package/dist/contract-functions/getStakeAndBakeFee/getStakeAndBakeFee.d.ts.map +1 -1
  56. package/dist/contract-functions/index.d.ts +2 -2
  57. package/dist/contract-functions/index.d.ts.map +1 -1
  58. package/dist/contract-functions/signNetworkFee/signNetworkFee.d.ts.map +1 -1
  59. package/dist/contract-functions/signStakeAndBake/handleApprove.d.ts.map +1 -1
  60. package/dist/contract-functions/signStakeAndBake/signStakeAndBake.d.ts.map +1 -1
  61. package/dist/contract-functions/signStakeAndBake/typed-data-builder.d.ts.map +1 -1
  62. package/dist/contract-functions/signStakeAndBake/utils.d.ts.map +1 -1
  63. package/dist/contract-functions/signStakeAndBake/validation.d.ts.map +1 -1
  64. package/dist/contract-functions/unstakeLBTC/unstakeLBTC.d.ts.map +1 -1
  65. package/dist/debug-api/btc-script-to-address.d.ts.map +1 -1
  66. package/dist/debug-api/btc-tx-info.d.ts.map +1 -1
  67. package/dist/debug-api/evm-by-btc-address.d.ts.map +1 -1
  68. package/dist/defi/defi-registry.d.ts +1 -1
  69. package/dist/defi/defi-registry.d.ts.map +1 -1
  70. package/dist/defi/defi-registry.stories.d.ts.map +1 -1
  71. package/dist/defi/index.d.ts +1 -1
  72. package/dist/defi/index.d.ts.map +1 -1
  73. package/dist/index.cjs +1 -1
  74. package/dist/index.d.ts +7 -7
  75. package/dist/index.d.ts.map +1 -1
  76. package/dist/index.js +51 -49
  77. package/dist/index2.cjs +54 -54
  78. package/dist/index2.js +14414 -11251
  79. package/dist/metrics/get-additional-rewards.d.ts +1 -1
  80. package/dist/metrics/get-additional-rewards.d.ts.map +1 -1
  81. package/dist/metrics/get-lbtc-apy.d.ts +1 -1
  82. package/dist/metrics/get-lbtc-apy.d.ts.map +1 -1
  83. package/dist/metrics/get-lbtc-stats.d.ts.map +1 -1
  84. package/dist/metrics/get-lbtc-stats.stories.d.ts.map +1 -1
  85. package/dist/metrics/get-positions-summary.d.ts.map +1 -1
  86. package/dist/metrics/get-positions-summary.stories.d.ts.map +1 -1
  87. package/dist/stories/arg-types.d.ts.map +1 -1
  88. package/dist/tokens/lbtc-addresses.d.ts.map +1 -1
  89. package/dist/tokens/token-addresses.d.ts +1 -1
  90. package/dist/tokens/token-addresses.d.ts.map +1 -1
  91. package/dist/tokens/tokens.d.ts +5 -5
  92. package/dist/tokens/tokens.d.ts.map +1 -1
  93. package/dist/utils/block.d.ts.map +1 -1
  94. package/dist/utils/env.d.ts.map +1 -1
  95. package/dist/utils/err.d.ts +2 -2
  96. package/dist/utils/err.d.ts.map +1 -1
  97. package/dist/utils/transaction-executor.d.ts.map +1 -1
  98. package/dist/vaults/index.d.ts +5 -5
  99. package/dist/vaults/index.d.ts.map +1 -1
  100. package/dist/vaults/lib/config.d.ts.map +1 -1
  101. package/dist/vaults/lib/metrics/get-vault-apy.d.ts.map +1 -1
  102. package/dist/vaults/lib/metrics/get-vault-points.d.ts.map +1 -1
  103. package/dist/vaults/lib/metrics/get-vault-tvl.d.ts.map +1 -1
  104. package/dist/vaults/lib/ops/deposit.d.ts.map +1 -1
  105. package/dist/vaults/lib/ops/get-vault-deposits.d.ts.map +1 -1
  106. package/dist/vaults/lib/ops/get-vault-withdrawals.d.ts.map +1 -1
  107. package/dist/vaults/lib/ops/withdraw.d.ts.map +1 -1
  108. package/package.json +4 -4
  109. package/src/api-functions/generateDepositBtcAddress/generateDepositBtcAddress.ts +4 -3
  110. package/src/api-functions/get-badges-by-address/get-badges-by-address.ts +2 -1
  111. package/src/api-functions/getDepositBtcAddress/getDepositBtcAddress.test.ts +3 -2
  112. package/src/api-functions/getDepositBtcAddress/getDepositBtcAddress.ts +3 -2
  113. package/src/api-functions/getDepositBtcAddress/make-request.ts +2 -1
  114. package/src/api-functions/getDepositsByAddress/getDepositsByAddress.ts +4 -3
  115. package/src/api-functions/getLBTCExchangeRate/get-exchange-ratio.ts +2 -1
  116. package/src/api-functions/getLBTCExchangeRate/getLBTCExchangeRate.ts +1 -0
  117. package/src/api-functions/getLBTCExchangeRate/index.ts +1 -1
  118. package/src/api-functions/getPointsByAddress/getPointsByAddress.ts +1 -0
  119. package/src/api-functions/getUnstakesByAddress/getUnstakesByAddress.ts +5 -4
  120. package/src/api-functions/getUserStakeAndBakeSignature/getUserStakeAndBakeSignature.ts +1 -0
  121. package/src/api-functions/setReferral/setReferral.ts +1 -0
  122. package/src/api-functions/storeNetworkFeeSignature/storeNetworkFeeSignature.ts +1 -0
  123. package/src/api-functions/storeStakeAndBakeSignature/storeStakeAndBakeSignature.ts +1 -0
  124. package/src/bridge/index.ts +2 -3
  125. package/src/bridge/lib/bridge.ts +3 -2
  126. package/src/bridge/lib/ccip-bridge.ts +5 -4
  127. package/src/bridge/lib/ccip-config.ts +2 -1
  128. package/src/bridge/lib/config.ts +1 -0
  129. package/src/bridge/lib/oft-bridge.ts +3 -2
  130. package/src/clients/evm-signer-adapter.ts +4 -3
  131. package/src/clients/public-client.ts +1 -0
  132. package/src/clients/rpc-url-config.ts +4 -1
  133. package/src/clients/wallet-client.ts +3 -2
  134. package/src/common/blockchain-identifier.ts +14 -2
  135. package/src/common/chains.stories.tsx +2 -2
  136. package/src/common/chains.ts +54 -10
  137. package/src/common/contract-info.ts +1 -0
  138. package/src/common/parameters.ts +1 -0
  139. package/src/contract-functions/approveLBTC/approveLBTC.ts +1 -0
  140. package/src/contract-functions/approveToken/approveToken.ts +3 -2
  141. package/src/contract-functions/approveToken/index.ts +0 -1
  142. package/src/contract-functions/claimLBTC/claimLBTC.ts +1 -0
  143. package/src/contract-functions/claimUnstakeRedeem/claimUnstakeRedeem.ts +6 -5
  144. package/src/contract-functions/claimUnstakeRedeem/index.ts +0 -1
  145. package/src/contract-functions/deposit/depositToken.ts +7 -6
  146. package/src/contract-functions/getBasculeDepositStatus/getBasculeDepositStatus.stories.tsx +6 -6
  147. package/src/contract-functions/getBasculeDepositStatus/getBasculeDepositStatus.ts +14 -9
  148. package/src/contract-functions/getBasculeDepositStatus/index.ts +1 -1
  149. package/src/contract-functions/getLBTCMintingFee/getLBTCMintingFee.stories.tsx +1 -1
  150. package/src/contract-functions/getLBTCMintingFee/getLBTCMintingFee.ts +1 -0
  151. package/src/contract-functions/getLBTCTotalSupply/getLBTCTotalSupply.ts +1 -0
  152. package/src/contract-functions/getPermitNonce/getPermitNonce.ts +1 -0
  153. package/src/contract-functions/getShareValue/getShareValue.ts +2 -1
  154. package/src/contract-functions/getSharesByAddress/getSharesByAddress.ts +2 -1
  155. package/src/contract-functions/getStakeAndBakeFee/__tests__/getStakeAndBakeFee.test.ts +8 -4
  156. package/src/contract-functions/getStakeAndBakeFee/getStakeAndBakeFee.tsx +1 -0
  157. package/src/contract-functions/index.ts +2 -2
  158. package/src/contract-functions/signNetworkFee/signNetworkFee.ts +1 -0
  159. package/src/contract-functions/signStakeAndBake/__tests__/signStakeAndBake.test.ts +5 -4
  160. package/src/contract-functions/signStakeAndBake/handleApprove.ts +1 -0
  161. package/src/contract-functions/signStakeAndBake/index.ts +0 -1
  162. package/src/contract-functions/signStakeAndBake/signStakeAndBake.ts +15 -17
  163. package/src/contract-functions/signStakeAndBake/typed-data-builder.ts +6 -6
  164. package/src/contract-functions/signStakeAndBake/utils.ts +2 -1
  165. package/src/contract-functions/signStakeAndBake/validation.ts +5 -4
  166. package/src/contract-functions/unstakeLBTC/unstakeLBTC.ts +2 -1
  167. package/src/debug-api/btc-script-to-address.ts +1 -0
  168. package/src/debug-api/btc-tx-info.ts +2 -1
  169. package/src/debug-api/evm-by-btc-address.ts +1 -0
  170. package/src/defi/README.md +62 -33
  171. package/src/defi/defi-registry.stories.tsx +3 -1
  172. package/src/defi/defi-registry.ts +2 -1
  173. package/src/defi/index.ts +1 -2
  174. package/src/index.ts +34 -32
  175. package/src/metrics/get-additional-rewards.ts +3 -2
  176. package/src/metrics/get-lbtc-apy.ts +2 -1
  177. package/src/metrics/get-lbtc-stats.stories.tsx +2 -2
  178. package/src/metrics/get-lbtc-stats.ts +1 -0
  179. package/src/metrics/get-positions-summary.stories.tsx +4 -4
  180. package/src/metrics/get-positions-summary.ts +2 -1
  181. package/src/stories/arg-types.ts +1 -1
  182. package/src/tokens/abi/ASSET_ROUTER_ABI.ts +1 -1
  183. package/src/tokens/cross-chain-addresses.stories.tsx +16 -17
  184. package/src/tokens/denomination-utils.stories.tsx +6 -7
  185. package/src/tokens/getLbtcContractAddresses.stories.tsx +7 -8
  186. package/src/tokens/getTokenByAddress.stories.tsx +6 -7
  187. package/src/tokens/getTokenContractInfo.stories.tsx +9 -10
  188. package/src/tokens/isUpgradedContract.stories.tsx +4 -5
  189. package/src/tokens/lbtc-addresses.ts +1 -0
  190. package/src/tokens/token-addresses.ts +72 -49
  191. package/src/tokens/tokens.ts +8 -7
  192. package/src/utils/block.ts +1 -0
  193. package/src/utils/env.ts +1 -0
  194. package/src/utils/err.ts +3 -2
  195. package/src/utils/transaction-executor.ts +2 -1
  196. package/src/vaults/index.ts +14 -21
  197. package/src/vaults/lib/config.ts +1 -0
  198. package/src/vaults/lib/metrics/get-vault-apy.ts +2 -1
  199. package/src/vaults/lib/metrics/get-vault-points.ts +2 -1
  200. package/src/vaults/lib/metrics/get-vault-tvl.ts +3 -2
  201. package/src/vaults/lib/ops/deposit.ts +2 -1
  202. package/src/vaults/lib/ops/get-vault-deposits.ts +6 -5
  203. package/src/vaults/lib/ops/get-vault-withdrawals.ts +6 -5
  204. package/src/vaults/lib/ops/withdraw.ts +2 -1
@@ -19,6 +19,7 @@ import BigNumber from 'bignumber.js';
19
19
  import type { EIP1193Provider } from 'viem';
20
20
  import type { Mock } from 'vitest';
21
21
  import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
22
+
22
23
  import { ChainId } from '../../../common/chains';
23
24
  import { DefiProtocol } from '../../../defi/defi-registry';
24
25
  import { Token } from '../../../tokens/token-addresses';
@@ -29,11 +30,11 @@ import { StakeAndBakeValidationError } from '../validation';
29
30
  // Mock dependencies
30
31
  vi.mock('../../../clients/wallet-client', () => ({
31
32
  makeWalletClient: vi.fn(() => ({
32
- signTypedData: vi.fn(async typedData => {
33
+ signTypedData: vi.fn(async _typedData => {
33
34
  // Return a mock signature - can't JSON.stringify BigInt values
34
35
  return '0xmocksignature1234567890abcdef';
35
36
  }),
36
- writeContract: vi.fn(async params => {
37
+ writeContract: vi.fn(async _params => {
37
38
  // Return a mock transaction hash for approve transactions
38
39
  return '0xapprovetxhash1234567890abcdef';
39
40
  }),
@@ -42,7 +43,7 @@ vi.mock('../../../clients/wallet-client', () => ({
42
43
 
43
44
  vi.mock('../../../clients/public-client', () => ({
44
45
  makePublicClient: vi.fn(() => ({
45
- readContract: vi.fn(async ({ functionName, args }) => {
46
+ readContract: vi.fn(async ({ functionName }) => {
46
47
  // Mock nonce response
47
48
  if (functionName === 'nonces') {
48
49
  return 5n; // Mock nonce value
@@ -66,7 +67,7 @@ vi.mock('../../../clients/public-client', () => ({
66
67
  }));
67
68
 
68
69
  vi.mock('../../../tokens/tokens', () => ({
69
- getTokenContractInfo: vi.fn(async (token, chainId, env, addressKind) => {
70
+ getTokenContractInfo: vi.fn(async (token, chainId, _env, _addressKind) => {
70
71
  // Return mock contract info based on token
71
72
  if (token === Token.LBTC) {
72
73
  return {
@@ -1,4 +1,5 @@
1
1
  import { Abi } from 'viem';
2
+
2
3
  import { makePublicClient } from '../../clients/public-client';
3
4
  import { makeWalletClient } from '../../clients/wallet-client';
4
5
  import { ChainId } from '../../common/chains';
@@ -1,3 +1,2 @@
1
1
  export * from './signStakeAndBake';
2
2
  export { getStakeAndBakeConfig } from './validation';
3
-
@@ -1,10 +1,11 @@
1
1
  import { DEFAULT_ENV } from '@lombard.finance/sdk-common';
2
2
  import BigNumber from 'bignumber.js';
3
+
3
4
  import { CommonWriteParameters } from '../../common/parameters';
4
5
  import {
5
- ApprovalMode,
6
- DefiProtocol,
7
- StakeAndBakeToken,
6
+ ApprovalMode,
7
+ DefiProtocol,
8
+ StakeAndBakeToken,
8
9
  } from '../../defi/defi-registry';
9
10
  import { DAY, now, toUnix } from '../../utils/time';
10
11
  import { getPermitNonce } from '../getPermitNonce/getPermitNonce';
@@ -12,8 +13,8 @@ import { handleApproveFlow } from './handleApprove';
12
13
  import { handlePermitFlow } from './handlePermit';
13
14
  import { buildTypedData } from './typed-data-builder';
14
15
  import {
15
- calculateStakeAndBakeLBTCAmount,
16
- getStakeAndBakeTokenContract,
16
+ calculateStakeAndBakeLBTCAmount,
17
+ getStakeAndBakeTokenContract,
17
18
  } from './utils';
18
19
  import { getStakeAndBakeConfig } from './validation';
19
20
 
@@ -99,19 +100,15 @@ export async function signStakeAndBake({
99
100
  rpcUrl,
100
101
  env = DEFAULT_ENV,
101
102
  }: ISignStakeAndBakeParams): Promise<ISignStakeAndBakeResult> {
102
- const strategy = getStakeAndBakeConfig(
103
- vaultKey,
104
- token,
105
- chainId,
106
- env,
107
- );
103
+ const strategy = getStakeAndBakeConfig(vaultKey, token, chainId, env);
108
104
 
109
105
  const spenderAddress = strategy.spenderContract.address;
110
106
 
111
107
  // Calculate permit value (with conversion if needed)
112
- const permitValue = strategy.amountStrategy === 'btcToLbtc'
113
- ? await calculateStakeAndBakeLBTCAmount(value, env)
114
- : new BigNumber(value);
108
+ const permitValue =
109
+ strategy.amountStrategy === 'btcToLbtc'
110
+ ? await calculateStakeAndBakeLBTCAmount(value, env)
111
+ : new BigNumber(value);
115
112
 
116
113
  // Get token contract (always use Token address for permits/approves, not adapter)
117
114
  const tokenContract = await getStakeAndBakeTokenContract(token, chainId, env);
@@ -123,9 +120,10 @@ export async function signStakeAndBake({
123
120
  strategy.approval.deadlineStrategy === 'zero' ? 0n : BigInt(expiry);
124
121
 
125
122
  // Get nonce if required
126
- const nonce = strategy.approval.nonceStrategy === 'chain'
127
- ? BigInt(await getPermitNonce({ owner: account, chainId, rpcUrl, env }))
128
- : 0n;
123
+ const nonce =
124
+ strategy.approval.nonceStrategy === 'chain'
125
+ ? BigInt(await getPermitNonce({ owner: account, chainId, rpcUrl, env }))
126
+ : 0n;
129
127
 
130
128
  // Build typed data using config
131
129
  const typedData = buildTypedData({
@@ -4,6 +4,7 @@
4
4
  */
5
5
 
6
6
  import type { Address } from 'viem';
7
+
7
8
  import type { ChainId } from '../../common/chains';
8
9
  import type { ApprovalMode } from '../../defi/defi-registry';
9
10
 
@@ -64,10 +65,10 @@ export interface TypedDataParams {
64
65
 
65
66
  /**
66
67
  * Builds EIP-712 typed data structure for signatures.
67
- *
68
+ *
68
69
  * @param params - Typed data parameters
69
70
  * @returns EIP-712 typed data structure ready for signing
70
- *
71
+ *
71
72
  * @example
72
73
  * ```typescript
73
74
  * const typedData = buildTypedData({
@@ -82,7 +83,7 @@ export interface TypedDataParams {
82
83
  * nonce: 0n,
83
84
  * deadline: 1234567890n,
84
85
  * });
85
- *
86
+ *
86
87
  * const signature = await walletClient.signTypedData(typedData);
87
88
  * ```
88
89
  */
@@ -116,10 +117,10 @@ export function buildTypedData(params: TypedDataParams) {
116
117
  /**
117
118
  * Serializes typed data to JSON string.
118
119
  * Handles BigInt serialization by converting to strings.
119
- *
120
+ *
120
121
  * @param typedData - Typed data structure from buildTypedData
121
122
  * @returns JSON string representation
122
- *
123
+ *
123
124
  * @example
124
125
  * ```typescript
125
126
  * const typedData = buildTypedData(params);
@@ -134,4 +135,3 @@ export function serializeTypedData(
134
135
  typeof v === 'bigint' ? v.toString() : v,
135
136
  );
136
137
  }
137
-
@@ -1,5 +1,6 @@
1
1
  import { Env } from '@lombard.finance/sdk-common';
2
2
  import BigNumber from 'bignumber.js';
3
+
3
4
  import { getExchangeRatio } from '../../api-functions/getLBTCExchangeRate/get-exchange-ratio';
4
5
  import { StakeAndBakeToken } from '../../defi/defi-registry';
5
6
  import { AddressKind, Token } from '../../tokens/token-addresses';
@@ -54,7 +55,7 @@ export async function calculateStakeAndBakeLBTCAmount(
54
55
  const lbtcAmount = new BigNumber(btcAmount).dividedBy(btcTokenRatio);
55
56
 
56
57
  return lbtcAmount;
57
- } catch (error) {
58
+ } catch {
58
59
  throw new Error('Failed to get exchange ratio for stake and bake');
59
60
  }
60
61
  }
@@ -4,12 +4,13 @@
4
4
  */
5
5
 
6
6
  import { Env } from '@lombard.finance/sdk-common';
7
+
7
8
  import type { ChainId } from '../../common/chains';
8
9
  import {
9
- DEFI_REGISTRY,
10
- DefiProtocol,
11
- StakeAndBakeStrategy,
12
- StakeAndBakeToken,
10
+ DEFI_REGISTRY,
11
+ DefiProtocol,
12
+ StakeAndBakeStrategy,
13
+ StakeAndBakeToken,
13
14
  } from '../../defi/defi-registry';
14
15
 
15
16
  /**
@@ -1,6 +1,7 @@
1
1
  import { getOutputScript } from '@lombard.finance/sdk-common';
2
2
  import BigNumber from 'bignumber.js';
3
- import { Address, Hex, erc20Abi, parseGwei } from 'viem';
3
+ import { Address, erc20Abi, Hex, parseGwei } from 'viem';
4
+
4
5
  import { makePublicClient } from '../../clients/public-client';
5
6
  import { makeWalletClient } from '../../clients/wallet-client';
6
7
  import {
@@ -1,5 +1,6 @@
1
1
  import { Env } from '@lombard.finance/sdk-common';
2
2
  import axios from 'axios';
3
+
3
4
  import { getApiConfig } from '../common/api-config';
4
5
 
5
6
  type BtcScriptToAddressResponse = {
@@ -1,6 +1,7 @@
1
1
  import { Env } from '@lombard.finance/sdk-common';
2
2
  import axios from 'axios';
3
3
  import { Address } from 'viem';
4
+
4
5
  import { getApiConfig } from '../common/api-config';
5
6
  import { BlockchainIdentifier } from '../common/blockchain-identifier';
6
7
 
@@ -19,7 +20,7 @@ type BtcTxInfoResponse = {
19
20
  };
20
21
 
21
22
  export const fetchBtcTxInfo = async (txHash: string, env?: Env) => {
22
- const { baseApiUrl } = getApiConfig();
23
+ const { baseApiUrl } = getApiConfig(env);
23
24
  try {
24
25
  const { data } = await axios.get<BtcTxInfoResponse>(
25
26
  `${baseApiUrl}/api/v1/debug/btc-tx-info/${txHash}`,
@@ -1,6 +1,7 @@
1
1
  import { Env } from '@lombard.finance/sdk-common';
2
2
  import axios from 'axios';
3
3
  import { Address } from 'viem';
4
+
4
5
  import { getApiConfig } from '../common/api-config';
5
6
  import { BlockchainIdentifier } from '../common/blockchain-identifier';
6
7
 
@@ -29,6 +29,7 @@ DEFI_REGISTRY
29
29
  - `'approve'` - On-chain ERC-20 approval transaction (user pays gas)
30
30
 
31
31
  2. **`TokenApprovalConfig`** - Defines approval behavior:
32
+
32
33
  ```typescript
33
34
  {
34
35
  mode: 'permit' | 'approve',
@@ -59,10 +60,10 @@ The `getStakeAndBakeConfig()` function queries the registry:
59
60
  import { getStakeAndBakeConfig } from './validation';
60
61
 
61
62
  const { tokenConfig, spenderContract } = getStakeAndBakeConfig(
62
- 'Veda', // Protocol
63
- Token.LBTC, // Token
64
- ChainId.ethereum, // Chain
65
- Env.prod, // Environment
63
+ 'Veda', // Protocol
64
+ Token.LBTC, // Token
65
+ ChainId.ethereum, // Chain
66
+ Env.prod, // Environment
66
67
  );
67
68
 
68
69
  // Returns:
@@ -80,14 +81,14 @@ The main function uses the registry to determine behavior:
80
81
  export async function signStakeAndBake(params) {
81
82
  // 1. Get config from registry
82
83
  const { tokenConfig, spenderContract } = getStakeAndBakeConfig(...);
83
-
84
+
84
85
  // 2. Build typed data based on config
85
86
  const typedData = buildTypedData({
86
87
  mode: tokenConfig.mode, // permit or approve
87
88
  domainName: tokenConfig.eip712Domain.name,
88
89
  // ...
89
90
  });
90
-
91
+
91
92
  // 3. Route to appropriate handler
92
93
  if (tokenConfig.mode === 'approve') {
93
94
  return handleApproveFlow({ ... }); // Submit transaction
@@ -110,7 +111,7 @@ export async function signStakeAndBake(params) {
110
111
  const VEDA_STAKE_AND_BAKE_CHAINS = [
111
112
  ChainId.ethereum,
112
113
  ChainId.binanceSmartChain,
113
- ChainId.base, // ← ADD THIS
114
+ ChainId.base, // ← ADD THIS
114
115
  // Testnets:
115
116
  ChainId.binanceSmartChainTestnet,
116
117
  ChainId.holesky,
@@ -121,6 +122,7 @@ const VEDA_STAKE_AND_BAKE_CHAINS = [
121
122
  ```
122
123
 
123
124
  **What Happens:**
125
+
124
126
  - `forChains()` automatically creates registry entries for all chains
125
127
  - LBTC inherits the same `LBTC_PERMIT_CONFIG` on Base
126
128
  - Uses the correct spender contract from `VEDA_VAULT_SPENDER_CONTRACTS[ChainId.base]`
@@ -138,7 +140,7 @@ const VEDA_STAKE_AND_BAKE_CHAINS = [
138
140
  const WBTC_PERMIT_CONFIG: TokenApprovalConfig = {
139
141
  mode: 'permit',
140
142
  eip712Domain: {
141
- name: 'Wrapped Bitcoin', // Check wBTC contract
143
+ name: 'Wrapped Bitcoin', // Check wBTC contract
142
144
  version: '1',
143
145
  },
144
146
  requiresNonce: true,
@@ -148,12 +150,16 @@ const WBTC_PERMIT_CONFIG: TokenApprovalConfig = {
148
150
  // 2. Add to DEFI_REGISTRY
149
151
  export const DEFI_REGISTRY = {
150
152
  Veda: {
151
- [Token.LBTC]: { /* existing */ },
152
- BTC: { /* existing */ },
153
-
153
+ [Token.LBTC]: {
154
+ /* existing */
155
+ },
156
+ BTC: {
157
+ /* existing */
158
+ },
159
+
154
160
  // Add wBTC
155
- [Token.wBTC]: forEnvs([Env.prod, Env.testnet], (env) => {
156
- return forChains([ChainId.ethereum, ChainId.base], (chain) => ({
161
+ [Token.wBTC]: forEnvs([Env.prod, Env.testnet], env => {
162
+ return forChains([ChainId.ethereum, ChainId.base], chain => ({
157
163
  approvalConfig: WBTC_PERMIT_CONFIG,
158
164
  spenderContract: VEDA_VAULT_SPENDER_CONTRACTS[chain],
159
165
  }));
@@ -176,13 +182,17 @@ export const DEFI_REGISTRY = {
176
182
  export const DefiProtocol = {
177
183
  Veda: 'Veda',
178
184
  Silo: 'Silo',
179
- Aave: 'Aave', // ← ADD THIS
185
+ Aave: 'Aave', // ← ADD THIS
180
186
  } as const;
181
187
 
182
188
  // 2. Add protocol metadata
183
189
  export const DefiProtocols = {
184
- [DefiProtocol.Veda]: { /* existing */ },
185
- [DefiProtocol.Silo]: { /* existing */ },
190
+ [DefiProtocol.Veda]: {
191
+ /* existing */
192
+ },
193
+ [DefiProtocol.Silo]: {
194
+ /* existing */
195
+ },
186
196
  [DefiProtocol.Aave]: {
187
197
  name: 'Aave v3',
188
198
  url: 'https://aave.com',
@@ -206,12 +216,12 @@ const AAVE_SPENDER_CONTRACTS = {
206
216
  // 4. Add to registry
207
217
  export const DEFI_REGISTRY = {
208
218
  // ... existing protocols
209
-
219
+
210
220
  Aave: {
211
221
  // LBTC uses standard permit
212
222
  [Token.LBTC]: forEnvs([Env.prod], () => {
213
- return forChains([ChainId.ethereum, ChainId.base], (chain) => ({
214
- approvalConfig: LBTC_PERMIT_CONFIG, // Reuse existing config
223
+ return forChains([ChainId.ethereum, ChainId.base], chain => ({
224
+ approvalConfig: LBTC_PERMIT_CONFIG, // Reuse existing config
215
225
  spenderContract: AAVE_SPENDER_CONTRACTS[chain],
216
226
  }));
217
227
  }),
@@ -220,6 +230,7 @@ export const DEFI_REGISTRY = {
220
230
  ```
221
231
 
222
232
  **That's it!** Now you can call:
233
+
223
234
  ```typescript
224
235
  await signStakeAndBake({
225
236
  vaultKey: 'Aave',
@@ -240,12 +251,12 @@ await signStakeAndBake({
240
251
 
241
252
  // 1. Define approval config for USDC
242
253
  const USDC_APPROVE_CONFIG: TokenApprovalConfig = {
243
- mode: 'approve', // On-chain transaction
254
+ mode: 'approve', // On-chain transaction
244
255
  eip712Domain: {
245
256
  name: 'USD Coin',
246
257
  version: '2',
247
258
  },
248
- requiresNonce: false, // Approve doesn't use nonce
259
+ requiresNonce: false, // Approve doesn't use nonce
249
260
  expiryBehavior: 'zero', // Approve uses zero deadline
250
261
  };
251
262
 
@@ -253,8 +264,10 @@ const USDC_APPROVE_CONFIG: TokenApprovalConfig = {
253
264
  export const DEFI_REGISTRY = {
254
265
  // ...
255
266
  Silo: {
256
- [Token.BTCb]: { /* existing */ },
257
-
267
+ [Token.BTCb]: {
268
+ /* existing */
269
+ },
270
+
258
271
  // Add USDC
259
272
  [Token.USDC]: forEnvs([Env.testnet], () => {
260
273
  return forChains([ChainId.avalancheFuji], () => ({
@@ -280,7 +293,7 @@ The registry automatically validates:
280
293
  // Example: Unsupported token
281
294
  await signStakeAndBake({
282
295
  vaultKey: 'Veda',
283
- token: Token.BTCb, // BTCb not configured for Veda
296
+ token: Token.BTCb, // BTCb not configured for Veda
284
297
  chainId: ChainId.ethereum,
285
298
  });
286
299
  // Throws: StakeAndBakeValidationError
@@ -289,6 +302,7 @@ await signStakeAndBake({
289
302
  ```
290
303
 
291
304
  **Error Codes:**
305
+
292
306
  - `UNSUPPORTED_VAULT` - Protocol not in registry
293
307
  - `UNSUPPORTED_CHAIN` - Chain not in vault's `stakeAndBakeChains`
294
308
  - `UNSUPPORTED_TOKEN` - Token not configured for protocol
@@ -300,13 +314,14 @@ await signStakeAndBake({
300
314
  ## 🛠️ Helper Functions
301
315
 
302
316
  ### `forChains()`
317
+
303
318
  Generate config for multiple chains with same settings:
304
319
 
305
320
  ```typescript
306
- forChains([ChainId.ethereum, ChainId.base, ChainId.bsc], (chain) => ({
321
+ forChains([ChainId.ethereum, ChainId.base, ChainId.bsc], chain => ({
307
322
  approvalConfig: LBTC_PERMIT_CONFIG,
308
323
  spenderContract: SPENDER_CONTRACTS[chain],
309
- }))
324
+ }));
310
325
 
311
326
  // Generates:
312
327
  // {
@@ -317,12 +332,13 @@ forChains([ChainId.ethereum, ChainId.base, ChainId.bsc], (chain) => ({
317
332
  ```
318
333
 
319
334
  ### `forEnvs()`
335
+
320
336
  Generate config for multiple environments:
321
337
 
322
338
  ```typescript
323
- forEnvs([Env.prod, Env.testnet], (env) => ({
339
+ forEnvs([Env.prod, Env.testnet], env => ({
324
340
  // Config for this env
325
- }))
341
+ }));
326
342
 
327
343
  // Generates:
328
344
  // {
@@ -343,6 +359,7 @@ defi/
343
359
  ```
344
360
 
345
361
  **Related Files:**
362
+
346
363
  ```
347
364
  contract-functions/signStakeAndBake/
348
365
  ├── signStakeAndBake.ts ← Main function (uses registry)
@@ -358,7 +375,9 @@ contract-functions/signStakeAndBake/
358
375
  ## 🎯 Best Practices
359
376
 
360
377
  ### 1. **Reuse Approval Configs**
378
+
361
379
  Don't duplicate configs for the same token behavior:
380
+
362
381
  ```typescript
363
382
  // ✅ Good: Reuse
364
383
  [Token.LBTC]: forEnvs(..., () => ({
@@ -378,9 +397,10 @@ Don't duplicate configs for the same token behavior:
378
397
  ```
379
398
 
380
399
  ### 2. **Use forChains() for Multi-Chain Support**
400
+
381
401
  ```typescript
382
402
  // ✅ Good: DRY with forChains()
383
- [Token.LBTC]: forEnvs([Env.prod], () =>
403
+ [Token.LBTC]: forEnvs([Env.prod], () =>
384
404
  forChains([ChainId.ethereum, ChainId.base], (chain) => ({
385
405
  approvalConfig: LBTC_PERMIT_CONFIG,
386
406
  spenderContract: SPENDER_CONTRACTS[chain],
@@ -397,7 +417,9 @@ Don't duplicate configs for the same token behavior:
397
417
  ```
398
418
 
399
419
  ### 3. **Define Spender Contracts Once**
420
+
400
421
  Store spender contracts in a map:
422
+
401
423
  ```typescript
402
424
  // At top of file
403
425
  const VEDA_VAULT_SPENDER_CONTRACTS = {
@@ -407,11 +429,13 @@ const VEDA_VAULT_SPENDER_CONTRACTS = {
407
429
  };
408
430
 
409
431
  // Then reference them
410
- spenderContract: VEDA_VAULT_SPENDER_CONTRACTS[chain]
432
+ spenderContract: VEDA_VAULT_SPENDER_CONTRACTS[chain];
411
433
  ```
412
434
 
413
435
  ### 4. **Document Token-Specific Behavior**
436
+
414
437
  Use comments for special cases:
438
+
415
439
  ```typescript
416
440
  // BTC is a virtual token that converts to LBTC via exchange ratio
417
441
  BTC: forEnvs(Object.values(Env), () => {
@@ -427,7 +451,9 @@ BTC: forEnvs(Object.values(Env), () => {
427
451
  ## 🧪 Testing New Integrations
428
452
 
429
453
  ### 1. **Unit Tests**
454
+
430
455
  Add test cases in `signStakeAndBake.test.ts`:
456
+
431
457
  ```typescript
432
458
  it('should handle NewToken on NewProtocol', async () => {
433
459
  const result = await signStakeAndBake({
@@ -436,14 +462,16 @@ it('should handle NewToken on NewProtocol', async () => {
436
462
  chainId: ChainId.ethereum,
437
463
  // ...
438
464
  });
439
-
440
- expect(result.mode).toBe('permit'); // or 'approve'
465
+
466
+ expect(result.mode).toBe('permit'); // or 'approve'
441
467
  expect(result.signature).toBeTruthy();
442
468
  });
443
469
  ```
444
470
 
445
471
  ### 2. **Storybook Testing**
472
+
446
473
  Test in Storybook UI:
474
+
447
475
  ```bash
448
476
  yarn storybook
449
477
  # Navigate to: write/signStakeAndBake
@@ -451,7 +479,9 @@ yarn storybook
451
479
  ```
452
480
 
453
481
  ### 3. **Integration Testing**
482
+
454
483
  Use the verification script:
484
+
455
485
  ```bash
456
486
  yarn verify:stake-and-bake
457
487
  ```
@@ -469,4 +499,3 @@ Adding a new integration? Follow these steps:
469
499
  - [ ] Add test case(s)
470
500
  - [ ] Test in Storybook
471
501
  - [ ] Update exports in `index.ts` if adding new protocol
472
-
@@ -285,7 +285,9 @@ function DefiRegistryViewer() {
285
285
  toggleProtocol(protocol);
286
286
  }}
287
287
  >
288
- <span className="me-2">{isProtocolExpanded ? '▼' : '▶'}</span>
288
+ <span className="me-2">
289
+ {isProtocolExpanded ? '▼' : '▶'}
290
+ </span>
289
291
  <strong>
290
292
  {DefiProtocols[protocol as DefiProtocol]?.name || protocol}
291
293
  </strong>
@@ -7,6 +7,7 @@
7
7
 
8
8
  import { Env } from '@lombard.finance/sdk-common';
9
9
  import { Abi } from 'viem';
10
+
10
11
  import { ChainId } from '../common/chains';
11
12
  import { ContractInfo } from '../common/contract-info';
12
13
  import { Token } from '../tokens/token-addresses';
@@ -93,7 +94,7 @@ function getVedaSpenderContract(
93
94
  return contract;
94
95
  }
95
96
 
96
- const DefiRegistryTokens = {
97
+ export const DefiRegistryTokens = {
97
98
  LBTC: Token.LBTC,
98
99
  BTCb: Token.BTCb,
99
100
  BTC: 'BTC',
package/src/defi/index.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  export {
2
2
  DefiProtocol,
3
3
  type DefiRegistryToken,
4
- type StakeAndBakeToken
4
+ type StakeAndBakeToken,
5
5
  } from './defi-registry';
6
-
package/src/index.ts CHANGED
@@ -15,33 +15,32 @@ export * from './common/api-config';
15
15
  export * from './common/blockchain-identifier';
16
16
  export * from './common/chains';
17
17
  export {
18
- SOLANA_DEVNET_CHAIN,
19
- SOLANA_MAINNET_CHAIN,
20
- SOLANA_TESTNET_CHAIN,
21
- SUI_DEVNET_CHAIN,
22
- SUI_MAINNET_CHAIN,
23
- SUI_TESTNET_CHAIN
18
+ SOLANA_DEVNET_CHAIN,
19
+ SOLANA_MAINNET_CHAIN,
20
+ SOLANA_TESTNET_CHAIN,
21
+ SUI_DEVNET_CHAIN,
22
+ SUI_MAINNET_CHAIN,
23
+ SUI_TESTNET_CHAIN,
24
24
  } from './common/chains';
25
25
  export * from './tokens/lbtc-addresses';
26
26
  export * from './tokens/token-addresses';
27
27
  export * from './utils/satoshi';
28
28
 
29
29
  // Metrics:
30
- export { getLBTCStats } from './metrics/get-lbtc-stats';
31
-
32
30
  export {
33
- getAdditionalRewards,
34
- type RewardsDistribution
31
+ getAdditionalRewards,
32
+ type RewardsDistribution,
35
33
  } from './metrics/get-additional-rewards';
36
34
  export {
37
- getApy,
38
- getEstimatedApy,
39
- type LbtcApy,
40
- type LbtcEstimatedApy
35
+ getApy,
36
+ getEstimatedApy,
37
+ type LbtcApy,
38
+ type LbtcEstimatedApy,
41
39
  } from './metrics/get-lbtc-apy';
40
+ export { getLBTCStats } from './metrics/get-lbtc-stats';
42
41
  export {
43
- getPositionsSummary,
44
- type PositionsSummary
42
+ getPositionsSummary,
43
+ type PositionsSummary,
45
44
  } from './metrics/get-positions-summary';
46
45
 
47
46
  // Tokens:
@@ -54,28 +53,31 @@ export type { Address, EIP1193Provider } from 'viem';
54
53
 
55
54
  // Signer support (custom transaction signing):
56
55
  export {
57
- createAccountFromSigner,
58
- createWalletClientFromSigner, SignerError, validateTransactionRequest,
59
- type DispatchCallback,
60
- type EvmTransactionRequest,
61
- type SignerAdapter
56
+ createAccountFromSigner,
57
+ createWalletClientFromSigner,
58
+ type DispatchCallback,
59
+ type EvmTransactionRequest,
60
+ type SignerAdapter,
61
+ SignerError,
62
+ validateTransactionRequest,
62
63
  } from './clients/evm-signer-adapter';
63
-
64
64
  export {
65
- isProviderFlow,
66
- isSignerFlow,
67
- type CommonSignerWriteParameters
65
+ type CommonSignerWriteParameters,
66
+ isProviderFlow,
67
+ isSignerFlow,
68
68
  } from './common/parameters';
69
69
 
70
70
  // Bridge:
71
71
  export {
72
- bridge,
73
- bridgeCCIP,
74
- bridgeOFT,
75
- getBridgeInfo, OFT_GAS_LIMIT,
76
- OFT_HI_GAS_LIMIT,
77
- OFT_HI_GAS_LIMIT_CHAINS, type BridgeCCIPParameters,
78
- type BridgeParameters
72
+ bridge,
73
+ bridgeCCIP,
74
+ type BridgeCCIPParameters,
75
+ bridgeOFT,
76
+ type BridgeParameters,
77
+ getBridgeInfo,
78
+ OFT_GAS_LIMIT,
79
+ OFT_HI_GAS_LIMIT,
80
+ OFT_HI_GAS_LIMIT_CHAINS,
79
81
  } from './bridge';
80
82
 
81
83
  // Debug: