@lombard.finance/sdk 2.4.0 → 2.4.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.
@@ -0,0 +1,175 @@
1
+ [
2
+ {
3
+ "inputs": [
4
+ { "internalType": "address", "name": "account", "type": "address" },
5
+ {
6
+ "internalType": "contract BoringVault",
7
+ "name": "boringVault",
8
+ "type": "address"
9
+ }
10
+ ],
11
+ "name": "balanceOf",
12
+ "outputs": [
13
+ { "internalType": "uint256", "name": "shares", "type": "uint256" }
14
+ ],
15
+ "stateMutability": "view",
16
+ "type": "function"
17
+ },
18
+ {
19
+ "inputs": [
20
+ { "internalType": "address", "name": "account", "type": "address" },
21
+ {
22
+ "internalType": "contract BoringVault",
23
+ "name": "boringVault",
24
+ "type": "address"
25
+ },
26
+ {
27
+ "internalType": "contract AccountantWithRateProviders",
28
+ "name": "accountant",
29
+ "type": "address"
30
+ }
31
+ ],
32
+ "name": "balanceOfInAssets",
33
+ "outputs": [
34
+ { "internalType": "uint256", "name": "assets", "type": "uint256" }
35
+ ],
36
+ "stateMutability": "view",
37
+ "type": "function"
38
+ },
39
+ {
40
+ "inputs": [
41
+ { "internalType": "address", "name": "account", "type": "address" },
42
+ {
43
+ "internalType": "contract ERC20",
44
+ "name": "depositAsset",
45
+ "type": "address"
46
+ },
47
+ { "internalType": "uint256", "name": "depositAmount", "type": "uint256" },
48
+ {
49
+ "internalType": "contract BoringVault",
50
+ "name": "boringVault",
51
+ "type": "address"
52
+ },
53
+ {
54
+ "internalType": "contract TellerWithMultiAssetSupport",
55
+ "name": "teller",
56
+ "type": "address"
57
+ }
58
+ ],
59
+ "name": "checkUserDeposit",
60
+ "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
61
+ "stateMutability": "view",
62
+ "type": "function"
63
+ },
64
+ {
65
+ "inputs": [
66
+ { "internalType": "address", "name": "account", "type": "address" },
67
+ {
68
+ "internalType": "contract ERC20",
69
+ "name": "depositAsset",
70
+ "type": "address"
71
+ },
72
+ { "internalType": "uint256", "name": "depositAmount", "type": "uint256" },
73
+ {
74
+ "internalType": "contract TellerWithMultiAssetSupport",
75
+ "name": "teller",
76
+ "type": "address"
77
+ }
78
+ ],
79
+ "name": "checkUserDepositWithPermit",
80
+ "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
81
+ "stateMutability": "view",
82
+ "type": "function"
83
+ },
84
+ {
85
+ "inputs": [
86
+ {
87
+ "internalType": "contract AccountantWithRateProviders",
88
+ "name": "accountant",
89
+ "type": "address"
90
+ }
91
+ ],
92
+ "name": "exchangeRate",
93
+ "outputs": [
94
+ { "internalType": "uint256", "name": "rate", "type": "uint256" }
95
+ ],
96
+ "stateMutability": "view",
97
+ "type": "function"
98
+ },
99
+ {
100
+ "inputs": [
101
+ {
102
+ "internalType": "contract TellerWithMultiAssetSupport",
103
+ "name": "teller",
104
+ "type": "address"
105
+ }
106
+ ],
107
+ "name": "isTellerPaused",
108
+ "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
109
+ "stateMutability": "view",
110
+ "type": "function"
111
+ },
112
+ {
113
+ "inputs": [
114
+ {
115
+ "internalType": "contract ERC20",
116
+ "name": "depositAsset",
117
+ "type": "address"
118
+ },
119
+ { "internalType": "uint256", "name": "depositAmount", "type": "uint256" },
120
+ {
121
+ "internalType": "contract BoringVault",
122
+ "name": "boringVault",
123
+ "type": "address"
124
+ },
125
+ {
126
+ "internalType": "contract AccountantWithRateProviders",
127
+ "name": "accountant",
128
+ "type": "address"
129
+ }
130
+ ],
131
+ "name": "previewDeposit",
132
+ "outputs": [
133
+ { "internalType": "uint256", "name": "shares", "type": "uint256" }
134
+ ],
135
+ "stateMutability": "view",
136
+ "type": "function"
137
+ },
138
+ {
139
+ "inputs": [
140
+ {
141
+ "internalType": "contract BoringVault",
142
+ "name": "boringVault",
143
+ "type": "address"
144
+ },
145
+ {
146
+ "internalType": "contract AccountantWithRateProviders",
147
+ "name": "accountant",
148
+ "type": "address"
149
+ }
150
+ ],
151
+ "name": "totalAssets",
152
+ "outputs": [
153
+ { "internalType": "contract ERC20", "name": "asset", "type": "address" },
154
+ { "internalType": "uint256", "name": "assets", "type": "uint256" }
155
+ ],
156
+ "stateMutability": "view",
157
+ "type": "function"
158
+ },
159
+ {
160
+ "inputs": [
161
+ { "internalType": "address", "name": "account", "type": "address" },
162
+ {
163
+ "internalType": "contract TellerWithMultiAssetSupport",
164
+ "name": "teller",
165
+ "type": "address"
166
+ }
167
+ ],
168
+ "name": "userUnlockTime",
169
+ "outputs": [
170
+ { "internalType": "uint256", "name": "time", "type": "uint256" }
171
+ ],
172
+ "stateMutability": "view",
173
+ "type": "function"
174
+ }
175
+ ]
@@ -0,0 +1,54 @@
1
+ import { OChainId } from '../common/types/types';
2
+
3
+ import VEDA_VAULT_ABI from './abi/VEDA_VAULT_ABI.json';
4
+ import VEDA_VAULT_ACCOUNTANT_ABI from './abi/VEDA_VAULT_ACCOUNTANT_ABI.json';
5
+ import VEDA_VAULT_LENS_ABI from './abi/VEDA_VAULT_LENS_ABI.json';
6
+
7
+ export const VEDA_VAULT_CHAIN_ID = OChainId.ethereum;
8
+ export const VEDA_VAULT_CONTRACT = '0x5401b8620E5FB570064CA9114fd1e135fd77D57c';
9
+ export const VEDA_VAULT_ACCOUNTANT_CONTRACT =
10
+ '0x28634D0c5edC67CF2450E74deA49B90a4FF93dCE';
11
+ export const VEDA_VAULT_LENS_CONTRACT =
12
+ '0x5232bc0F5999f8dA604c42E1748A13a170F94A1B';
13
+
14
+ export const VEDA_VAULT_SPENDER_CONTRACTS = {
15
+ [OChainId.holesky]: '0x4A3cD83CEbb91E0Cd31EdA2Ee0F4AebfcCFCbBb6',
16
+ [OChainId.ethereum]: '0xC8bbF6153D7Ba105f1399D992ebd32B0541996ef',
17
+ [OChainId.binanceSmartChain]: '0xC8bbF6153D7Ba105f1399D992ebd32B0541996ef',
18
+ [OChainId.binanceSmartChainTestnet]:
19
+ '0x72143309A662bDB4aad5cA65Ab59eD8977D047C5',
20
+ } as const;
21
+
22
+ export enum Vault {
23
+ Veda = 'veda',
24
+ }
25
+
26
+ export const VaultNameMap = {
27
+ [Vault.Veda]: 'Veda / Lombard DeFi Vault',
28
+ } as const;
29
+
30
+ export const VAULTS = {
31
+ [Vault.Veda]: {
32
+ defaultChainId: VEDA_VAULT_CHAIN_ID,
33
+ chains: [
34
+ OChainId.base,
35
+ OChainId.binanceSmartChain,
36
+ OChainId.corn,
37
+ OChainId.ethereum,
38
+ ],
39
+ decimals: 8,
40
+ vaultContract: {
41
+ abi: VEDA_VAULT_ABI,
42
+ address: VEDA_VAULT_CONTRACT,
43
+ },
44
+ accountantContract: {
45
+ abi: VEDA_VAULT_ACCOUNTANT_ABI,
46
+ address: VEDA_VAULT_ACCOUNTANT_CONTRACT,
47
+ },
48
+ lensContract: {
49
+ abi: VEDA_VAULT_LENS_ABI,
50
+ address: VEDA_VAULT_LENS_CONTRACT,
51
+ },
52
+ spenderContracts: VEDA_VAULT_SPENDER_CONTRACTS,
53
+ },
54
+ } as const;
@@ -3,4 +3,4 @@ import LBTCABI from './LBTC.json';
3
3
  import BASCULE_ABI from './BASCULE.json';
