@lombard.finance/sdk 3.5.10 → 3.6.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/dist/index.cjs +1 -1
- package/dist/index.js +95 -89
- package/dist/index2.cjs +52 -52
- package/dist/index2.js +8970 -5588
- package/package.json +6 -4
- package/src/api-functions/generateDepositBtcAddress/generateDepositBtcAddress.stories.tsx +1 -1
- package/src/api-functions/generateDepositBtcAddress/generateDepositBtcAddress.ts +2 -2
- package/src/api-functions/getDepositBtcAddress/getDepositBtcAddress.stories.tsx +1 -1
- package/src/api-functions/getDepositBtcAddress/getDepositBtcAddress.ts +12 -13
- package/src/bridge/index.ts +8 -2
- package/src/bridge/lib/config.ts +28 -0
- package/src/bridge/lib/oft-bridge.ts +1 -0
- package/src/clients/rpc-url-config.ts +3 -1
- package/src/common/api-config.ts +4 -4
- package/src/common/chains.ts +22 -1
- package/src/contract-functions/claimLBTC/claimLBTC.stories.tsx +1 -1
- package/src/contract-functions/claimLBTC/claimLBTC.ts +3 -2
- package/src/contract-functions/getLBTCMintingFee/getLBTCMintingFee.tsx +84 -17
- package/src/contract-functions/unstakeLBTC/unstakeLBTC.stories.tsx +1 -1
- package/src/contract-functions/unstakeLBTC/unstakeLBTC.ts +6 -4
- package/src/index.ts +3 -0
- package/src/stories/components/decorators/wagmi-decorator.tsx +3 -1
- package/src/tokens/abi/ASSET_ROUTER_ABI.ts +1102 -0
- package/src/tokens/abi/NATIVE_LBTC_ABI.ts +1147 -0
- package/src/tokens/abi/STLBTC_ABI.ts +1062 -0
- package/src/tokens/lbtc-addresses.ts +2 -48
- package/src/tokens/token-addresses.ts +27 -19
- package/src/tokens/tokens.ts +45 -15
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
|
+
"name": "@lombard.finance/sdk",
|
|
3
|
+
"version": "3.6.0",
|
|
2
4
|
"dependencies": {
|
|
3
5
|
"@lombard.finance/sdk-common": "^3.0.0",
|
|
4
|
-
"viem": "^2.23.15"
|
|
6
|
+
"viem": "^2.23.15",
|
|
7
|
+
"vite": "^6.3.5"
|
|
5
8
|
},
|
|
6
9
|
"devDependencies": {
|
|
10
|
+
"@biomejs/biome": "^1.9.4",
|
|
7
11
|
"@chromatic-com/storybook": "1.6.1",
|
|
8
12
|
"@storybook/addon-essentials": "^8.2.9",
|
|
9
13
|
"@storybook/addon-interactions": "^8.2.9",
|
|
@@ -40,7 +44,6 @@
|
|
|
40
44
|
"src"
|
|
41
45
|
],
|
|
42
46
|
"license": "MIT",
|
|
43
|
-
"name": "@lombard.finance/sdk",
|
|
44
47
|
"peerDependencies": {
|
|
45
48
|
"@layerzerolabs/lz-v2-utilities": "3.0.17",
|
|
46
49
|
"axios": "^1",
|
|
@@ -58,6 +61,5 @@
|
|
|
58
61
|
"watch": "vite build --watch"
|
|
59
62
|
},
|
|
60
63
|
"type": "module",
|
|
61
|
-
"types": "./src/index.ts"
|
|
62
|
-
"version": "3.5.10"
|
|
64
|
+
"types": "./src/index.ts"
|
|
63
65
|
}
|
|
@@ -20,7 +20,7 @@ const meta = {
|
|
|
20
20
|
decorators: [functionType('api-post')],
|
|
21
21
|
argTypes: {
|
|
22
22
|
...chainSelector,
|
|
23
|
-
...makeTokenSelector([Token.LBTC, Token.BTCK]),
|
|
23
|
+
...makeTokenSelector([Token.LBTC, Token.BTCK, Token.NativeLBTC]),
|
|
24
24
|
},
|
|
25
25
|
} satisfies Meta<typeof StoryView>;
|
|
26
26
|
|
|
@@ -63,8 +63,8 @@ export interface IGenerateDepositBtcAddressParams extends IEnvParam {
|
|
|
63
63
|
signatureData?: string;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
const EXTRA_PARAMS_TOKENS = [Token.LBTC, Token.BTCK];
|
|
67
|
-
const SUPPORTED_TOKENS = [Token.LBTC, Token.BTCK];
|
|
66
|
+
const EXTRA_PARAMS_TOKENS = [Token.LBTC, Token.BTCK, Token.NativeLBTC];
|
|
67
|
+
const SUPPORTED_TOKENS = [Token.LBTC, Token.BTCK, Token.NativeLBTC];
|
|
68
68
|
|
|
69
69
|
/**
|
|
70
70
|
* Generates a BTC deposit address.
|
|
@@ -20,7 +20,7 @@ const meta = {
|
|
|
20
20
|
decorators: [functionType('api-get')],
|
|
21
21
|
argTypes: {
|
|
22
22
|
...chainSelector,
|
|
23
|
-
...makeTokenSelector([Token.LBTC, Token.BTCK]),
|
|
23
|
+
...makeTokenSelector([Token.LBTC, Token.BTCK, Token.NativeLBTC]),
|
|
24
24
|
},
|
|
25
25
|
} satisfies Meta<typeof StoryView>;
|
|
26
26
|
|
|
@@ -4,7 +4,12 @@ import {
|
|
|
4
4
|
BlockchainIdentifier,
|
|
5
5
|
getChainNameById,
|
|
6
6
|
} from '../../common/blockchain-identifier';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
ChainId,
|
|
9
|
+
isValidChain,
|
|
10
|
+
SolanaChain,
|
|
11
|
+
SuiChain,
|
|
12
|
+
} from '../../common/chains';
|
|
8
13
|
import { IEnvParam } from '../../common/parameters';
|
|
9
14
|
import { Token } from '../../tokens/token-addresses';
|
|
10
15
|
import { getTokenContractInfo } from '../../tokens/tokens';
|
|
@@ -176,7 +181,7 @@ export async function getDepositBtcAddress({
|
|
|
176
181
|
|
|
177
182
|
let depositAddress: string | undefined = undefined;
|
|
178
183
|
|
|
179
|
-
if (![Token.LBTC, Token.BTCK].includes(token)) {
|
|
184
|
+
if (![Token.LBTC, Token.BTCK, Token.NativeLBTC].includes(token)) {
|
|
180
185
|
throw new Error('Unsupported token');
|
|
181
186
|
}
|
|
182
187
|
|
|
@@ -185,19 +190,13 @@ export async function getDepositBtcAddress({
|
|
|
185
190
|
| { token_address: string; aux_version?: number }
|
|
186
191
|
| undefined = undefined;
|
|
187
192
|
try {
|
|
188
|
-
if (chainId
|
|
193
|
+
if (isValidChain(chainId)) {
|
|
189
194
|
const tokenContractInfo = getTokenContractInfo(token, chainId, env);
|
|
190
195
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
};
|
|
196
|
-
} else {
|
|
197
|
-
tokenAddressFilter = {
|
|
198
|
-
token_address: tokenContractInfo.address.toLowerCase(),
|
|
199
|
-
};
|
|
200
|
-
}
|
|
196
|
+
tokenAddressFilter = {
|
|
197
|
+
token_address: tokenContractInfo.address.toLowerCase(),
|
|
198
|
+
aux_version: token === Token.BTCK ? 1 : undefined,
|
|
199
|
+
};
|
|
201
200
|
}
|
|
202
201
|
} catch {
|
|
203
202
|
// NOOP
|
package/src/bridge/index.ts
CHANGED
|
@@ -5,7 +5,13 @@ export { bridge, type BridgeParameters } from './lib/bridge';
|
|
|
5
5
|
export { bridgeCCIP, type BridgeCCIPParameters } from './lib/ccip-bridge';
|
|
6
6
|
|
|
7
7
|
/** OFT bridge func */
|
|
8
|
-
export { bridgeOFT, type BridgeOFTParameters } from './lib/oft-bridge';
|
|
8
|
+
export { bridgeOFT, type BridgeOFTParameters, } from './lib/oft-bridge';
|
|
9
9
|
|
|
10
10
|
/** Utils */
|
|
11
|
-
export {
|
|
11
|
+
export {
|
|
12
|
+
getBridgeInfo,
|
|
13
|
+
OFT_HI_GAS_LIMIT_CHAINS,
|
|
14
|
+
OFT_GAS_LIMIT,
|
|
15
|
+
OFT_HI_GAS_LIMIT,
|
|
16
|
+
} from './lib/config';
|
|
17
|
+
|
package/src/bridge/lib/config.ts
CHANGED
|
@@ -43,6 +43,7 @@ export const OFT_BRIDGE_CHAINS = [
|
|
|
43
43
|
ChainId.corn,
|
|
44
44
|
ChainId.etherlink,
|
|
45
45
|
ChainId.swell,
|
|
46
|
+
ChainId.tac,
|
|
46
47
|
// Testnets:
|
|
47
48
|
ChainId.berachainBartioTestnet,
|
|
48
49
|
ChainId.sepolia,
|
|
@@ -60,8 +61,13 @@ export const OFT_HI_GAS_LIMIT_CHAINS = [
|
|
|
60
61
|
// Mainnets:
|
|
61
62
|
ChainId.berachain,
|
|
62
63
|
ChainId.etherlink,
|
|
64
|
+
ChainId.morph,
|
|
65
|
+
ChainId.sonic,
|
|
66
|
+
ChainId.corn,
|
|
67
|
+
ChainId.tac,
|
|
63
68
|
// Testnets:
|
|
64
69
|
ChainId.berachainBartioTestnet,
|
|
70
|
+
ChainId.morphHolesky,
|
|
65
71
|
];
|
|
66
72
|
|
|
67
73
|
export type OFTBridgeChain = (typeof OFT_BRIDGE_CHAINS)[number];
|
|
@@ -266,6 +272,17 @@ const OFT_BRIDGES: OFTBridgeConfig[] = [
|
|
|
266
272
|
},
|
|
267
273
|
},
|
|
268
274
|
],
|
|
275
|
+
[
|
|
276
|
+
bridgeIdentifier([ChainId.ethereum, ChainId.tac]),
|
|
277
|
+
{
|
|
278
|
+
type: BridgeType.OFT,
|
|
279
|
+
contract: {
|
|
280
|
+
address: '0xA7c4d94F98b6e94C139c4645e4E9a94CD7C0Abf7',
|
|
281
|
+
abi: OFT_BRIDGE_ADAPTER_ABI as Abi,
|
|
282
|
+
chainId: ChainId.ethereum,
|
|
283
|
+
},
|
|
284
|
+
},
|
|
285
|
+
],
|
|
269
286
|
|
|
270
287
|
[
|
|
271
288
|
bridgeIdentifier([ChainId.berachain, ChainId.ethereum]),
|
|
@@ -314,6 +331,17 @@ const OFT_BRIDGES: OFTBridgeConfig[] = [
|
|
|
314
331
|
},
|
|
315
332
|
},
|
|
316
333
|
],
|
|
334
|
+
[
|
|
335
|
+
bridgeIdentifier([ChainId.tac, ChainId.ethereum]),
|
|
336
|
+
{
|
|
337
|
+
type: BridgeType.OFT,
|
|
338
|
+
contract: {
|
|
339
|
+
address: '0x1298131cDa718bBcA7ACB1f2411e71c05E16f269',
|
|
340
|
+
abi: OFT_BRIDGE_ADAPTER_ABI as Abi,
|
|
341
|
+
chainId: ChainId.tac,
|
|
342
|
+
},
|
|
343
|
+
},
|
|
344
|
+
],
|
|
317
345
|
|
|
318
346
|
// Testnets:
|
|
319
347
|
|
|
@@ -32,6 +32,7 @@ const DESTINATION_ENDPOINT_ID_MAP: Record<OFTBridgeChain, number> = {
|
|
|
32
32
|
[ChainId.corn]: 30331,
|
|
33
33
|
[ChainId.etherlink]: 30292,
|
|
34
34
|
[ChainId.swell]: 30335,
|
|
35
|
+
[ChainId.tac]: 30377,
|
|
35
36
|
// Testnets:
|
|
36
37
|
[ChainId.sepolia]: 40161,
|
|
37
38
|
[ChainId.berachainBartioTestnet]: 40291,
|
|
@@ -4,7 +4,7 @@ import { getApiConfig } from '../common/api-config';
|
|
|
4
4
|
|
|
5
5
|
export type TRpcUrlConfig = Record<number, string>;
|
|
6
6
|
|
|
7
|
-
export const RPC_URL = 'https://bff.prod.lombard.
|
|
7
|
+
export const RPC_URL = 'https://bff.prod.lombard-fi.com/multi-rpc/proxy';
|
|
8
8
|
// export const RPC_URL = 'http://localhost:8001/multi-rpc/proxy';
|
|
9
9
|
|
|
10
10
|
export const rpcUrlConfig: TRpcUrlConfig = {
|
|
@@ -14,6 +14,7 @@ export const rpcUrlConfig: TRpcUrlConfig = {
|
|
|
14
14
|
[ChainId.corn]: `${RPC_URL}/corn_maizenet`,
|
|
15
15
|
[ChainId.katana]: `${RPC_URL}/katana`,
|
|
16
16
|
[ChainId.sonic]: `${RPC_URL}/sonic_mainnet`,
|
|
17
|
+
[ChainId.tac]: `${RPC_URL}/tac`,
|
|
17
18
|
// Testnets:
|
|
18
19
|
[ChainId.baseSepoliaTestnet]: `${RPC_URL}/base_sepolia`,
|
|
19
20
|
[ChainId.binanceSmartChainTestnet]:
|
|
@@ -36,6 +37,7 @@ export function getRpcUrlConfig(env: Env) {
|
|
|
36
37
|
[ChainId.corn]: `${proxy}/corn_maizenet`,
|
|
37
38
|
[ChainId.katana]: `${proxy}/katana`,
|
|
38
39
|
[ChainId.sonic]: `${proxy}/sonic_mainnet`,
|
|
40
|
+
[ChainId.tac]: `${proxy}/tac`,
|
|
39
41
|
// Testnets:
|
|
40
42
|
[ChainId.baseSepoliaTestnet]: `${proxy}/base_sepolia`,
|
|
41
43
|
[ChainId.binanceSmartChainTestnet]:
|
package/src/common/api-config.ts
CHANGED
|
@@ -7,23 +7,23 @@ interface IApiConfig {
|
|
|
7
7
|
|
|
8
8
|
const stageConfig: IApiConfig = {
|
|
9
9
|
baseApiUrl: 'https://staging.prod.lombard.finance',
|
|
10
|
-
bffApiUrl: 'https://bff.stage.lombard.
|
|
10
|
+
bffApiUrl: 'https://bff.stage.lombard-fi.com',
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
const testnetConfig: IApiConfig = {
|
|
14
14
|
baseApiUrl: 'https://gastald-testnet.prod.lombard.finance',
|
|
15
|
-
bffApiUrl: 'https://bff.stage.lombard.
|
|
15
|
+
bffApiUrl: 'https://bff.stage.lombard-fi.com',
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
const prodConfig: IApiConfig = {
|
|
19
19
|
baseApiUrl: 'https://mainnet.prod.lombard.finance',
|
|
20
|
-
bffApiUrl: 'https://bff.prod.lombard.
|
|
20
|
+
bffApiUrl: 'https://bff.prod.lombard-fi.com',
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
const devConfig: IApiConfig = {
|
|
24
24
|
baseApiUrl: 'https://bft-dev.stage.lombard.finance',
|
|
25
25
|
// Note, bff on localhost works on 8001
|
|
26
|
-
bffApiUrl: 'https://bff.stage.lombard.
|
|
26
|
+
bffApiUrl: 'https://bff.stage.lombard-fi.com',
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
export const getApiConfig = (env: Env = DEFAULT_ENV): IApiConfig => {
|
package/src/common/chains.ts
CHANGED
|
@@ -74,6 +74,25 @@ export const katanaTatara = defineChain({
|
|
|
74
74
|
},
|
|
75
75
|
});
|
|
76
76
|
|
|
77
|
+
// FIXME: Remove this custom chain definition once TAC is supported by viem
|
|
78
|
+
export const tac = defineChain({
|
|
79
|
+
id: 239,
|
|
80
|
+
name: 'TAC',
|
|
81
|
+
nativeCurrency: {
|
|
82
|
+
decimals: 18,
|
|
83
|
+
name: 'TAC',
|
|
84
|
+
symbol: 'TAC',
|
|
85
|
+
},
|
|
86
|
+
rpcUrls: {
|
|
87
|
+
default: {
|
|
88
|
+
http: ['https://rpc.tac.build'],
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
blockExplorers: {
|
|
92
|
+
default: { name: 'TAC Explorer', url: 'https://explorer.tac.build' },
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
|
|
77
96
|
export const SUI_DEVNET_CHAIN = 'sui:devnet' as const;
|
|
78
97
|
export const SUI_TESTNET_CHAIN = 'sui:testnet' as const;
|
|
79
98
|
export const SUI_LOCALNET_CHAIN = 'sui:localnet' as const;
|
|
@@ -105,6 +124,7 @@ export const ChainId = {
|
|
|
105
124
|
morph: 2818,
|
|
106
125
|
sonic: 146,
|
|
107
126
|
swell: 1923,
|
|
127
|
+
tac: 239,
|
|
108
128
|
// Testnets:
|
|
109
129
|
baseSepoliaTestnet: 84532,
|
|
110
130
|
berachainBartioTestnet: 80084,
|
|
@@ -129,6 +149,7 @@ export const CHAIN_ID_TO_VIEM_CHAIN_MAP = {
|
|
|
129
149
|
[ChainId.morph]: morph,
|
|
130
150
|
[ChainId.sonic]: sonic,
|
|
131
151
|
[ChainId.swell]: swellchain,
|
|
152
|
+
[ChainId.tac]: tac,
|
|
132
153
|
// Testnets:
|
|
133
154
|
[ChainId.baseSepoliaTestnet]: baseSepolia,
|
|
134
155
|
[ChainId.berachainBartioTestnet]: berachainTestnetbArtio,
|
|
@@ -147,7 +168,7 @@ export const isKatanaChain = (chainId: unknown): chainId is KatanaChain => {
|
|
|
147
168
|
);
|
|
148
169
|
};
|
|
149
170
|
|
|
150
|
-
export function isValidChain(chainId:
|
|
171
|
+
export function isValidChain(chainId: unknown): chainId is ChainId {
|
|
151
172
|
return Object.values(ChainId).includes(chainId as ChainId);
|
|
152
173
|
}
|
|
153
174
|
|
|
@@ -22,7 +22,7 @@ const meta = {
|
|
|
22
22
|
tags: ['autodocs'],
|
|
23
23
|
decorators: [wagmiDecorator, functionType('write')],
|
|
24
24
|
argTypes: {
|
|
25
|
-
...makeTokenSelector([Token.LBTC, Token.BTCK]),
|
|
25
|
+
...makeTokenSelector([Token.LBTC, Token.BTCK, Token.NativeLBTC]),
|
|
26
26
|
},
|
|
27
27
|
} satisfies Meta<typeof StoryView>;
|
|
28
28
|
|
|
@@ -68,7 +68,7 @@ export async function mintToken({
|
|
|
68
68
|
env,
|
|
69
69
|
token = Token.LBTC,
|
|
70
70
|
}: IClaimLBTCParams & { token?: Token }) {
|
|
71
|
-
if (![Token.LBTC, Token.BTCK].includes(token)) {
|
|
71
|
+
if (![Token.LBTC, Token.BTCK, Token.NativeLBTC].includes(token)) {
|
|
72
72
|
throw new Error('Unsupported token');
|
|
73
73
|
}
|
|
74
74
|
|
|
@@ -109,7 +109,8 @@ export async function mintToken({
|
|
|
109
109
|
account,
|
|
110
110
|
chain: CHAIN_ID_TO_VIEM_CHAIN_MAP[chainId],
|
|
111
111
|
abi: tokenContract.abi,
|
|
112
|
-
functionName:
|
|
112
|
+
functionName:
|
|
113
|
+
token === Token.BTCK || token === Token.NativeLBTC ? 'mintV1' : 'mint', // FIXME: mintV1 is the equivalent on Native LBTC contract of mint on LBTC contract, change if contract ABI changes.
|
|
113
114
|
args: [ensureHex(data), ensureHex(proofSignature)],
|
|
114
115
|
} as const;
|
|
115
116
|
|
|
@@ -3,8 +3,9 @@ import { CommonParameters } from '../../common/parameters';
|
|
|
3
3
|
import { determineEnv } from '../../utils/env';
|
|
4
4
|
import { fromSatoshi } from '../../utils/satoshi';
|
|
5
5
|
import { makePublicClient } from '../../clients/public-client';
|
|
6
|
-
import { getTokenContractInfo } from '../../tokens/tokens';
|
|
6
|
+
import { getTokenContractInfo, isSTLBTCAbi } from '../../tokens/tokens';
|
|
7
7
|
import { Token } from '../../tokens/token-addresses';
|
|
8
|
+
import ASSET_ROUTER_ABI from '../../tokens/abi/ASSET_ROUTER_ABI';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Gets LBTC minting fee amount.
|
|
@@ -24,7 +25,7 @@ export async function getLBTCMintingFee(
|
|
|
24
25
|
|
|
25
26
|
/** Gets LBTC burn commission (fee) amount. */
|
|
26
27
|
export async function getLBTCBurningFee(props: CommonParameters) {
|
|
27
|
-
return
|
|
28
|
+
return getRedeemFee({ token: Token.LBTC, ...props });
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
export async function getMintingFee({
|
|
@@ -33,44 +34,110 @@ export async function getMintingFee({
|
|
|
33
34
|
rpcUrl,
|
|
34
35
|
env,
|
|
35
36
|
}: { token: Token } & CommonParameters) {
|
|
36
|
-
if (![Token.LBTC, Token.BTCK].includes(token)) {
|
|
37
|
+
if (![Token.LBTC, Token.BTCK, Token.NativeLBTC].includes(token)) {
|
|
37
38
|
throw new Error(`Unsupported token: ${token}`);
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
const environment = env || determineEnv(chainId);
|
|
41
42
|
|
|
42
43
|
const publicClient = makePublicClient({ chainId, rpcUrl, env: environment });
|
|
43
|
-
const
|
|
44
|
+
const tokenContract = getTokenContractInfo(token, chainId, environment);
|
|
45
|
+
const tokenContractAbi = tokenContract.abi;
|
|
44
46
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
let rawFeeValue = 0n;
|
|
48
|
+
|
|
49
|
+
if (isSTLBTCAbi(tokenContractAbi) || token === Token.NativeLBTC) {
|
|
50
|
+
const assetRouterAddress = await publicClient.readContract({
|
|
51
|
+
abi: tokenContractAbi,
|
|
52
|
+
address: tokenContract.address,
|
|
53
|
+
functionName: 'getAssetRouter',
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const assetRouter = {
|
|
57
|
+
abi: ASSET_ROUTER_ABI,
|
|
58
|
+
address: assetRouterAddress,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
rawFeeValue = await publicClient.readContract({
|
|
62
|
+
abi: assetRouter.abi,
|
|
63
|
+
address: assetRouter.address,
|
|
64
|
+
functionName: 'maxMintCommission',
|
|
65
|
+
});
|
|
66
|
+
} else {
|
|
67
|
+
rawFeeValue = await publicClient.readContract({
|
|
68
|
+
abi: tokenContract.abi,
|
|
69
|
+
address: tokenContract.address,
|
|
70
|
+
functionName: 'getMintFee',
|
|
71
|
+
});
|
|
72
|
+
}
|
|
50
73
|
|
|
51
74
|
return fromSatoshi(String(rawFeeValue));
|
|
52
75
|
}
|
|
53
76
|
|
|
54
|
-
export async function
|
|
77
|
+
export async function getRedeemFee({
|
|
55
78
|
token,
|
|
56
79
|
chainId,
|
|
57
80
|
rpcUrl,
|
|
58
81
|
env,
|
|
59
82
|
}: { token: Token } & CommonParameters) {
|
|
60
|
-
if (![Token.LBTC, Token.BTCK].includes(token)) {
|
|
83
|
+
if (![Token.LBTC, Token.BTCK, Token.NativeLBTC].includes(token)) {
|
|
61
84
|
throw new Error(`Unsupported token: ${token}`);
|
|
62
85
|
}
|
|
63
86
|
|
|
64
87
|
const environment = env || determineEnv(chainId);
|
|
65
88
|
|
|
66
89
|
const publicClient = makePublicClient({ chainId, rpcUrl, env: environment });
|
|
67
|
-
const
|
|
90
|
+
const tokenContract = getTokenContractInfo(token, chainId, environment);
|
|
91
|
+
|
|
92
|
+
let rawFeeValue = 0n;
|
|
93
|
+
if (
|
|
94
|
+
(token === Token.LBTC && isSTLBTCAbi(tokenContract.abi)) ||
|
|
95
|
+
token === Token.NativeLBTC
|
|
96
|
+
) {
|
|
97
|
+
const nativeTokenContract = getTokenContractInfo(
|
|
98
|
+
Token.NativeLBTC,
|
|
99
|
+
chainId,
|
|
100
|
+
environment,
|
|
101
|
+
);
|
|
68
102
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
103
|
+
const assetRouterAddress = await publicClient.readContract({
|
|
104
|
+
abi: tokenContract.abi,
|
|
105
|
+
address: tokenContract.address,
|
|
106
|
+
functionName: 'getAssetRouter',
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const assetRouter = {
|
|
110
|
+
abi: ASSET_ROUTER_ABI,
|
|
111
|
+
address: assetRouterAddress,
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const toNativeCommissionValue = await publicClient.readContract({
|
|
115
|
+
abi: assetRouter.abi,
|
|
116
|
+
address: assetRouter.address,
|
|
117
|
+
functionName: 'toNativeCommission',
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const [redeemFeeValue /* redeemForBtcMinAmountValue, isRedeemEnabled */] =
|
|
121
|
+
await publicClient.readContract({
|
|
122
|
+
abi: assetRouter.abi,
|
|
123
|
+
address: assetRouter.address,
|
|
124
|
+
functionName: 'tokenConfig',
|
|
125
|
+
args: [nativeTokenContract.address],
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
if (token === Token.LBTC) {
|
|
129
|
+
rawFeeValue = toNativeCommissionValue + redeemFeeValue;
|
|
130
|
+
} else {
|
|
131
|
+
rawFeeValue = redeemFeeValue;
|
|
132
|
+
}
|
|
133
|
+
} else {
|
|
134
|
+
// legacy (and BTCK v1)
|
|
135
|
+
rawFeeValue = await publicClient.readContract({
|
|
136
|
+
abi: tokenContract.abi,
|
|
137
|
+
address: tokenContract.address,
|
|
138
|
+
functionName: 'getBurnCommission',
|
|
139
|
+
});
|
|
140
|
+
}
|
|
74
141
|
|
|
75
142
|
return fromSatoshi(String(rawFeeValue));
|
|
76
143
|
}
|
|
@@ -22,7 +22,7 @@ const meta = {
|
|
|
22
22
|
tags: ['autodocs'],
|
|
23
23
|
decorators: [wagmiDecorator, functionType('write')],
|
|
24
24
|
argTypes: {
|
|
25
|
-
...makeTokenSelector([Token.LBTC, Token.BTCK]),
|
|
25
|
+
...makeTokenSelector([Token.LBTC, Token.BTCK, Token.NativeLBTC]),
|
|
26
26
|
},
|
|
27
27
|
} satisfies Meta<typeof StoryView>;
|
|
28
28
|
|
|
@@ -6,7 +6,7 @@ import { makePublicClient } from '../../clients/public-client';
|
|
|
6
6
|
import { CHAIN_ID_TO_VIEM_CHAIN_MAP, isKatanaChain } from '../../common/chains';
|
|
7
7
|
import { type Hex, parseGwei } from 'viem';
|
|
8
8
|
import type BigNumber from 'bignumber.js';
|
|
9
|
-
import { getTokenContractInfo } from '../../tokens/tokens';
|
|
9
|
+
import { getTokenContractInfo, isSTLBTCAbi } from '../../tokens/tokens';
|
|
10
10
|
import { Token } from '../../tokens/token-addresses';
|
|
11
11
|
import { estimateGasFees } from '../../utils/gas';
|
|
12
12
|
|
|
@@ -66,7 +66,7 @@ export async function redeemToken({
|
|
|
66
66
|
env,
|
|
67
67
|
token = Token.LBTC,
|
|
68
68
|
}: IUnstakeLBTCParams & { token?: Token }) {
|
|
69
|
-
if (![Token.LBTC, Token.BTCK].includes(token)) {
|
|
69
|
+
if (![Token.LBTC, Token.BTCK, Token.NativeLBTC].includes(token)) {
|
|
70
70
|
throw new Error('Unsupported token');
|
|
71
71
|
}
|
|
72
72
|
|
|
@@ -88,11 +88,13 @@ export async function redeemToken({
|
|
|
88
88
|
address: tokenContract.address,
|
|
89
89
|
account,
|
|
90
90
|
chain: CHAIN_ID_TO_VIEM_CHAIN_MAP[chainId],
|
|
91
|
-
functionName:
|
|
91
|
+
functionName:
|
|
92
|
+
isSTLBTCAbi(tokenContract.abi) || token === Token.NativeLBTC
|
|
93
|
+
? 'redeemForBtc'
|
|
94
|
+
: 'redeem', // FIXME: Change this to `redeemForBtc` once all contracts are updated.
|
|
92
95
|
args: [outputScript, BigInt(amountSat)],
|
|
93
96
|
} as const;
|
|
94
97
|
|
|
95
|
-
// Katana Tatara requires tip TODO: Recheck if this is needed or is it just OKX wallet issue
|
|
96
98
|
const gasEstimationData = isKatanaChain(chainId)
|
|
97
99
|
? await estimateGasFees(publicClient, callData, parseGwei('1'))
|
|
98
100
|
: {};
|
package/src/index.ts
CHANGED
|
@@ -19,7 +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
|
+
import { katana, katanaTatara, tac } from '../../../common/chains';
|
|
23
23
|
|
|
24
24
|
const config = createConfig({
|
|
25
25
|
chains: [
|
|
@@ -32,6 +32,7 @@ const config = createConfig({
|
|
|
32
32
|
morph,
|
|
33
33
|
sonic,
|
|
34
34
|
swellchain,
|
|
35
|
+
tac,
|
|
35
36
|
// Testnets:
|
|
36
37
|
baseSepolia,
|
|
37
38
|
berachainTestnetbArtio,
|
|
@@ -52,6 +53,7 @@ const config = createConfig({
|
|
|
52
53
|
[morph.id]: http(rpcUrlConfig[morph.id]),
|
|
53
54
|
[sonic.id]: http(rpcUrlConfig[sonic.id]),
|
|
54
55
|
[swellchain.id]: http(rpcUrlConfig[swellchain.id]),
|
|
56
|
+
[tac.id]: http(rpcUrlConfig[tac.id]),
|
|
55
57
|
// Testnets:
|
|
56
58
|
[baseSepolia.id]: http(rpcUrlConfig[baseSepolia.id]),
|
|
57
59
|
[berachainTestnetbArtio.id]: http(rpcUrlConfig[berachainTestnetbArtio.id]),
|