@lombard.finance/sdk-solana 2.0.1 → 2.0.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.
- package/dist/index.cjs +1 -1
- package/dist/index.js +23 -22
- package/dist/index2.cjs +47 -47
- package/dist/index2.js +6103 -6029
- package/dist/sendBridgeTransaction.cjs +1 -1
- package/dist/sendBridgeTransaction.js +19 -19
- package/package.json +1 -1
- package/src/bridge/sendBridgeTransaction.ts +2 -2
- package/src/const/__tests__/rpcUrls.test.ts +73 -0
- package/src/const/errors.ts +0 -1
- package/src/const/getConfig.ts +30 -15
- package/src/const/rpcUrls.ts +53 -7
- package/src/idl/asset_router.json +182 -1532
- package/src/idl/bridge.json +139 -1185
- package/src/idl/consortium.json +62 -498
- package/src/idl/getAssetRouterIdl.ts +1 -3
- package/src/idl/getConsortiumIdl.ts +1 -3
- package/src/idl/getLbtcIdl.ts +4 -1
- package/src/idl/getMailboxIdl.ts +1 -3
- package/src/idl/lombard_token_pool.json +92 -932
- package/src/idl/mailbox.json +114 -1018
- package/src/idl/ratio_oracle.json +35 -332
- package/src/services/SolanaServiceImpl.test.ts +5 -4
- package/src/stories/components/ConnectButton/ConnectButton.tsx +2 -2
- package/src/stories/components/NetworkSelector/NetworkSelector.tsx +1 -1
- package/src/stories/components/OutputSelector/OutputSelector.tsx +4 -4
- package/src/stories/components/SelectField/SelectField.tsx +2 -3
- package/src/stories/hooks/useFetchOutputs.ts +1 -1
- package/src/stories/utils/fromCamelCase.ts +1 -1
- package/src/types/sdkTypes.ts +7 -0
- package/src/utils/createDebugLogger.ts +1 -1
- package/src/web3Sdk/claimToken/claimBtcb.ts +19 -5
- package/src/web3Sdk/claimToken/claimLbtcGmp.ts +55 -25
- package/src/web3Sdk/claimToken/claimToken.stories.tsx +4 -3
- package/src/web3Sdk/claimToken/claimToken.ts +16 -6
- package/src/web3Sdk/claimToken/shared.ts +18 -12
- package/src/web3Sdk/claimToken/utils/__tests__/signatureUtils.test.ts +10 -4
- package/src/web3Sdk/claimToken/utils/signatureUtils.ts +3 -1
- package/src/web3Sdk/deposit/deposit.stories.tsx +1 -4
- package/src/web3Sdk/deposit/deposit.test.ts +67 -37
- package/src/web3Sdk/deposit/deposit.ts +14 -14
- package/src/web3Sdk/detectWallet/detectWallet.test.ts +2 -2
- package/src/web3Sdk/getBalance/getBalance.test.ts +1 -1
- package/src/web3Sdk/getBalance/getBalance.ts +2 -1
- package/src/web3Sdk/getTokenFeeConfig/getTokenFeeConfig.stories.tsx +8 -18
- package/src/web3Sdk/getTokenFeeConfig/getTokenFeeConfig.ts +2 -4
- package/src/web3Sdk/redeem/redeem.stories.tsx +17 -8
- package/src/web3Sdk/redeem/redeem.test.ts +45 -13
- package/src/web3Sdk/redeem/redeem.ts +46 -20
- package/src/web3Sdk/redeemToken/redeemBtcb.ts +28 -12
- package/src/web3Sdk/redeemToken/redeemForBtc.stories.tsx +6 -6
- package/src/web3Sdk/redeemToken/redeemForBtc.test.ts +43 -13
- package/src/web3Sdk/redeemToken/redeemForBtc.ts +27 -14
- package/src/web3Sdk/redeemToken/redeemLbtc.ts +28 -12
- package/src/web3Sdk/redeemToken/shared.test.ts +6 -2
- package/src/web3Sdk/redeemToken/shared.ts +1 -3
|
@@ -6,10 +6,7 @@ import { DEFAULT_ENV, getConfig, networkToEnv } from '../../const/getConfig';
|
|
|
6
6
|
import { getConnection } from '../../const/rpcUrls';
|
|
7
7
|
import { getAssetRouterIdl } from '../../idl/getAssetRouterIdl';
|
|
8
8
|
import { ISolanaWalletProvider } from '../../types';
|
|
9
|
-
import {
|
|
10
|
-
ErrorCode,
|
|
11
|
-
SolanaSdkError,
|
|
12
|
-
} from '../../utils';
|
|
9
|
+
import { ErrorCode, SolanaSdkError } from '../../utils';
|
|
13
10
|
import { createDebugLogger } from '../../utils/createDebugLogger';
|
|
14
11
|
import { getTokenProgramForMint } from '../../utils/tokenAccount';
|
|
15
12
|
import { redeemBtcbForBtc } from './redeemBtcb';
|
|
@@ -29,7 +26,14 @@ export async function redeemForBtc(
|
|
|
29
26
|
provider: ISolanaWalletProvider,
|
|
30
27
|
params: RedeemForBtcParams,
|
|
31
28
|
): Promise<string> {
|
|
32
|
-
const {
|
|
29
|
+
const {
|
|
30
|
+
amount,
|
|
31
|
+
btcAddress,
|
|
32
|
+
network,
|
|
33
|
+
env: envOverride,
|
|
34
|
+
rpcUrl,
|
|
35
|
+
debug = false,
|
|
36
|
+
} = params;
|
|
33
37
|
const { debugLog, printLogs } = createDebugLogger({ debug });
|
|
34
38
|
|
|
35
39
|
try {
|
|
@@ -47,10 +51,14 @@ export async function redeemForBtc(
|
|
|
47
51
|
throw new Error(`Mailbox not configured for network: ${network}`);
|
|
48
52
|
}
|
|
49
53
|
if (!config.solanaRoutingChainId) {
|
|
50
|
-
throw new Error(
|
|
54
|
+
throw new Error(
|
|
55
|
+
`Solana routing chain ID not configured for network: ${network}`,
|
|
56
|
+
);
|
|
51
57
|
}
|
|
52
58
|
if (!config.bitcoinRoutingChainId) {
|
|
53
|
-
throw new Error(
|
|
59
|
+
throw new Error(
|
|
60
|
+
`Bitcoin routing chain ID not configured for network: ${network}`,
|
|
61
|
+
);
|
|
54
62
|
}
|
|
55
63
|
|
|
56
64
|
const mintAddress = params.tokenMint;
|
|
@@ -65,13 +73,19 @@ export async function redeemForBtc(
|
|
|
65
73
|
|
|
66
74
|
validateAmount(amount);
|
|
67
75
|
|
|
68
|
-
const connection = getConnection(network, rpcUrl);
|
|
76
|
+
const connection = getConnection(network, rpcUrl, env);
|
|
69
77
|
const payer = new PublicKey(provider.publicKey);
|
|
70
78
|
const mint = new PublicKey(mintAddress);
|
|
71
79
|
const assetRouterProgramId = new PublicKey(config.assetRouter);
|
|
72
80
|
const mailboxProgramId = new PublicKey(config.mailbox);
|
|
73
|
-
const solanaRoutingChainId = Buffer.from(
|
|
74
|
-
|
|
81
|
+
const solanaRoutingChainId = Buffer.from(
|
|
82
|
+
config.solanaRoutingChainId,
|
|
83
|
+
'hex',
|
|
84
|
+
);
|
|
85
|
+
const bitcoinRoutingChainId = Buffer.from(
|
|
86
|
+
config.bitcoinRoutingChainId,
|
|
87
|
+
'hex',
|
|
88
|
+
);
|
|
75
89
|
|
|
76
90
|
debugLog('Payer:', payer.toBase58());
|
|
77
91
|
debugLog('Mint:', mint.toBase58());
|
|
@@ -143,10 +157,9 @@ export async function redeemForBtc(
|
|
|
143
157
|
);
|
|
144
158
|
debugLog('Mailbox treasury:', mailboxTreasury.toBase58());
|
|
145
159
|
|
|
146
|
-
const assetRouterProgram = new Program(
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
);
|
|
160
|
+
const assetRouterProgram = new Program(getAssetRouterIdl(env), {
|
|
161
|
+
connection,
|
|
162
|
+
});
|
|
150
163
|
|
|
151
164
|
const ctx: RedeemContext = {
|
|
152
165
|
provider,
|
|
@@ -16,12 +16,23 @@ import { BTC_NATIVE_TOKEN_ADDRESS, RedeemContext } from './shared';
|
|
|
16
16
|
*/
|
|
17
17
|
export async function redeemLbtcForBtc(ctx: RedeemContext): Promise<string> {
|
|
18
18
|
const {
|
|
19
|
-
provider,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
provider,
|
|
20
|
+
params,
|
|
21
|
+
config,
|
|
22
|
+
connection,
|
|
23
|
+
payer,
|
|
24
|
+
mint,
|
|
25
|
+
tokenProgramId,
|
|
26
|
+
scriptPubKey,
|
|
27
|
+
assetRouterProgramId,
|
|
28
|
+
mailboxProgramId,
|
|
29
|
+
solanaRoutingChainId,
|
|
30
|
+
bitcoinRoutingChainId,
|
|
31
|
+
assetRouterProgram,
|
|
32
|
+
assetRouterConfigPDA,
|
|
33
|
+
mailboxConfigPDA,
|
|
34
|
+
arTreasury,
|
|
35
|
+
mailboxTreasury,
|
|
25
36
|
debugLog,
|
|
26
37
|
} = ctx;
|
|
27
38
|
|
|
@@ -53,7 +64,9 @@ export async function redeemLbtcForBtc(ctx: RedeemContext): Promise<string> {
|
|
|
53
64
|
|
|
54
65
|
// ── Mailbox PDAs ──
|
|
55
66
|
if (!config.ledgerChainId) {
|
|
56
|
-
throw new Error(
|
|
67
|
+
throw new Error(
|
|
68
|
+
`Ledger chain ID not configured for network: ${params.network}`,
|
|
69
|
+
);
|
|
57
70
|
}
|
|
58
71
|
const ledgerChainId = Buffer.from(config.ledgerChainId, 'hex');
|
|
59
72
|
const [outboundMessagePathPDA] = PublicKey.findProgramAddressSync(
|
|
@@ -88,7 +101,8 @@ export async function redeemLbtcForBtc(ctx: RedeemContext): Promise<string> {
|
|
|
88
101
|
debugLog('Treasury token account:', treasuryTokenAccount.toBase58());
|
|
89
102
|
|
|
90
103
|
// ── Balance check ──
|
|
91
|
-
const tokenBalance =
|
|
104
|
+
const tokenBalance =
|
|
105
|
+
await connection.getTokenAccountBalance(payerTokenAccount);
|
|
92
106
|
const userBalance = BigInt(tokenBalance.value.amount);
|
|
93
107
|
const parsedAmount = BigInt(amount);
|
|
94
108
|
if (userBalance < parsedAmount) {
|
|
@@ -102,7 +116,8 @@ export async function redeemLbtcForBtc(ctx: RedeemContext): Promise<string> {
|
|
|
102
116
|
// reads. Retry up to 3 times if the nonce becomes stale.
|
|
103
117
|
const MAX_NONCE_RETRIES = 3;
|
|
104
118
|
for (let attempt = 0; attempt < MAX_NONCE_RETRIES; attempt++) {
|
|
105
|
-
const freshMailboxConfig =
|
|
119
|
+
const freshMailboxConfig =
|
|
120
|
+
await connection.getAccountInfo(mailboxConfigPDA);
|
|
106
121
|
if (!freshMailboxConfig) {
|
|
107
122
|
throw new Error('Mailbox config account not found');
|
|
108
123
|
}
|
|
@@ -121,7 +136,9 @@ export async function redeemLbtcForBtc(ctx: RedeemContext): Promise<string> {
|
|
|
121
136
|
mailboxProgramId,
|
|
122
137
|
);
|
|
123
138
|
|
|
124
|
-
debugLog(
|
|
139
|
+
debugLog(
|
|
140
|
+
`Attempt ${attempt + 1}: global nonce=${globalNonce}, outbound_message=${outboundMessagePDA.toBase58()}`,
|
|
141
|
+
);
|
|
125
142
|
|
|
126
143
|
const tx = await assetRouterProgram.methods
|
|
127
144
|
.redeemForBtc(scriptPubKey, new BN(amount))
|
|
@@ -160,8 +177,7 @@ export async function redeemLbtcForBtc(ctx: RedeemContext): Promise<string> {
|
|
|
160
177
|
return signature;
|
|
161
178
|
} catch (err: unknown) {
|
|
162
179
|
const isNonceError =
|
|
163
|
-
err instanceof Error &&
|
|
164
|
-
err.message.includes('0x7d6'); // ConstraintSeeds
|
|
180
|
+
err instanceof Error && err.message.includes('0x7d6'); // ConstraintSeeds
|
|
165
181
|
if (isNonceError && attempt < MAX_NONCE_RETRIES - 1) {
|
|
166
182
|
debugLog(`Nonce stale (ConstraintSeeds), retrying...`);
|
|
167
183
|
continue;
|
|
@@ -22,8 +22,12 @@ describe('validateAmount', () => {
|
|
|
22
22
|
});
|
|
23
23
|
|
|
24
24
|
it('should reject amounts exceeding u64 max', () => {
|
|
25
|
-
expect(() => validateAmount('18446744073709551616')).toThrow(
|
|
26
|
-
|
|
25
|
+
expect(() => validateAmount('18446744073709551616')).toThrow(
|
|
26
|
+
'exceeds the u64 maximum',
|
|
27
|
+
);
|
|
28
|
+
expect(() => validateAmount('99999999999999999999999')).toThrow(
|
|
29
|
+
'exceeds the u64 maximum',
|
|
30
|
+
);
|
|
27
31
|
});
|
|
28
32
|
});
|
|
29
33
|
|
|
@@ -90,8 +90,6 @@ export function validateAmount(amount: string): void {
|
|
|
90
90
|
throw new Error('Amount must be greater than zero');
|
|
91
91
|
}
|
|
92
92
|
if (parsedAmount > U64_MAX) {
|
|
93
|
-
throw new Error(
|
|
94
|
-
`Amount ${amount} exceeds the u64 maximum (${U64_MAX})`,
|
|
95
|
-
);
|
|
93
|
+
throw new Error(`Amount ${amount} exceeds the u64 maximum (${U64_MAX})`);
|
|
96
94
|
}
|
|
97
95
|
}
|