4
4
  import STAKE_AND_BAKE from './STAKE_AND_BAKE.json';
5
5
 
6
- export { IERC20, LBTCABI, BASCULE_ABI, STAKE_AND_BAKE };
6
+ export { BASCULE_ABI, IERC20, LBTCABI, STAKE_AND_BAKE };
@@ -0,0 +1,51 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+
3
+ import { OChainId } from '../../common/types/types';
4
+ import { Button } from '../../stories/components/Button';
5
+ import useQuery from '../../stories/hooks/useQuery';
6
+ import { getShareValue, IGetShareValueParameters } from './getShareValue';
7
+ import { Vault } from '../../vaults';
8
+
9
+ const meta = {
10
+ title: 'Web3SDK/getShareValue',
11
+ component: StoryView,
12
+ tags: ['autodocs'],
13
+ } satisfies Meta<typeof StoryView>;
14
+
15
+ export default meta;
16
+
17
+ type Story = StoryObj<typeof meta>;
18
+
19
+ export const WithParams: Story = {
20
+ args: {
21
+ chainId: OChainId.ethereum,
22
+ vaultKey: Vault.Veda,
23
+ },
24
+ };
25
+
26
+ export function StoryView(props: IGetShareValueParameters) {
27
+ const request = async () => {
28
+ return getShareValue({
29
+ ...props,
30
+ });
31
+ };
32
+
33
+ const { data, error, isLoading, refetch } = useQuery(request, [], false);
34
+
35
+ const value = data?.toString();
36
+
37
+ return (
38
+ <div>
39
+ <Button onClick={refetch} disabled={isLoading} isLoading={isLoading}>
40
+ Get LBTCv value
41
+ </Button>
42
+
43
+ {data && (
44
+ <div className="mt-4 p-4 border rounded">
45
+ <h3 className="text-lg font-bold mb-2">LBTCv share value</h3>
46
+ <p>1 LBTCv = {value} LBTC</p>
47
+ </div>
48
+ )}
49
+ </div>
50
+ );
51
+ }
@@ -0,0 +1,58 @@
1
+ import BigNumber from 'bignumber.js';
2
+ import { TChainId } from '../../common/types/types';
3
+ import { ReadProvider } from '../../provider/ReadProvider';
4
+ import { getRpcUrlConfigFromChain } from '../utils/getRpcUrlConfigFromChain';
5
+ import { getErrorMessage } from '../../common/utils/getErrorMessage';
6
+ import { VAULTS } from '../../vaults';
7
+ import { fromSatoshi } from '../../common/utils/convertSatoshi';
8
+
9
+ export interface IGetShareValueParameters {
10
+ /**
11
+ * Chain ID for identifying the blockchain network (e.g., Ethereum, Binance Smart Chain, etc.)
12
+ */
13
+ chainId: TChainId;
14
+ /**
15
+ * Optional RPC URL to connect to the blockchain. If not provided, a default RPC URL might be used.
16
+ */
17
+ rpcUrl?: string;
18
+ /**
19
+ * Optional vault key specifying the vault in use
20
+ * @default {string} - "veda"
21
+ */
22
+ vaultKey?: 'veda';
23
+ }
24
+
25
+ /**
26
+ * Gets the value of a single share unit (in LBTC) from the specified vault.
27
+ */
28
+ export async function getShareValue({
29
+ chainId,
30
+ rpcUrl,
31
+ vaultKey = 'veda',
32
+ }: IGetShareValueParameters): Promise<BigNumber> {
33
+ const vault = VAULTS[vaultKey];
34
+ if (!vault) {
35
+ throw new Error(`Unknown vault key: ${vaultKey}`);
36
+ }
37
+
38
+ if (!(vault.chains as unknown as number[]).includes(chainId)) {
39
+ throw new Error(
40
+ `Unsupported chain id: ${chainId}. Please switch to one of the supported chains: ${vault.chains.join(', ')}`,
41
+ );
42
+ }
43
+
44
+ const rpcUrlConfig = getRpcUrlConfigFromChain(chainId, rpcUrl);
45
+ const provider = new ReadProvider({ chainId, rpcUrlConfig });
46
+
47
+ try {
48
+ const accountant = provider.createContract<
49
+ typeof vault.accountantContract.abi
50
+ >(vault.accountantContract.abi, vault.accountantContract.address);
51
+
52
+ const exchangeRate = await accountant.methods['getRate']().call();
53
+ return fromSatoshi(String(exchangeRate));
54
+ } catch (error) {
55
+ const errorMessage = getErrorMessage(error);
56
+ throw new Error(errorMessage);
57
+ }
58
+ }
@@ -0,0 +1 @@
1
+ export { getShareValue, type IGetShareValueParameters } from './getShareValue';
@@ -0,0 +1,60 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+
3
+ import { OChainId } from '../../common/types/types';
4
+ import { Button } from '../../stories/components/Button';
5
+ import useQuery from '../../stories/hooks/useQuery';
6
+ import {
7
+ getSharesByAddress,
8
+ IGetSharesByAddressParameters,
9
+ } from './getSharesByAddress';
10
+ import { Vault } from '../../vaults';
11
+ import { exampleEvmAddress } from '../../stories/const';
12
+ import { CodeBlock } from '../../stories/components/CodeBlock';
13
+
14
+ const meta = {
15
+ title: 'Web3SDK/getSharesByAddress',
16
+ component: StoryView,
17
+ tags: ['autodocs'],
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
+ chainId: OChainId.ethereum,
27
+ address: exampleEvmAddress,
28
+ vaultKey: Vault.Veda,
29
+ },
30
+ };
31
+
32
+ export function StoryView(props: IGetSharesByAddressParameters) {
33
+ const request = async () => {
34
+ return getSharesByAddress({
35
+ ...props,
36
+ });
37
+ };
38
+
39
+ const { data, error, isLoading, refetch } = useQuery(request, [], false);
40
+
41
+ return (
42
+ <div>
43
+ <Button onClick={refetch} disabled={isLoading} isLoading={isLoading}>
44
+ Get LBTCv shares owned
45
+ </Button>
46
+
47
+ <CodeBlock text={error || data} />
48
+
49
+ {data && (
50
+ <div className="mt-4 p-4 border rounded">
51
+ <h3 className="text-lg font-bold mb-2">LBTCv shares owned</h3>
52
+ <p>
53
+ <b>{data.balance.toString()}</b> LBTCv ={' '}
54
+ {data.balanceLbtc.toString()} LBTC
55
+ </p>
56
+ </div>
57
+ )}
58
+ </div>
59
+ );
60
+ }
@@ -0,0 +1,84 @@
1
+ import BigNumber from 'bignumber.js';
2
+ import { TChainId } from '../../common/types/types';
3
+ import { ReadProvider } from '../../provider/ReadProvider';
4
+ import { getRpcUrlConfigFromChain } from '../utils/getRpcUrlConfigFromChain';
5
+ import { getErrorMessage } from '../../common/utils/getErrorMessage';
6
+ import { VAULTS } from '../../vaults';
7
+ import { fromSatoshi } from '../../common/utils/convertSatoshi';
8
+ import { getShareValue } from '../getShareValue';
9
+
10
+ export interface IGetSharesByAddressParameters {
11
+ /**
12
+ * Chain ID for identifying the blockchain network (e.g., Ethereum, Binance Smart Chain, etc.)
13
+ */
14
+ chainId: TChainId;
15
+ /**
16
+ * Optional RPC URL to connect to the blockchain. If not provided, a default RPC URL might be used.
17
+ */
18
+ rpcUrl?: string;
19
+ /**
20
+ * The address of the share holder.
21
+ */
22
+ address: string;
23
+ /**
24
+ * Optional vault key specifying the vault in use
25
+ * @default {string} - "veda"
26
+ */
27
+ vaultKey?: 'veda';
28
+ }
29
+
30
+ interface IGetSharesByAddressResponse {
31
+ /** The amount of share owned. */
32
+ balance: BigNumber;
33
+ /** The value of a single share unit */
34
+ exchangeRate: BigNumber;
35
+ /** The balance represented in BTC. */
36
+ balanceLbtc: BigNumber;
37
+ }
38
+
39
+ /**
40
+ * Gets the amount of shares (LBTCv) owned by the provided address.
41
+ */
42
+ export async function getSharesByAddress({
43
+ chainId,
44
+ rpcUrl,
45
+ address,
46
+ vaultKey = 'veda',
47
+ }: IGetSharesByAddressParameters): Promise<IGetSharesByAddressResponse> {
48
+ const vault = VAULTS[vaultKey];
49
+ if (!vault) {
50
+ throw new Error(`Unknown vault key: ${vaultKey}`);
51
+ }
52
+
53
+ if (!(vault.chains as unknown as number[]).includes(chainId)) {
54
+ throw new Error(
55
+ `Unsupported chain id: ${chainId}. Please switch to one of the supported chains: ${vault.chains.join(', ')}`,
56
+ );
57
+ }
58
+
59
+ const rpcUrlConfig = getRpcUrlConfigFromChain(chainId, rpcUrl);
60
+ const provider = new ReadProvider({ chainId, rpcUrlConfig });
61
+
62
+ try {
63
+ const lensContract = provider.createContract<typeof vault.lensContract.abi>(
64
+ vault.lensContract.abi,
65
+ vault.lensContract.address,
66
+ );
67
+
68
+ const balanceValue = await lensContract.methods
69
+ .balanceOf(address, vault.vaultContract.address)
70
+ .call();
71
+ const balance = fromSatoshi(String(balanceValue));
72
+
73
+ const exchangeRate = await getShareValue({ chainId, rpcUrl, vaultKey });
74
+
75
+ return {
76
+ balance,
77
+ exchangeRate,
78
+ balanceLbtc: balance.multipliedBy(exchangeRate),
79
+ };
80
+ } catch (error) {
81
+ const errorMessage = getErrorMessage(error);
82
+ throw new Error(errorMessage);
83
+ }
84
+ }
@@ -0,0 +1,4 @@
1
+ export {
2
+ getSharesByAddress,
3
+ type IGetSharesByAddressParameters,
4
+ } from './getSharesByAddress';
@@ -13,3 +13,5 @@ export * from './unstakeLBTC';
13
13
  export * from './getBasculeDepositStatus';
