@lombard.finance/sdk 3.4.0 → 3.5.6
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 +1 -0
- package/dist/ccip.cjs +0 -1
- package/dist/ccip.js +0 -1
- package/dist/index.cjs +1 -2
- package/dist/index.js +84 -73
- package/dist/index2.cjs +54 -55
- package/dist/index2.js +7959 -6547
- package/package.json +1 -1
- package/src/api-functions/generateDepositBtcAddress/generateDepositBtcAddress.stories.tsx +7 -0
- package/src/api-functions/generateDepositBtcAddress/generateDepositBtcAddress.ts +78 -2
- package/src/api-functions/getDepositBtcAddress/getDepositBtcAddress.stories.tsx +7 -8
- package/src/api-functions/getDepositBtcAddress/getDepositBtcAddress.ts +66 -3
- package/src/api-functions/getDepositBtcAddress/getDepositBtcAddresses.stories.tsx +4 -0
- package/src/api-functions/getDepositsByAddress/getDepositsByAddress.ts +4 -2
- package/src/api-functions/getNetworkFeeSignature/getNetworkFeeSignature.stories.tsx +2 -0
- package/src/api-functions/getUnstakesByAddress/getUnstakesByAddress.ts +35 -6
- package/src/api-functions/getUnstakesByAddress/index.ts +1 -1
- package/src/bridge/lib/config.ts +119 -104
- package/src/clients/public-client.ts +9 -1
- package/src/clients/rpc-url-config.ts +27 -0
- package/src/common/api-config.ts +2 -2
- package/src/common/blockchain-identifier.ts +11 -0
- package/src/common/chains.stories.tsx +67 -0
- package/src/common/chains.ts +83 -0
- package/src/contract-functions/approveLBTC/approveLBTC.stories.tsx +2 -0
- package/src/contract-functions/claimLBTC/claimLBTC.stories.tsx +13 -4
- package/src/contract-functions/claimLBTC/claimLBTC.ts +50 -10
- package/src/contract-functions/getBasculeDepositStatus/getBasculeDepositStatus.ts +6 -4
- package/src/contract-functions/getLBTCMintingFee/getLBTCMintingFee.stories.tsx +7 -10
- package/src/contract-functions/getLBTCMintingFee/getLBTCMintingFee.tsx +45 -6
- package/src/contract-functions/getLBTCTotalSupply/getLBTCTotalSupply.stories.tsx +3 -1
- package/src/contract-functions/getLBTCTotalSupply/getLBTCTotalSupply.ts +5 -4
- package/src/contract-functions/signNetworkFee/signNetworkFee.stories.tsx +2 -0
- package/src/contract-functions/unstakeLBTC/unstakeLBTC.stories.tsx +15 -4
- package/src/contract-functions/unstakeLBTC/unstakeLBTC.ts +53 -11
- package/src/index.ts +1 -0
- package/src/stories/arg-types.ts +34 -0
- package/src/stories/components/decorators/wagmi-decorator.tsx +5 -0
- package/src/tokens/abi/BTCK_ABI.ts +1092 -0
- package/src/tokens/lbtc-addresses.ts +7 -0
- package/src/tokens/token-addresses.ts +97 -10
- package/src/tokens/tokens.ts +29 -18
- package/src/utils/env.ts +7 -0
- package/src/utils/err.ts +14 -0
- package/src/utils/gas.ts +36 -0
- package/src/vaults/lib/metrics/get-vault-tvl.ts +1 -0
- package/dist/ccip.cjs.map +0 -1
- package/dist/ccip.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index2.cjs.map +0 -1
- package/dist/index2.js.map +0 -1
|
@@ -3,13 +3,15 @@ import {
|
|
|
3
3
|
getBasculeDepositStatus,
|
|
4
4
|
} from '../getBasculeDepositStatus';
|
|
5
5
|
import { CommonWriteParameters } from '../../common/parameters';
|
|
6
|
-
import { CHAIN_ID_TO_VIEM_CHAIN_MAP } from '../../common/chains';
|
|
6
|
+
import { CHAIN_ID_TO_VIEM_CHAIN_MAP, isKatanaChain } from '../../common/chains';
|
|
7
7
|
import { makePublicClient } from '../../clients/public-client';
|
|
8
8
|
import { makeWalletClient } from '../../clients/wallet-client';
|
|
9
9
|
import { ensureHex } from '../../utils/hex';
|
|
10
|
-
import { Hash } from 'viem';
|
|
10
|
+
import { Hash, parseGwei } from 'viem';
|
|
11
11
|
import { getTokenContractInfo } from '../../tokens/tokens';
|
|
12
12
|
import { Token } from '../../tokens/token-addresses';
|
|
13
|
+
import BigNumber from 'bignumber.js';
|
|
14
|
+
import { estimateGasFees } from '../../utils/gas';
|
|
13
15
|
|
|
14
16
|
export interface IClaimLBTCParams extends CommonWriteParameters {
|
|
15
17
|
/**
|
|
@@ -45,14 +47,42 @@ export async function claimLBTC({
|
|
|
45
47
|
rpcUrl,
|
|
46
48
|
env,
|
|
47
49
|
}: IClaimLBTCParams): Promise<Hash> {
|
|
48
|
-
|
|
50
|
+
return mintToken({
|
|
51
|
+
data,
|
|
52
|
+
proofSignature,
|
|
53
|
+
account,
|
|
54
|
+
chainId,
|
|
55
|
+
provider,
|
|
56
|
+
rpcUrl,
|
|
57
|
+
env,
|
|
58
|
+
token: Token.LBTC,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export async function mintToken({
|
|
63
|
+
data,
|
|
64
|
+
proofSignature,
|
|
65
|
+
account,
|
|
66
|
+
chainId,
|
|
67
|
+
provider,
|
|
68
|
+
rpcUrl,
|
|
69
|
+
env,
|
|
70
|
+
token = Token.LBTC,
|
|
71
|
+
}: IClaimLBTCParams & { token?: Token.LBTC | Token.BTCK }) {
|
|
72
|
+
if (![Token.LBTC, Token.BTCK].includes(token)) {
|
|
73
|
+
throw new Error('Unsupported token');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (token === Token.BTCK && !isKatanaChain(chainId)) {
|
|
77
|
+
throw new Error('Operation not permitted');
|
|
78
|
+
}
|
|
49
79
|
|
|
50
|
-
|
|
51
|
-
// Block any deposit that is not reported.
|
|
80
|
+
const tokenContract = getTokenContractInfo(token, chainId, env);
|
|
52
81
|
const basculeStatus = await getBasculeDepositStatus({
|
|
53
82
|
chainId,
|
|
54
83
|
rawPayload: data,
|
|
55
84
|
env,
|
|
85
|
+
token,
|
|
56
86
|
});
|
|
57
87
|
|
|
58
88
|
if (basculeStatus !== BasculeDepositStatus.REPORTED) {
|
|
@@ -72,16 +102,26 @@ export async function claimLBTC({
|
|
|
72
102
|
}
|
|
73
103
|
}
|
|
74
104
|
|
|
75
|
-
const publicClient = makePublicClient({ chainId, rpcUrl });
|
|
105
|
+
const publicClient = makePublicClient({ chainId, rpcUrl, env });
|
|
76
106
|
const walletClient = makeWalletClient({ chainId, provider });
|
|
77
107
|
|
|
78
|
-
const
|
|
79
|
-
address:
|
|
108
|
+
const callData = {
|
|
109
|
+
address: tokenContract.address,
|
|
80
110
|
account,
|
|
81
111
|
chain: CHAIN_ID_TO_VIEM_CHAIN_MAP[chainId],
|
|
82
|
-
abi:
|
|
83
|
-
functionName: 'mint',
|
|
112
|
+
abi: tokenContract.abi,
|
|
113
|
+
functionName: token === Token.BTCK ? 'mintV1' : 'mint', // FIXME: mintV1 is the equivalent on Native LBTC contract of mint on LBTC contract, change if contract ABI changes.
|
|
84
114
|
args: [ensureHex(data), ensureHex(proofSignature)],
|
|
115
|
+
} as const;
|
|
116
|
+
|
|
117
|
+
// Katana Tatara requires tip TODO: Recheck this part
|
|
118
|
+
const gasEstimationData = isKatanaChain(chainId)
|
|
119
|
+
? await estimateGasFees(publicClient, callData, parseGwei('1'))
|
|
120
|
+
: {};
|
|
121
|
+
|
|
122
|
+
const { request } = await publicClient.simulateContract({
|
|
123
|
+
...callData,
|
|
124
|
+
...gasEstimationData,
|
|
85
125
|
});
|
|
86
126
|
|
|
87
127
|
const txHash = await walletClient.writeContract(request);
|
|
@@ -48,6 +48,7 @@ export interface IGetBasculeDepositStatusParameters
|
|
|
48
48
|
* You can omit `deposit` parameter if `rawPayload` is provided.
|
|
49
49
|
*/
|
|
50
50
|
rawPayload?: string;
|
|
51
|
+
token?: Token;
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
/**
|
|
@@ -69,6 +70,7 @@ export async function getBasculeDepositStatus({
|
|
|
69
70
|
chainId,
|
|
70
71
|
rpcUrl,
|
|
71
72
|
env = DEFAULT_ENV,
|
|
73
|
+
token = Token.LBTC,
|
|
72
74
|
}: IGetBasculeDepositStatusParameters) {
|
|
73
75
|
const payload = deposit?.rawPayload || rawPayload;
|
|
74
76
|
|
|
@@ -78,12 +80,12 @@ export async function getBasculeDepositStatus({
|
|
|
78
80
|
);
|
|
79
81
|
}
|
|
80
82
|
|
|
81
|
-
const publicClient = makePublicClient({ chainId, rpcUrl });
|
|
82
|
-
const
|
|
83
|
+
const publicClient = makePublicClient({ chainId, rpcUrl, env });
|
|
84
|
+
const tokenContractInfo = getTokenContractInfo(token, chainId, env);
|
|
83
85
|
|
|
84
86
|
const basculeContractAddress = await publicClient.readContract({
|
|
85
|
-
abi:
|
|
86
|
-
address:
|
|
87
|
+
abi: tokenContractInfo.abi,
|
|
88
|
+
address: tokenContractInfo.address,
|
|
87
89
|
functionName: 'Bascule',
|
|
88
90
|
});
|
|
89
91
|
|
|
@@ -5,12 +5,15 @@ import { CodeBlock } from '../../stories/components/CodeBlock';
|
|
|
5
5
|
import { functionType } from '../../stories/components/decorators';
|
|
6
6
|
import useQuery from '../../stories/hooks/useQuery';
|
|
7
7
|
import { getLBTCMintingFee } from './getLBTCMintingFee';
|
|
8
|
+
import { chainSelector, envSelector } from '../../stories/arg-types';
|
|
9
|
+
import { Env } from '@lombard.finance/sdk-common';
|
|
8
10
|
|
|
9
11
|
const meta = {
|
|
10
12
|
title: 'read/getLBTCMintingFee',
|
|
11
13
|
component: StoryView,
|
|
12
14
|
tags: ['autodocs'],
|
|
13
15
|
decorators: [functionType('read')],
|
|
16
|
+
argTypes: { ...chainSelector, ...envSelector },
|
|
14
17
|
} satisfies Meta<typeof StoryView>;
|
|
15
18
|
|
|
16
19
|
export default meta;
|
|
@@ -20,23 +23,17 @@ type Story = StoryObj<typeof meta>;
|
|
|
20
23
|
export const Holesky: Story = {
|
|
21
24
|
args: {
|
|
22
25
|
chainId: ChainId.holesky,
|
|
26
|
+
env: undefined,
|
|
23
27
|
},
|
|
24
28
|
};
|
|
25
29
|
|
|
26
|
-
|
|
27
|
-
args: {
|
|
28
|
-
chainId: ChainId.ethereum,
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
type GetLBTCMintingFeeProps = {
|
|
33
|
-
chainId: ChainId;
|
|
34
|
-
};
|
|
30
|
+
type Params = Parameters<typeof getLBTCMintingFee>[0];
|
|
35
31
|
|
|
36
|
-
export function StoryView(props:
|
|
32
|
+
export function StoryView(props: Params) {
|
|
37
33
|
const request = async () => {
|
|
38
34
|
return getLBTCMintingFee({
|
|
39
35
|
chainId: props.chainId,
|
|
36
|
+
env: props.env,
|
|
40
37
|
});
|
|
41
38
|
};
|
|
42
39
|
|
|
@@ -16,15 +16,31 @@ import { Token } from '../../tokens/token-addresses';
|
|
|
16
16
|
*
|
|
17
17
|
* @return {Promise<BigNumber>}
|
|
18
18
|
*/
|
|
19
|
-
export async function getLBTCMintingFee(
|
|
19
|
+
export async function getLBTCMintingFee(
|
|
20
|
+
props: CommonParameters,
|
|
21
|
+
): Promise<BigNumber> {
|
|
22
|
+
return getMintingFee({ token: Token.LBTC, ...props });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Gets LBTC burn commission (fee) amount. */
|
|
26
|
+
export async function getLBTCBurningFee(props: CommonParameters) {
|
|
27
|
+
return getBurningFee({ token: Token.LBTC, ...props });
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function getMintingFee({
|
|
31
|
+
token,
|
|
20
32
|
chainId,
|
|
21
33
|
rpcUrl,
|
|
22
34
|
env,
|
|
23
|
-
}: CommonParameters)
|
|
35
|
+
}: { token: Token } & CommonParameters) {
|
|
36
|
+
if (![Token.LBTC, Token.BTCK].includes(token)) {
|
|
37
|
+
throw new Error(`Unsupported token: ${token}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
24
40
|
const environment = env || determineEnv(chainId);
|
|
25
41
|
|
|
26
|
-
const publicClient = makePublicClient({ chainId, rpcUrl });
|
|
27
|
-
const lbtcContract = getTokenContractInfo(
|
|
42
|
+
const publicClient = makePublicClient({ chainId, rpcUrl, env: environment });
|
|
43
|
+
const lbtcContract = getTokenContractInfo(token, chainId, environment);
|
|
28
44
|
|
|
29
45
|
const rawFeeValue = await publicClient.readContract({
|
|
30
46
|
abi: lbtcContract.abi,
|
|
@@ -32,6 +48,29 @@ export async function getLBTCMintingFee({
|
|
|
32
48
|
functionName: 'getMintFee',
|
|
33
49
|
});
|
|
34
50
|
|
|
35
|
-
|
|
36
|
-
|
|
51
|
+
return fromSatoshi(String(rawFeeValue));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function getBurningFee({
|
|
55
|
+
token,
|
|
56
|
+
chainId,
|
|
57
|
+
rpcUrl,
|
|
58
|
+
env,
|
|
59
|
+
}: { token: Token } & CommonParameters) {
|
|
60
|
+
if (![Token.LBTC, Token.BTCK].includes(token)) {
|
|
61
|
+
throw new Error(`Unsupported token: ${token}`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const environment = env || determineEnv(chainId);
|
|
65
|
+
|
|
66
|
+
const publicClient = makePublicClient({ chainId, rpcUrl, env: environment });
|
|
67
|
+
const lbtcContract = getTokenContractInfo(token, chainId, environment);
|
|
68
|
+
|
|
69
|
+
const rawFeeValue = await publicClient.readContract({
|
|
70
|
+
abi: lbtcContract.abi,
|
|
71
|
+
address: lbtcContract.address,
|
|
72
|
+
functionName: 'getBurnCommission',
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
return fromSatoshi(String(rawFeeValue));
|
|
37
76
|
}
|
|
@@ -6,12 +6,14 @@ import useQuery from '../../stories/hooks/useQuery';
|
|
|
6
6
|
import { getLBTCTotalSupply } from './getLBTCTotalSupply';
|
|
7
7
|
import { ChainId } from '../../common/chains';
|
|
8
8
|
import { functionType } from '../../stories/components/decorators';
|
|
9
|
+
import { chainSelector, envSelector } from '../../stories/arg-types';
|
|
9
10
|
|
|
10
11
|
const meta = {
|
|
11
12
|
title: 'read/getLBTCTotalSupply',
|
|
12
13
|
component: StoryView,
|
|
13
14
|
tags: ['autodocs'],
|
|
14
15
|
decorators: [functionType('read')],
|
|
16
|
+
argTypes: { ...chainSelector, ...envSelector },
|
|
15
17
|
} satisfies Meta<typeof StoryView>;
|
|
16
18
|
|
|
17
19
|
export default meta;
|
|
@@ -21,7 +23,7 @@ type Story = StoryObj<typeof meta>;
|
|
|
21
23
|
export const WithParams: Story = {
|
|
22
24
|
args: {
|
|
23
25
|
chainId: ChainId.ethereum,
|
|
24
|
-
env:
|
|
26
|
+
env: undefined,
|
|
25
27
|
},
|
|
26
28
|
};
|
|
27
29
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { CommonParameters } from '../../common/parameters';
|
|
2
|
-
import { DEFAULT_ENV } from '@lombard.finance/sdk-common';
|
|
3
2
|
import BigNumber from 'bignumber.js';
|
|
4
3
|
import { fromSatoshi } from '../../utils/satoshi';
|
|
5
4
|
import { makePublicClient } from '../../clients/public-client';
|
|
6
5
|
import { getTokenContractInfo } from '../../tokens/tokens';
|
|
7
6
|
import { Token } from '../../tokens/token-addresses';
|
|
7
|
+
import { determineEnv } from '../../utils/env';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Get the total supply of LBTC tokens.
|
|
@@ -19,10 +19,11 @@ import { Token } from '../../tokens/token-addresses';
|
|
|
19
19
|
export async function getLBTCTotalSupply({
|
|
20
20
|
chainId,
|
|
21
21
|
rpcUrl,
|
|
22
|
-
env
|
|
22
|
+
env,
|
|
23
23
|
}: CommonParameters): Promise<BigNumber> {
|
|
24
|
-
const
|
|
25
|
-
const
|
|
24
|
+
const environment = env || determineEnv(chainId);
|
|
25
|
+
const publicClient = makePublicClient({ chainId, rpcUrl, env: environment });
|
|
26
|
+
const lbtcContract = getTokenContractInfo(Token.LBTC, chainId, environment);
|
|
26
27
|
|
|
27
28
|
const totalSupplyRaw = await publicClient.readContract({
|
|
28
29
|
abi: lbtcContract.abi,
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
functionType,
|
|
14
14
|
wagmiDecorator,
|
|
15
15
|
} from '../../stories/components/decorators';
|
|
16
|
+
import { Env } from '@lombard.finance/sdk-common';
|
|
16
17
|
|
|
17
18
|
const meta = {
|
|
18
19
|
title: 'write/signNetworkFee',
|
|
@@ -29,6 +30,7 @@ export const WithParams: Story = {
|
|
|
29
30
|
args: {
|
|
30
31
|
fee: '1100',
|
|
31
32
|
expiry: toUnix(now() + DAY),
|
|
33
|
+
env: Env.prod,
|
|
32
34
|
},
|
|
33
35
|
};
|
|
34
36
|
|
|
@@ -3,7 +3,7 @@ import { DEFAULT_ENV } from '@lombard.finance/sdk-common';
|
|
|
3
3
|
import { Button } from '../../stories/components/Button';
|
|
4
4
|
import { CodeBlock } from '../../stories/components/CodeBlock';
|
|
5
5
|
import useQuery from '../../stories/hooks/useQuery';
|
|
6
|
-
import {
|
|
6
|
+
import { redeemToken } from './unstakeLBTC';
|
|
7
7
|
import { ConnectButton } from '../../stories/components/ConnectButton';
|
|
8
8
|
import {
|
|
9
9
|
canPerformAction,
|
|
@@ -13,12 +13,17 @@ import {
|
|
|
13
13
|
functionType,
|
|
14
14
|
wagmiDecorator,
|
|
15
15
|
} from '../../stories/components/decorators';
|
|
16
|
+
import { Token } from '../../tokens/token-addresses';
|
|
17
|
+
import { makeTokenSelector } from '../../stories/arg-types';
|
|
16
18
|
|
|
17
19
|
const meta = {
|
|
18
20
|
title: 'write/unstakeLBTC',
|
|
19
21
|
component: StoryView,
|
|
20
22
|
tags: ['autodocs'],
|
|
21
23
|
decorators: [wagmiDecorator, functionType('write')],
|
|
24
|
+
argTypes: {
|
|
25
|
+
...makeTokenSelector([Token.LBTC, Token.BTCK]),
|
|
26
|
+
},
|
|
22
27
|
} satisfies Meta<typeof StoryView>;
|
|
23
28
|
|
|
24
29
|
export default meta;
|
|
@@ -28,12 +33,16 @@ type Story = StoryObj<typeof meta>;
|
|
|
28
33
|
export const WithParams: Story = {
|
|
29
34
|
args: {
|
|
30
35
|
amount: 0.00001,
|
|
36
|
+
token: Token.LBTC,
|
|
31
37
|
btcAddress: '',
|
|
32
38
|
env: DEFAULT_ENV,
|
|
33
39
|
},
|
|
34
40
|
};
|
|
35
41
|
|
|
36
|
-
type ClaimLBTCProps =
|
|
42
|
+
type ClaimLBTCProps = Omit<
|
|
43
|
+
Parameters<typeof redeemToken>[0],
|
|
44
|
+
'account' | 'chainId' | 'provider'
|
|
45
|
+
>;
|
|
37
46
|
|
|
38
47
|
export function StoryView(props: ClaimLBTCProps) {
|
|
39
48
|
const connection = useConnection();
|
|
@@ -44,9 +53,11 @@ export function StoryView(props: ClaimLBTCProps) {
|
|
|
44
53
|
return;
|
|
45
54
|
}
|
|
46
55
|
|
|
47
|
-
return
|
|
56
|
+
return redeemToken({
|
|
48
57
|
amount: props.amount,
|
|
49
58
|
btcAddress: props.btcAddress,
|
|
59
|
+
env: props.env,
|
|
60
|
+
token: props.token,
|
|
50
61
|
|
|
51
62
|
account: connection.account.address,
|
|
52
63
|
chainId: connection.account.chainId,
|
|
@@ -71,7 +82,7 @@ export function StoryView(props: ClaimLBTCProps) {
|
|
|
71
82
|
onClick={refetch}
|
|
72
83
|
disabled={isLoading || !connection.account.address}
|
|
73
84
|
isLoading={isLoading}
|
|
74
|
-
actionName={
|
|
85
|
+
actionName={redeemToken.name}
|
|
75
86
|
/>
|
|
76
87
|
|
|
77
88
|
<CodeBlock text={error || data} />
|
|
@@ -3,11 +3,12 @@ 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 { CHAIN_ID_TO_VIEM_CHAIN_MAP } from '../../common/chains';
|
|
7
|
-
import { Hex } from 'viem';
|
|
6
|
+
import { CHAIN_ID_TO_VIEM_CHAIN_MAP, isKatanaChain } from '../../common/chains';
|
|
7
|
+
import { Hex, parseGwei } from 'viem';
|
|
8
8
|
import BigNumber from 'bignumber.js';
|
|
9
9
|
import { getTokenContractInfo } from '../../tokens/tokens';
|
|
10
10
|
import { Token } from '../../tokens/token-addresses';
|
|
11
|
+
import { estimateGasFees } from '../../utils/gas';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* The unstake parameters.
|
|
@@ -43,24 +44,65 @@ export async function unstakeLBTC({
|
|
|
43
44
|
rpcUrl,
|
|
44
45
|
env,
|
|
45
46
|
}: IUnstakeLBTCParams): Promise<Hex> {
|
|
47
|
+
return redeemToken({
|
|
48
|
+
btcAddress,
|
|
49
|
+
amount,
|
|
50
|
+
account,
|
|
51
|
+
chainId,
|
|
52
|
+
provider,
|
|
53
|
+
rpcUrl,
|
|
54
|
+
env,
|
|
55
|
+
token: Token.LBTC,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export async function redeemToken({
|
|
60
|
+
btcAddress,
|
|
61
|
+
amount,
|
|
62
|
+
account,
|
|
63
|
+
chainId,
|
|
64
|
+
provider,
|
|
65
|
+
rpcUrl,
|
|
66
|
+
env,
|
|
67
|
+
token = Token.LBTC,
|
|
68
|
+
}: IUnstakeLBTCParams & { token?: Token.LBTC | Token.BTCK }) {
|
|
69
|
+
if (![Token.LBTC, Token.BTCK].includes(token)) {
|
|
70
|
+
throw new Error('Unsupported token');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (token === Token.BTCK && !isKatanaChain(chainId)) {
|
|
74
|
+
throw new Error('Operation not permitted');
|
|
75
|
+
}
|
|
76
|
+
|
|
46
77
|
const outputScript = getOutputScript(btcAddress, env);
|
|
47
|
-
const amountSat = toSatoshi(amount).toNumber();
|
|
48
78
|
|
|
49
|
-
const
|
|
79
|
+
const amountSat = toSatoshi(amount).toNumber();
|
|
50
80
|
|
|
51
|
-
const publicClient = makePublicClient({ chainId, rpcUrl });
|
|
81
|
+
const publicClient = makePublicClient({ chainId, rpcUrl, env });
|
|
52
82
|
const walletClient = makeWalletClient({ provider, chainId });
|
|
53
83
|
|
|
54
|
-
const
|
|
55
|
-
|
|
84
|
+
const tokenContract = getTokenContractInfo(token, chainId, env);
|
|
85
|
+
|
|
86
|
+
const callData = {
|
|
87
|
+
abi: tokenContract.abi,
|
|
88
|
+
address: tokenContract.address,
|
|
56
89
|
account,
|
|
57
90
|
chain: CHAIN_ID_TO_VIEM_CHAIN_MAP[chainId],
|
|
58
|
-
|
|
59
|
-
functionName: 'redeem',
|
|
91
|
+
functionName: 'redeem', // FIXME: both LBTC and Native LBTC have the same redeem method, change this if Native LBTC ABI changes.
|
|
60
92
|
args: [outputScript, BigInt(amountSat)],
|
|
61
|
-
}
|
|
93
|
+
} as const;
|
|
94
|
+
|
|
95
|
+
// Katana Tatara requires tip TODO: Recheck if this is needed or is it just OKX wallet issue
|
|
96
|
+
const gasEstimationData = isKatanaChain(chainId)
|
|
97
|
+
? await estimateGasFees(publicClient, callData, parseGwei('1'))
|
|
98
|
+
: {};
|
|
62
99
|
|
|
63
|
-
const
|
|
100
|
+
const { request } = await publicClient.simulateContract(callData);
|
|
101
|
+
|
|
102
|
+
const txHash = await walletClient.writeContract({
|
|
103
|
+
...request,
|
|
104
|
+
...gasEstimationData,
|
|
105
|
+
});
|
|
64
106
|
|
|
65
107
|
return txHash;
|
|
66
108
|
}
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ArgTypes } from 'storybook/internal/types';
|
|
2
|
+
import { ChainId } from '../common/chains';
|
|
3
|
+
import { Env } from '@lombard.finance/sdk-common';
|
|
4
|
+
import { Token } from '../tokens/token-addresses';
|
|
5
|
+
|
|
6
|
+
export const chainSelector: Partial<ArgTypes> = {
|
|
7
|
+
chainId: {
|
|
8
|
+
mapping: ChainId,
|
|
9
|
+
options: Object.keys(ChainId),
|
|
10
|
+
control: { type: 'select' },
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const envSelector: Partial<ArgTypes> = {
|
|
15
|
+
env: {
|
|
16
|
+
mapping: Env,
|
|
17
|
+
options: Object.keys(Env),
|
|
18
|
+
control: { type: 'select' },
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const makeTokenSelector = (tokens?: Token[]): Partial<ArgTypes> => ({
|
|
23
|
+
token: {
|
|
24
|
+
mapping: Token,
|
|
25
|
+
options: Object.keys(Token).filter(tk => {
|
|
26
|
+
if (!tokens) return true;
|
|
27
|
+
|
|
28
|
+
const entries = Object.entries(Token);
|
|
29
|
+
const keys = tokens.map(tv => entries.find(([, v]) => v === tv)?.[0]);
|
|
30
|
+
return keys.includes(tk);
|
|
31
|
+
}),
|
|
32
|
+
control: { type: 'select' },
|
|
33
|
+
},
|
|
34
|
+
});
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
swellchain,
|
|
20
20
|
} from 'viem/chains';
|
|
21
21
|
import { createConfig, http, WagmiProvider } from 'wagmi';
|
|
22
|
+
import { katana, katanaTatara } from '../../../common/chains';
|
|
22
23
|
|
|
23
24
|
const config = createConfig({
|
|
24
25
|
chains: [
|
|
@@ -27,6 +28,7 @@ const config = createConfig({
|
|
|
27
28
|
berachain,
|
|
28
29
|
bsc,
|
|
29
30
|
corn,
|
|
31
|
+
katana,
|
|
30
32
|
morph,
|
|
31
33
|
sonic,
|
|
32
34
|
swellchain,
|
|
@@ -35,6 +37,7 @@ const config = createConfig({
|
|
|
35
37
|
berachainTestnetbArtio,
|
|
36
38
|
bscTestnet,
|
|
37
39
|
holesky,
|
|
40
|
+
katanaTatara,
|
|
38
41
|
morphHolesky,
|
|
39
42
|
sepolia,
|
|
40
43
|
sonicBlazeTestnet,
|
|
@@ -45,6 +48,7 @@ const config = createConfig({
|
|
|
45
48
|
[berachain.id]: http(rpcUrlConfig[berachain.id]),
|
|
46
49
|
[bsc.id]: http(rpcUrlConfig[bsc.id]),
|
|
47
50
|
[corn.id]: http(rpcUrlConfig[corn.id]),
|
|
51
|
+
[katana.id]: http(rpcUrlConfig[katana.id]),
|
|
48
52
|
[morph.id]: http(rpcUrlConfig[morph.id]),
|
|
49
53
|
[sonic.id]: http(rpcUrlConfig[sonic.id]),
|
|
50
54
|
[swellchain.id]: http(rpcUrlConfig[swellchain.id]),
|
|
@@ -53,6 +57,7 @@ const config = createConfig({
|
|
|
53
57
|
[berachainTestnetbArtio.id]: http(rpcUrlConfig[berachainTestnetbArtio.id]),
|
|
54
58
|
[bscTestnet.id]: http(rpcUrlConfig[bscTestnet.id]),
|
|
55
59
|
[holesky.id]: http(rpcUrlConfig[holesky.id]),
|
|
60
|
+
[katanaTatara.id]: http(rpcUrlConfig[katanaTatara.id]),
|
|
56
61
|
[morphHolesky.id]: http(rpcUrlConfig[morphHolesky.id]),
|
|
57
62
|
[sepolia.id]: http(rpcUrlConfig[sepolia.id]),
|
|
58
63
|
[sonicBlazeTestnet.id]: http(rpcUrlConfig[sonicBlazeTestnet.id]),
|