@lombard.finance/sdk 3.1.0 → 3.4.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.
- package/README.md +60 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +73 -62
- package/dist/index2.cjs +62 -52
- package/dist/index2.cjs.map +1 -1
- package/dist/index2.js +8361 -12041
- package/dist/index2.js.map +1 -1
- package/package.json +35 -33
- package/src/api-functions/generateDepositBtcAddress/generateDepositBtcAddress.ts +4 -4
- package/src/api-functions/getDepositBtcAddress/getDepositBtcAddress.stories.tsx +8 -0
- package/src/api-functions/getDepositBtcAddress/getDepositBtcAddress.ts +3 -3
- package/src/api-functions/getDepositsByAddress/getDepositsByAddress.ts +8 -7
- package/src/api-functions/getUnstakesByAddress/getUnstakesByAddress.ts +5 -5
- package/src/api-functions/getUserStakeAndBakeSignature/getUserStakeAndBakeSignature.stories.tsx +8 -0
- package/src/bridge/abi/CCIP_BRIDGE_ADAPTER_ABI.json +704 -0
- package/src/bridge/abi/OFT_BRIDGE_ADAPTER_ABI.json +912 -0
- package/src/bridge/index.ts +11 -0
- package/src/bridge/lib/bridge.stories.tsx +89 -0
- package/src/bridge/lib/bridge.ts +101 -0
- package/src/bridge/lib/ccip-bridge.stories.tsx +90 -0
- package/src/bridge/lib/ccip-bridge.ts +163 -0
- package/src/bridge/lib/config.ts +338 -0
- package/src/bridge/lib/oft-bridge.stories.tsx +89 -0
- package/src/bridge/lib/oft-bridge.ts +211 -0
- package/src/common/api-config.ts +8 -2
- package/src/common/blockchain-identifier.ts +32 -5
- package/src/common/chains.ts +13 -1
- package/src/common/contract-info.ts +8 -0
- package/src/contract-functions/approveLBTC/approveLBTC.stories.tsx +1 -1
- package/src/contract-functions/approveLBTC/approveLBTC.ts +3 -2
- package/src/contract-functions/claimLBTC/claimLBTC.ts +3 -2
- package/src/contract-functions/getBasculeDepositStatus/getBasculeDepositStatus.ts +10 -4
- package/src/contract-functions/getLBTCMintingFee/getLBTCMintingFee.tsx +14 -11
- package/src/contract-functions/getLBTCTotalSupply/getLBTCTotalSupply.ts +13 -9
- package/src/contract-functions/getPermitNonce/getPermitNonce.ts +16 -10
- package/src/contract-functions/getShareValue/getShareValue.stories.tsx +1 -1
- package/src/contract-functions/getShareValue/getShareValue.ts +1 -1
- package/src/contract-functions/getSharesByAddress/getSharesByAddress.stories.tsx +1 -1
- package/src/contract-functions/getSharesByAddress/getSharesByAddress.ts +1 -1
- package/src/contract-functions/getStakeAndBakeFee/getStakeAndBakeFee.stories.tsx +14 -1
- package/src/contract-functions/getStakeAndBakeFee/getStakeAndBakeFee.tsx +5 -1
- package/src/contract-functions/signNetworkFee/signNetworkFee.ts +3 -2
- package/src/contract-functions/signStakeAndBake/signStakeAndBake.stories.tsx +2 -1
- package/src/contract-functions/signStakeAndBake/signStakeAndBake.ts +8 -3
- package/src/contract-functions/unstakeLBTC/unstakeLBTC.ts +3 -2
- package/src/index.ts +26 -28
- package/src/metrics/get-lbtc-stats.stories.tsx +51 -0
- package/src/metrics/get-lbtc-stats.ts +38 -0
- package/src/rewards/lib/claim-reward.stories.tsx +1 -0
- package/src/rewards/lib/claim-reward.ts +5 -0
- package/src/rewards/lib/get-reward-signing-data.stories.tsx +1 -0
- package/src/rewards/lib/get-reward-signing-data.ts +4 -0
- package/src/tokens/abi/LBTC_ABI.json +1760 -1760
- package/src/tokens/abi/LBTC_ABI.ts +1761 -0
- package/src/tokens/lbtc-addresses.ts +1 -0
- package/src/tokens/token-addresses.ts +32 -0
- package/src/tokens/tokens.ts +59 -50
- package/src/utils/numbers.ts +3 -0
- package/src/vaults/index.ts +35 -176
- package/src/vaults/lib/config.ts +196 -0
- package/src/vaults/lib/metrics/get-vault-apy.stories.tsx +57 -0
- package/src/vaults/lib/metrics/get-vault-apy.ts +132 -0
- package/src/vaults/lib/{get-vault-points.stories.tsx → metrics/get-vault-points.stories.tsx} +8 -8
- package/src/vaults/lib/{get-vault-points.ts → metrics/get-vault-points.ts} +1 -1
- package/src/vaults/lib/metrics/get-vault-tvl.stories.tsx +57 -0
- package/src/vaults/lib/metrics/get-vault-tvl.ts +119 -0
- package/src/vaults/lib/{cancel-withdraw.stories.tsx → ops/cancel-withdraw.stories.tsx} +9 -9
- package/src/vaults/lib/{deposit.stories.tsx → ops/deposit.stories.tsx} +9 -9
- package/src/vaults/lib/{deposit.ts → ops/deposit.ts} +10 -10
- package/src/vaults/lib/{get-vault-deposits.stories.tsx → ops/get-vault-deposits.stories.tsx} +9 -9
- package/src/vaults/lib/{get-vault-deposits.ts → ops/get-vault-deposits.ts} +5 -5
- package/src/vaults/lib/{get-vault-withdrawals.stories.tsx → ops/get-vault-withdrawals.stories.tsx} +9 -9
- package/src/vaults/lib/{get-vault-withdrawals.ts → ops/get-vault-withdrawals.ts} +5 -5
- package/src/vaults/lib/{withdraw.stories.tsx → ops/withdraw.stories.tsx} +9 -9
- package/src/vaults/lib/{withdraw.ts → ops/withdraw.ts} +12 -12
- package/src/tokens/lbtc-contract.ts +0 -89
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { DEFAULT_ENV, Env } from '@lombard.finance/sdk-common';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
ChainId,
|
|
4
|
+
SOLANA_DEVNET_CHAIN,
|
|
5
|
+
SOLANA_MAINNET_CHAIN,
|
|
6
|
+
SOLANA_TESTNET_CHAIN,
|
|
7
|
+
SUI_MAINNET_CHAIN,
|
|
8
|
+
SUI_TESTNET_CHAIN,
|
|
9
|
+
SolanaChain,
|
|
10
|
+
SuiChain,
|
|
11
|
+
} from './chains';
|
|
3
12
|
|
|
4
13
|
export const BlockchainIdentifier = {
|
|
5
14
|
eth: 'DESTINATION_BLOCKCHAIN_ETHEREUM',
|
|
@@ -16,13 +25,16 @@ export const BlockchainIdentifier = {
|
|
|
16
25
|
|
|
17
26
|
sonic: 'DESTINATION_BLOCKCHAIN_SONIC',
|
|
18
27
|
sonicOld: 'BLOCKCHAIN_SONIC',
|
|
28
|
+
|
|
29
|
+
solana: 'DESTINATION_BLOCKCHAIN_SOLANA',
|
|
30
|
+
solanaOld: 'BLOCKCHAIN_SOLANA',
|
|
19
31
|
} as const;
|
|
20
32
|
|
|
21
33
|
export type BlockchainIdentifier =
|
|
22
34
|
(typeof BlockchainIdentifier)[keyof typeof BlockchainIdentifier];
|
|
23
35
|
|
|
24
36
|
export function getChainNameById(
|
|
25
|
-
chainId: ChainId | SuiChain,
|
|
37
|
+
chainId: ChainId | SuiChain | SolanaChain,
|
|
26
38
|
): BlockchainIdentifier {
|
|
27
39
|
if (
|
|
28
40
|
chainId === ChainId.ethereum ||
|
|
@@ -47,10 +59,18 @@ export function getChainNameById(
|
|
|
47
59
|
return BlockchainIdentifier.sonic;
|
|
48
60
|
}
|
|
49
61
|
|
|
50
|
-
if (chainId ===
|
|
62
|
+
if (chainId === SUI_TESTNET_CHAIN || chainId === SUI_MAINNET_CHAIN) {
|
|
51
63
|
return BlockchainIdentifier.sui;
|
|
52
64
|
}
|
|
53
65
|
|
|
66
|
+
if (
|
|
67
|
+
chainId === SOLANA_DEVNET_CHAIN ||
|
|
68
|
+
chainId === SOLANA_TESTNET_CHAIN ||
|
|
69
|
+
chainId === SOLANA_MAINNET_CHAIN
|
|
70
|
+
) {
|
|
71
|
+
return BlockchainIdentifier.solana;
|
|
72
|
+
}
|
|
73
|
+
|
|
54
74
|
throw new Error(`Unknown chain ID: ${chainId}`);
|
|
55
75
|
}
|
|
56
76
|
|
|
@@ -66,11 +86,14 @@ export const getBaseNetworkByEnv = (env: Env) =>
|
|
|
66
86
|
env === Env.prod ? ChainId.base : ChainId.baseSepoliaTestnet;
|
|
67
87
|
|
|
68
88
|
export const getSuiNetworkByEnv = (env: Env) =>
|
|
69
|
-
env === Env.prod ?
|
|
89
|
+
env === Env.prod ? SUI_MAINNET_CHAIN : SUI_TESTNET_CHAIN;
|
|
70
90
|
|
|
71
91
|
export const getSonicNetworkByEnv = (env: Env) =>
|
|
72
92
|
env === Env.prod ? ChainId.sonic : ChainId.sonicBlazeTestnet;
|
|
73
93
|
|
|
94
|
+
export const getSolanaNetworkByEnv = (env: Env) =>
|
|
95
|
+
env === Env.prod ? SOLANA_MAINNET_CHAIN : SOLANA_DEVNET_CHAIN;
|
|
96
|
+
|
|
74
97
|
/**
|
|
75
98
|
* @param chain the chain ID
|
|
76
99
|
* @param env
|
|
@@ -79,7 +102,7 @@ export const getSonicNetworkByEnv = (env: Env) =>
|
|
|
79
102
|
export function getChainIdByName(
|
|
80
103
|
chain: string,
|
|
81
104
|
env: Env = DEFAULT_ENV,
|
|
82
|
-
): ChainId | SuiChain {
|
|
105
|
+
): ChainId | SuiChain | SolanaChain {
|
|
83
106
|
switch (chain as BlockchainIdentifier) {
|
|
84
107
|
case BlockchainIdentifier.eth:
|
|
85
108
|
case BlockchainIdentifier.ethOld:
|
|
@@ -101,6 +124,10 @@ export function getChainIdByName(
|
|
|
101
124
|
case BlockchainIdentifier.sonicOld:
|
|
102
125
|
return getSonicNetworkByEnv(env);
|
|
103
126
|
|
|
127
|
+
case BlockchainIdentifier.solana:
|
|
128
|
+
case BlockchainIdentifier.solanaOld:
|
|
129
|
+
return getSolanaNetworkByEnv(env);
|
|
130
|
+
|
|
104
131
|
default:
|
|
105
132
|
return ChainId.ethereum;
|
|
106
133
|
}
|
package/src/common/chains.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
bsc,
|
|
7
7
|
bscTestnet,
|
|
8
8
|
corn,
|
|
9
|
+
etherlink,
|
|
9
10
|
holesky,
|
|
10
11
|
mainnet,
|
|
11
12
|
morph,
|
|
@@ -27,13 +28,22 @@ export type SuiChain =
|
|
|
27
28
|
| typeof SUI_LOCALNET_CHAIN
|
|
28
29
|
| typeof SUI_MAINNET_CHAIN;
|
|
29
30
|
|
|
31
|
+
export const SOLANA_MAINNET_CHAIN = 'solana:mainnet-beta' as const;
|
|
32
|
+
export const SOLANA_TESTNET_CHAIN = 'solana:testnet' as const;
|
|
33
|
+
export const SOLANA_DEVNET_CHAIN = 'solana:devnet' as const;
|
|
34
|
+
|
|
35
|
+
export type SolanaChain =
|
|
36
|
+
| typeof SOLANA_MAINNET_CHAIN
|
|
37
|
+
| typeof SOLANA_TESTNET_CHAIN
|
|
38
|
+
| typeof SOLANA_DEVNET_CHAIN;
|
|
39
|
+
|
|
30
40
|
export const ChainId = {
|
|
31
41
|
ethereum: 1,
|
|
32
42
|
base: 8453,
|
|
33
43
|
berachain: 80094,
|
|
34
44
|
binanceSmartChain: 56,
|
|
35
45
|
corn: 21000000,
|
|
36
|
-
|
|
46
|
+
etherlink: 42793,
|
|
37
47
|
morph: 2818,
|
|
38
48
|
sonic: 146,
|
|
39
49
|
swell: 1923,
|
|
@@ -41,6 +51,7 @@ export const ChainId = {
|
|
|
41
51
|
baseSepoliaTestnet: 84532,
|
|
42
52
|
berachainBartioTestnet: 80084,
|
|
43
53
|
binanceSmartChainTestnet: 97,
|
|
54
|
+
holesky: 17000,
|
|
44
55
|
morphHolesky: 2810,
|
|
45
56
|
sepolia: 11155111,
|
|
46
57
|
sonicBlazeTestnet: 57054,
|
|
@@ -54,6 +65,7 @@ export const CHAIN_ID_TO_VIEM_CHAIN_MAP = {
|
|
|
54
65
|
[ChainId.berachain]: berachain,
|
|
55
66
|
[ChainId.binanceSmartChain]: bsc,
|
|
56
67
|
[ChainId.corn]: corn,
|
|
68
|
+
[ChainId.etherlink]: etherlink,
|
|
57
69
|
[ChainId.morph]: morph,
|
|
58
70
|
[ChainId.sonic]: sonic,
|
|
59
71
|
[ChainId.swell]: swellchain,
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from '../../stories/hooks/useConnection';
|
|
8
8
|
import useQuery from '../../stories/hooks/useQuery';
|
|
9
9
|
import { approveLBTC, IApproveLBTCParams } from './approveLBTC';
|
|
10
|
-
import { Vault, VAULTS } from '../../vaults';
|
|
10
|
+
import { Vault, VAULTS } from '../../vaults/lib/config';
|
|
11
11
|
import { ChainId } from '../../common/chains';
|
|
12
12
|
import { Env } from '@lombard.finance/sdk-common';
|
|
13
13
|
import {
|
|
@@ -2,10 +2,11 @@ import { CHAIN_ID_TO_VIEM_CHAIN_MAP } from '../../common/chains';
|
|
|
2
2
|
import { makeWalletClient } from '../../clients/wallet-client';
|
|
3
3
|
import { CommonWriteParameters } from '../../common/parameters';
|
|
4
4
|
import { toSatoshi } from '../../utils/satoshi';
|
|
5
|
-
import { getLBTCContractInfo } from '../../tokens/lbtc-contract';
|
|
6
5
|
import { Address, Hash } from 'viem';
|
|
7
6
|
import { makePublicClient } from '../../clients/public-client';
|
|
8
7
|
import BigNumber from 'bignumber.js';
|
|
8
|
+
import { getTokenContractInfo } from '../../tokens/tokens';
|
|
9
|
+
import { Token } from '../../tokens/token-addresses';
|
|
9
10
|
|
|
10
11
|
export interface IApproveLBTCParams extends CommonWriteParameters {
|
|
11
12
|
/**
|
|
@@ -45,7 +46,7 @@ export async function approveLBTC({
|
|
|
45
46
|
const publicClient = makePublicClient({ chainId, rpcUrl });
|
|
46
47
|
const walletClient = makeWalletClient({ chainId, provider });
|
|
47
48
|
|
|
48
|
-
const lbtcContract =
|
|
49
|
+
const lbtcContract = getTokenContractInfo(Token.LBTC, chainId, env);
|
|
49
50
|
|
|
50
51
|
const amountSat = toSatoshi(amount).toNumber();
|
|
51
52
|
|
|
@@ -3,12 +3,13 @@ import {
|
|
|
3
3
|
getBasculeDepositStatus,
|
|
4
4
|
} from '../getBasculeDepositStatus';
|
|
5
5
|
import { CommonWriteParameters } from '../../common/parameters';
|
|
6
|
-
import { getLBTCContractInfo } from '../../tokens/lbtc-contract';
|
|
7
6
|
import { CHAIN_ID_TO_VIEM_CHAIN_MAP } from '../../common/chains';
|
|
8
7
|
import { makePublicClient } from '../../clients/public-client';
|
|
9
8
|
import { makeWalletClient } from '../../clients/wallet-client';
|
|
10
9
|
import { ensureHex } from '../../utils/hex';
|
|
11
10
|
import { Hash } from 'viem';
|
|
11
|
+
import { getTokenContractInfo } from '../../tokens/tokens';
|
|
12
|
+
import { Token } from '../../tokens/token-addresses';
|
|
12
13
|
|
|
13
14
|
export interface IClaimLBTCParams extends CommonWriteParameters {
|
|
14
15
|
/**
|
|
@@ -44,7 +45,7 @@ export async function claimLBTC({
|
|
|
44
45
|
rpcUrl,
|
|
45
46
|
env,
|
|
46
47
|
}: IClaimLBTCParams): Promise<Hash> {
|
|
47
|
-
const lbtcContract =
|
|
48
|
+
const lbtcContract = getTokenContractInfo(Token.LBTC, chainId, env);
|
|
48
49
|
|
|
49
50
|
// Check the deposit status against Bascule Drawbridge security.
|
|
50
51
|
// Block any deposit that is not reported.
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { CommonOptionalWriteParameters } from '../../common/parameters';
|
|
2
2
|
import { getErrorMessage } from '../../utils/err';
|
|
3
|
-
import { getLBTCContract } from '../../tokens/lbtc-contract';
|
|
4
3
|
import { DEFAULT_ENV } from '@lombard.finance/sdk-common';
|
|
5
4
|
import { IDeposit } from '../../api-functions/getDepositsByAddress/getDepositsByAddress';
|
|
6
5
|
import {
|
|
7
|
-
Address,
|
|
8
6
|
ByteArray,
|
|
9
7
|
Client,
|
|
10
8
|
getContract,
|
|
@@ -15,6 +13,8 @@ import {
|
|
|
15
13
|
import { makePublicClient } from '../../clients/public-client';
|
|
16
14
|
import { makeWalletClient } from '../../clients/wallet-client';
|
|
17
15
|
import LBTC_BASCULE_ABI from '../../tokens/abi/LBTC_BASCULE_ABI.json';
|
|
16
|
+
import { getTokenContractInfo } from '../../tokens/tokens';
|
|
17
|
+
import { Token } from '../../tokens/token-addresses';
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* The bascule drawbridge deposit status.
|
|
@@ -78,8 +78,14 @@ export async function getBasculeDepositStatus({
|
|
|
78
78
|
);
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
const
|
|
82
|
-
const
|
|
81
|
+
const publicClient = makePublicClient({ chainId, rpcUrl });
|
|
82
|
+
const lbtcContract = getTokenContractInfo(Token.LBTC, chainId, env);
|
|
83
|
+
|
|
84
|
+
const basculeContractAddress = await publicClient.readContract({
|
|
85
|
+
abi: lbtcContract.abi,
|
|
86
|
+
address: lbtcContract.address,
|
|
87
|
+
functionName: 'Bascule',
|
|
88
|
+
});
|
|
83
89
|
|
|
84
90
|
// If there's no bascule contract address on the LBTC contract then return
|
|
85
91
|
// the the deposit is ok (REPORTED).
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
2
|
import { CommonParameters } from '../../common/parameters';
|
|
3
|
-
import { getLBTCContract } from '../../tokens/lbtc-contract';
|
|
4
3
|
import { determineEnv } from '../../utils/env';
|
|
5
|
-
import { getErrorMessage } from '../../utils/err';
|
|
6
4
|
import { fromSatoshi } from '../../utils/satoshi';
|
|
5
|
+
import { makePublicClient } from '../../clients/public-client';
|
|
6
|
+
import { getTokenContractInfo } from '../../tokens/tokens';
|
|
7
|
+
import { Token } from '../../tokens/token-addresses';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Gets LBTC minting fee amount.
|
|
@@ -20,15 +21,17 @@ export async function getLBTCMintingFee({
|
|
|
20
21
|
rpcUrl,
|
|
21
22
|
env,
|
|
22
23
|
}: CommonParameters): Promise<BigNumber> {
|
|
23
|
-
|
|
24
|
-
const environment = env || determineEnv(chainId);
|
|
24
|
+
const environment = env || determineEnv(chainId);
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
const publicClient = makePublicClient({ chainId, rpcUrl });
|
|
27
|
+
const lbtcContract = getTokenContractInfo(Token.LBTC, chainId, environment);
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
const rawFeeValue = await publicClient.readContract({
|
|
30
|
+
abi: lbtcContract.abi,
|
|
31
|
+
address: lbtcContract.address,
|
|
32
|
+
functionName: 'getMintFee',
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const lbtcMintFee = fromSatoshi(String(rawFeeValue));
|
|
36
|
+
return lbtcMintFee;
|
|
34
37
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { CommonParameters } from '../../common/parameters';
|
|
2
2
|
import { DEFAULT_ENV } from '@lombard.finance/sdk-common';
|
|
3
|
-
import { getLBTCContract } from '../../tokens/lbtc-contract';
|
|
4
|
-
import { getErrorMessage } from '../../utils/err';
|
|
5
3
|
import BigNumber from 'bignumber.js';
|
|
6
4
|
import { fromSatoshi } from '../../utils/satoshi';
|
|
5
|
+
import { makePublicClient } from '../../clients/public-client';
|
|
6
|
+
import { getTokenContractInfo } from '../../tokens/tokens';
|
|
7
|
+
import { Token } from '../../tokens/token-addresses';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Get the total supply of LBTC tokens.
|
|
@@ -20,11 +21,14 @@ export async function getLBTCTotalSupply({
|
|
|
20
21
|
rpcUrl,
|
|
21
22
|
env = DEFAULT_ENV,
|
|
22
23
|
}: CommonParameters): Promise<BigNumber> {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
const publicClient = makePublicClient({ chainId, rpcUrl });
|
|
25
|
+
const lbtcContract = getTokenContractInfo(Token.LBTC, chainId, env);
|
|
26
|
+
|
|
27
|
+
const totalSupplyRaw = await publicClient.readContract({
|
|
28
|
+
abi: lbtcContract.abi,
|
|
29
|
+
address: lbtcContract.address,
|
|
30
|
+
functionName: 'totalSupply',
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return fromSatoshi(String(totalSupplyRaw));
|
|
30
34
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { CommonParameters } from '../../common/parameters';
|
|
2
|
-
import { getErrorMessage } from '../../utils/err';
|
|
3
2
|
import { determineEnv } from '../../utils/env';
|
|
4
3
|
import { DEFAULT_ENV } from '@lombard.finance/sdk-common';
|
|
5
|
-
import { getLBTCContract } from '../../tokens/lbtc-contract';
|
|
6
4
|
import { Address } from 'viem';
|
|
5
|
+
import { makePublicClient } from '../../clients/public-client';
|
|
6
|
+
import { getTokenContractInfo } from '../../tokens/tokens';
|
|
7
|
+
import { Token } from '../../tokens/token-addresses';
|
|
7
8
|
|
|
8
9
|
export interface IGetPermitNonceParams extends CommonParameters {
|
|
9
10
|
/**
|
|
@@ -28,12 +29,17 @@ export async function getPermitNonce({
|
|
|
28
29
|
rpcUrl,
|
|
29
30
|
env = DEFAULT_ENV,
|
|
30
31
|
}: IGetPermitNonceParams): Promise<string> {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
const environment = env || determineEnv(chainId);
|
|
33
|
+
|
|
34
|
+
const publicClient = makePublicClient({ chainId, rpcUrl });
|
|
35
|
+
const lbtcContract = getTokenContractInfo(Token.LBTC, chainId, environment);
|
|
36
|
+
|
|
37
|
+
const nonce = await publicClient.readContract({
|
|
38
|
+
abi: lbtcContract.abi,
|
|
39
|
+
address: lbtcContract.address,
|
|
40
|
+
functionName: 'nonces',
|
|
41
|
+
args: [owner],
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
return String(nonce);
|
|
39
45
|
}
|
|
@@ -4,7 +4,7 @@ import { ChainId } from '../../common/chains';
|
|
|
4
4
|
import { Button } from '../../stories/components/Button';
|
|
5
5
|
import useQuery from '../../stories/hooks/useQuery';
|
|
6
6
|
import { getShareValue, IGetShareValueParameters } from './getShareValue';
|
|
7
|
-
import { Vault } from '../../vaults';
|
|
7
|
+
import { Vault } from '../../vaults/lib/config';
|
|
8
8
|
import { functionType } from '../../stories/components/decorators';
|
|
9
9
|
|
|
10
10
|
const meta = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
2
|
import { getErrorMessage } from '../../utils/err';
|
|
3
|
-
import { isVedaVaultChain, Vault, VAULTS } from '../../vaults';
|
|
3
|
+
import { isVedaVaultChain, Vault, VAULTS } from '../../vaults/lib/config';
|
|
4
4
|
import { fromSatoshi } from '../../utils/satoshi';
|
|
5
5
|
import { makePublicClient } from '../../clients/public-client';
|
|
6
6
|
import { getContract } from 'viem';
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
getSharesByAddress,
|
|
8
8
|
IGetSharesByAddressParameters,
|
|
9
9
|
} from './getSharesByAddress';
|
|
10
|
-
import { Vault } from '../../vaults';
|
|
10
|
+
import { Vault } from '../../vaults/lib/config';
|
|
11
11
|
import { EXAMPLE_EVM_ADDRESS } from '../../stories/constants';
|
|
12
12
|
import { CodeBlock } from '../../stories/components/CodeBlock';
|
|
13
13
|
import { functionType } from '../../stories/components/decorators';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
2
|
import { getErrorMessage } from '../../utils/err';
|
|
3
|
-
import { isVedaVaultChain, Vault, VAULTS } from '../../vaults';
|
|
3
|
+
import { isVedaVaultChain, Vault, VAULTS } from '../../vaults/lib/config';
|
|
4
4
|
import { fromSatoshi } from '../../utils/satoshi';
|
|
5
5
|
import { getShareValue } from '../getShareValue';
|
|
6
6
|
import { makePublicClient } from '../../clients/public-client';
|
|
@@ -8,7 +8,10 @@ import {
|
|
|
8
8
|
getStakeAndBakeFee,
|
|
9
9
|
IGetStakeAndBakeFeeParams,
|
|
10
10
|
} from './getStakeAndBakeFee';
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
Vault,
|
|
13
|
+
VEDA_VAULT_STAKE_AND_BAKE_CHAINS,
|
|
14
|
+
} from '../../vaults/lib/config';
|
|
12
15
|
import { functionType } from '../../stories/components/decorators';
|
|
13
16
|
|
|
14
17
|
const meta = {
|
|
@@ -27,6 +30,16 @@ export const WithParams: Story = {
|
|
|
27
30
|
vaultKey: Vault.Veda,
|
|
28
31
|
chainId: ChainId.ethereum,
|
|
29
32
|
},
|
|
33
|
+
argTypes: {
|
|
34
|
+
chainId: {
|
|
35
|
+
mapping: ChainId,
|
|
36
|
+
options: VEDA_VAULT_STAKE_AND_BAKE_CHAINS.map(
|
|
37
|
+
ch => Object.entries(ChainId).find(([_, v]) => v === ch)?.[0],
|
|
38
|
+
),
|
|
39
|
+
description: 'The chain',
|
|
40
|
+
control: { type: 'select' },
|
|
41
|
+
},
|
|
42
|
+
},
|
|
30
43
|
};
|
|
31
44
|
|
|
32
45
|
type GetStakeAndBakeFeeProps = IGetStakeAndBakeFeeParams;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { getErrorMessage } from '../../utils/err';
|
|
2
2
|
import { CommonParameters } from '../../common/parameters';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
isVedaVaultStakeAndBakeChain,
|
|
5
|
+
Vault,
|
|
6
|
+
VAULTS,
|
|
7
|
+
} from '../../vaults/lib/config';
|
|
4
8
|
import { makePublicClient } from '../../clients/public-client';
|
|
5
9
|
import { getContract } from 'viem';
|
|
6
10
|
import { fromSatoshi } from '../../utils/satoshi';
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
2
|
import { makeWalletClient } from '../../clients/wallet-client';
|
|
3
3
|
import { CommonWriteParameters } from '../../common/parameters';
|
|
4
|
-
import { getLBTCContractInfo } from '../../tokens/lbtc-contract';
|
|
5
4
|
import { DAY, now, toUnix } from '../../utils/time';
|
|
6
5
|
import { Hex } from 'viem';
|
|
6
|
+
import { getTokenContractInfo } from '../../tokens/tokens';
|
|
7
|
+
import { Token } from '../../tokens/token-addresses';
|
|
7
8
|
|
|
8
9
|
export interface ISignNetworkFeeParams extends CommonWriteParameters {
|
|
9
10
|
/**
|
|
@@ -51,7 +52,7 @@ export async function signNetworkFee({
|
|
|
51
52
|
provider,
|
|
52
53
|
env,
|
|
53
54
|
}: ISignNetworkFeeParams): Promise<ISignNetworkFeeResponse> {
|
|
54
|
-
const lbtcContract =
|
|
55
|
+
const lbtcContract = getTokenContractInfo(Token.LBTC, chainId, env);
|
|
55
56
|
const walletClient = makeWalletClient({
|
|
56
57
|
chainId,
|
|
57
58
|
provider,
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
functionType,
|
|
13
13
|
wagmiDecorator,
|
|
14
14
|
} from '../../stories/components/decorators';
|
|
15
|
+
import { DAY, now, toUnix } from '../../utils/time';
|
|
15
16
|
|
|
16
17
|
const { name } = signStakeAndBake;
|
|
17
18
|
|
|
@@ -29,7 +30,7 @@ type Story = StoryObj<typeof meta>;
|
|
|
29
30
|
export const WithParams: Story = {
|
|
30
31
|
args: {
|
|
31
32
|
value: '20000',
|
|
32
|
-
expiry:
|
|
33
|
+
expiry: toUnix(now() + DAY),
|
|
33
34
|
},
|
|
34
35
|
};
|
|
35
36
|
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { makeWalletClient } from '../../clients/wallet-client';
|
|
2
2
|
import { CommonWriteParameters } from '../../common/parameters';
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import {
|
|
4
|
+
isVedaVaultStakeAndBakeChain,
|
|
5
|
+
Vault,
|
|
6
|
+
VAULTS,
|
|
7
|
+
} from '../../vaults/lib/config';
|
|
5
8
|
import { getPermitNonce } from '../getPermitNonce/getPermitNonce';
|
|
6
9
|
import BigNumber from 'bignumber.js';
|
|
7
10
|
import { DAY, now, toUnix } from '../../utils/time';
|
|
11
|
+
import { getTokenContractInfo } from '../../tokens/tokens';
|
|
12
|
+
import { Token } from '../../tokens/token-addresses';
|
|
8
13
|
|
|
9
14
|
export interface ISignStakeAndBakeParams extends CommonWriteParameters {
|
|
10
15
|
/**
|
|
@@ -74,7 +79,7 @@ export async function signStakeAndBake({
|
|
|
74
79
|
);
|
|
75
80
|
}
|
|
76
81
|
|
|
77
|
-
const lbtcContract =
|
|
82
|
+
const lbtcContract = getTokenContractInfo(Token.LBTC, chainId, env);
|
|
78
83
|
const walletClient = makeWalletClient({ chainId, provider });
|
|
79
84
|
const spenderContract = vault.spenderContracts[chainId];
|
|
80
85
|
|
|
@@ -3,10 +3,11 @@ import { CommonWriteParameters } from '../../common/parameters';
|
|
|
3
3
|
import { toSatoshi } from '../../utils/satoshi';
|
|
4
4
|
import { makeWalletClient } from '../../clients/wallet-client';
|
|
5
5
|
import { makePublicClient } from '../../clients/public-client';
|
|
6
|
-
import { getLBTCContractInfo } from '../../tokens/lbtc-contract';
|
|
7
6
|
import { CHAIN_ID_TO_VIEM_CHAIN_MAP } from '../../common/chains';
|
|
8
7
|
import { Hex } from 'viem';
|
|
9
8
|
import BigNumber from 'bignumber.js';
|
|
9
|
+
import { getTokenContractInfo } from '../../tokens/tokens';
|
|
10
|
+
import { Token } from '../../tokens/token-addresses';
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* The unstake parameters.
|
|
@@ -45,7 +46,7 @@ export async function unstakeLBTC({
|
|
|
45
46
|
const outputScript = getOutputScript(btcAddress, env);
|
|
46
47
|
const amountSat = toSatoshi(amount).toNumber();
|
|
47
48
|
|
|
48
|
-
const lbtcContract =
|
|
49
|
+
const lbtcContract = getTokenContractInfo(Token.LBTC, chainId, env);
|
|
49
50
|
|
|
50
51
|
const publicClient = makePublicClient({ chainId, rpcUrl });
|
|
51
52
|
const walletClient = makeWalletClient({ provider, chainId });
|
package/src/index.ts
CHANGED
|
@@ -5,33 +5,7 @@ export * from './api-functions';
|
|
|
5
5
|
export * from './contract-functions';
|
|
6
6
|
|
|
7
7
|
// Vault:
|
|
8
|
-
export
|
|
9
|
-
export {
|
|
10
|
-
deposit,
|
|
11
|
-
type DepositParameters,
|
|
12
|
-
} from './vaults/lib/deposit';
|
|
13
|
-
|
|
14
|
-
export {
|
|
15
|
-
queueWithdraw,
|
|
16
|
-
type QueueWithdrawParameters,
|
|
17
|
-
cancelWithdraw,
|
|
18
|
-
type CancelWithdrawParameters,
|
|
19
|
-
} from './vaults/lib/withdraw';
|
|
20
|
-
|
|
21
|
-
export {
|
|
22
|
-
getVaultDeposits,
|
|
23
|
-
type GetVaultDepositsParameters,
|
|
24
|
-
} from './vaults/lib/get-vault-deposits';
|
|
25
|
-
|
|
26
|
-
export {
|
|
27
|
-
getVaultWithdrawals,
|
|
28
|
-
type GetVaultWithdrawalsParameters,
|
|
29
|
-
} from './vaults/lib/get-vault-withdrawals';
|
|
30
|
-
|
|
31
|
-
export {
|
|
32
|
-
getVaultPoints,
|
|
33
|
-
type GetVaultPointsParameters,
|
|
34
|
-
} from './vaults/lib/get-vault-points';
|
|
8
|
+
export * from './vaults';
|
|
35
9
|
|
|
36
10
|
// Rewards:
|
|
37
11
|
export * from './rewards';
|
|
@@ -40,9 +14,33 @@ export * from './rewards';
|
|
|
40
14
|
export * from './common/api-config';
|
|
41
15
|
export * from './common/blockchain-identifier';
|
|
42
16
|
export * from './common/chains';
|
|
43
|
-
export
|
|
17
|
+
export {
|
|
18
|
+
SOLANA_DEVNET_CHAIN,
|
|
19
|
+
SOLANA_MAINNET_CHAIN,
|
|
20
|
+
SOLANA_TESTNET_CHAIN,
|
|
21
|
+
} from './common/chains';
|
|
22
|
+
export {
|
|
23
|
+
SUI_DEVNET_CHAIN,
|
|
24
|
+
SUI_MAINNET_CHAIN,
|
|
25
|
+
SUI_TESTNET_CHAIN,
|
|
26
|
+
} from './common/chains';
|
|
44
27
|
export * from './tokens/lbtc-addresses';
|
|
28
|
+
export * from './utils/satoshi';
|
|
29
|
+
|
|
30
|
+
// Metrics:
|
|
31
|
+
export { getLBTCStats } from './metrics/get-lbtc-stats';
|
|
45
32
|
|
|
46
33
|
// Re-exports:
|
|
47
34
|
export type { Address, EIP1193Provider } from 'viem';
|
|
48
35
|
export { Env } from '@lombard.finance/sdk-common';
|
|
36
|
+
|
|
37
|
+
// Bridge:
|
|
38
|
+
export {
|
|
39
|
+
getBridgeInfo,
|
|
40
|
+
bridge,
|
|
41
|
+
bridgeCCIP,
|
|
42
|
+
bridgeOFT,
|
|
43
|
+
type BridgeParameters,
|
|
44
|
+
type BridgeCCIPParameters,
|
|
45
|
+
type BridgeOFTParameters,
|
|
46
|
+
} from './bridge';
|
|
@@ -0,0 +1,51 @@
|
|
|
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 { functionType, wagmiDecorator } from '../stories/components/decorators';
|
|
6
|
+
import { ErrorBlock } from '../stories/components/error-block';
|
|
7
|
+
import { getLBTCStats } from './get-lbtc-stats';
|
|
8
|
+
|
|
9
|
+
const meta = {
|
|
10
|
+
title: 'metrics/getLBTCStats',
|
|
11
|
+
component: StoryView,
|
|
12
|
+
tags: ['autodocs'],
|
|
13
|
+
decorators: [wagmiDecorator, functionType('api-get')],
|
|
14
|
+
} satisfies Meta<typeof StoryView>;
|
|
15
|
+
|
|
16
|
+
export default meta;
|
|
17
|
+
|
|
18
|
+
type Story = StoryObj<typeof meta>;
|
|
19
|
+
|
|
20
|
+
export const WithParams: Story = {
|
|
21
|
+
args: {},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
type SignNetworkFeeProps = Parameters<typeof getLBTCStats>[0];
|
|
25
|
+
|
|
26
|
+
export function StoryView(props: SignNetworkFeeProps) {
|
|
27
|
+
const request = async () => {
|
|
28
|
+
return getLBTCStats({
|
|
29
|
+
...props,
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const { data, error, isLoading, refetch } = useQuery(request, [], false);
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<>
|
|
37
|
+
<p>This function returns the total supply of the LBTC.</p>
|
|
38
|
+
|
|
39
|
+
<Button
|
|
40
|
+
onClick={refetch}
|
|
41
|
+
disabled={isLoading}
|
|
42
|
+
isLoading={isLoading}
|
|
43
|
+
actionName={getLBTCStats.name}
|
|
44
|
+
/>
|
|
45
|
+
|
|
46
|
+
<ErrorBlock>{error}</ErrorBlock>
|
|
47
|
+
|
|
48
|
+
<CodeBlock text={data} />
|
|
49
|
+
</>
|
|
50
|
+
);
|
|
51
|
+
}
|