14
14
  export * from './getLBTCTotalSupply';
15
15
  export * from './getStakeAndBakeFee';
16
+ export * from './getShareValue';
17
+ export * from './getSharesByAddress';
@@ -1,3 +1,8 @@
1
+ import {
2
+ Vault,
3
+ VaultNameMap,
4
+ VEDA_VAULT_SPENDER_CONTRACTS,
5
+ } from '../../vaults';
1
6
  import { OChainId, TChainId } from '../../common/types/types';
2
7
 
3
8
  export interface IStakeAndBakeVault {
@@ -18,30 +23,30 @@ export interface IStakeAndBakeVault {
18
23
  export const STAKE_AND_BAKE_VAULTS: Record<number, IStakeAndBakeVault[]> = {
19
24
  [OChainId.holesky]: [
20
25
  {
21
- key: 'veda',
22
- name: 'Veda / Lombard DeFi Vault',
23
- address: '0x4A3cD83CEbb91E0Cd31EdA2Ee0F4AebfcCFCbBb6',
26
+ key: Vault.Veda,
27
+ name: VaultNameMap[Vault.Veda],
28
+ address: VEDA_VAULT_SPENDER_CONTRACTS[OChainId.holesky],
24
29
  },
25
30
  ],
26
31
  [OChainId.ethereum]: [
27
32
  {
28
- key: 'veda',
29
- name: 'Veda / Lombard DeFi Vault',
30
- address: '0xC8bbF6153D7Ba105f1399D992ebd32B0541996ef',
33
+ key: Vault.Veda,
34
+ name: VaultNameMap[Vault.Veda],
35
+ address: VEDA_VAULT_SPENDER_CONTRACTS[OChainId.ethereum],
31
36
  },
32
37
  ],
33
38
  [OChainId.binanceSmartChain]: [
34
39
  {
35
- key: 'veda',
36
- name: 'Veda / Lombard DeFi Vault',
37
- address: '0xC8bbF6153D7Ba105f1399D992ebd32B0541996ef',
40
+ key: Vault.Veda,
41
+ name: VaultNameMap[Vault.Veda],
42
+ address: VEDA_VAULT_SPENDER_CONTRACTS[OChainId.binanceSmartChain],
38
43
  },
39
44
  ],
40
45
  [OChainId.binanceSmartChainTestnet]: [
41
46
  {
42
- key: 'veda',
43
- name: 'Veda / Lombard DeFi Vault',
44
- address: '0x72143309A662bDB4aad5cA65Ab59eD8977D047C5',
47
+ key: Vault.Veda,
48
+ name: VaultNameMap[Vault.Veda],
49
+ address: VEDA_VAULT_SPENDER_CONTRACTS[OChainId.binanceSmartChainTestnet],
45
50
  },
46
51
  ],
47
52
  } as const;