@lombard.finance/sdk-solana 1.2.2 → 2.0.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 +48 -15
- package/dist/index.cjs +1 -1
- package/dist/index.js +37 -31
- package/dist/index2.cjs +57 -54
- package/dist/index2.js +7608 -7206
- package/package.json +2 -2
- package/src/const/errors.ts +0 -4
- package/src/const/getConfig.ts +43 -20
- package/src/const/rpcUrls.ts +2 -2
- package/src/idl/asset_router.json +548 -179
- package/src/idl/consortium.json +24 -43
- package/src/idl/mailbox.json +118 -107
- package/src/index.ts +1 -3
- package/src/services/SolanaServiceImpl.test.ts +123 -0
- package/src/services/SolanaServiceImpl.ts +53 -17
- package/src/stories/components/OutputSelector/OutputSelector.tsx +1 -0
- package/src/types/errors.ts +2 -0
- package/src/utils/createDebugLogger.ts +6 -13
- package/src/utils/errors.ts +2 -0
- package/src/utils/tokenAccount.ts +3 -1
- package/src/utils/transactions.ts +1 -1
- package/src/web3Sdk/claimToken/claimBtcb.ts +37 -28
- package/src/web3Sdk/claimToken/claimLbtcGmp.ts +66 -8
- package/src/web3Sdk/claimToken/claimToken.stories.tsx +2 -2
- package/src/web3Sdk/claimToken/claimToken.ts +20 -16
- package/src/web3Sdk/claimToken/constants.ts +5 -0
- package/src/web3Sdk/claimToken/index.ts +1 -0
- package/src/web3Sdk/claimToken/shared.ts +88 -80
- package/src/web3Sdk/deposit/deposit.stories.tsx +240 -0
- package/src/web3Sdk/deposit/deposit.test.ts +327 -0
- package/src/web3Sdk/deposit/deposit.ts +339 -0
- package/src/web3Sdk/deposit/index.ts +1 -0
- package/src/web3Sdk/getTokenFeeConfig/getTokenFeeConfig.stories.tsx +166 -0
- package/src/web3Sdk/getTokenFeeConfig/getTokenFeeConfig.test.ts +224 -0
- package/src/web3Sdk/getTokenFeeConfig/getTokenFeeConfig.ts +154 -0
- package/src/web3Sdk/getTokenFeeConfig/index.ts +11 -0
- package/src/web3Sdk/index.ts +3 -4
- package/src/web3Sdk/redeem/index.ts +1 -0
- package/src/web3Sdk/redeem/redeem.stories.tsx +226 -0
- package/src/web3Sdk/redeem/redeem.test.ts +327 -0
- package/src/web3Sdk/redeem/redeem.ts +352 -0
- package/src/web3Sdk/redeemToken/redeemBtcb.ts +174 -0
- package/src/web3Sdk/redeemToken/redeemForBtc.stories.tsx +35 -21
- package/src/web3Sdk/redeemToken/redeemForBtc.test.ts +306 -0
- package/src/web3Sdk/redeemToken/redeemForBtc.ts +54 -215
- package/src/web3Sdk/redeemToken/redeemLbtc.ts +174 -0
- package/src/web3Sdk/redeemToken/shared.test.ts +45 -0
- package/src/web3Sdk/redeemToken/shared.ts +97 -0
- package/src/web3Sdk/claimLBTC/claimLBTC.stories.tsx +0 -189
- package/src/web3Sdk/claimLBTC/claimLBTC.ts +0 -225
- package/src/web3Sdk/claimLBTC/index.ts +0 -1
- package/src/web3Sdk/claimLBTC/utils/generateDepositId.ts +0 -75
- package/src/web3Sdk/claimLBTC/utils/index.ts +0 -2
- package/src/web3Sdk/claimLBTC/utils/parseTransactionLogs.ts +0 -44
- package/src/web3Sdk/claimLBTC/utils/payloadUtils.ts +0 -58
- package/src/web3Sdk/claimLBTC/utils/postMintSignatures.ts +0 -50
- package/src/web3Sdk/unstakeLBTC/index.ts +0 -1
- package/src/web3Sdk/unstakeLBTC/unstakeLBTC.stories.tsx +0 -141
- package/src/web3Sdk/unstakeLBTC/unstakeLBTC.ts +0 -140
- /package/src/web3Sdk/{claimLBTC → claimToken}/utils/__tests__/signatureUtils.test.ts +0 -0
- /package/src/web3Sdk/{claimLBTC → claimToken}/utils/signatureUtils.ts +0 -0
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { BN, Program } from '@coral-xyz/anchor';
|
|
2
|
-
import { getOutputScript } from '@lombard.finance/sdk-common';
|
|
3
|
-
import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
|
4
|
-
import { PublicKey } from '@solana/web3.js';
|
|
5
|
-
|
|
6
|
-
import { DEFAULT_ENV, getConfig, networkToEnv } from '../../const/getConfig';
|
|
7
|
-
import { getConnection } from '../../const/rpcUrls';
|
|
8
|
-
import { getLbtcIdl } from '../../idl/getLbtcIdl';
|
|
9
|
-
import { ISolanaWalletProvider, SolanaNetwork } from '../../types';
|
|
10
|
-
import {
|
|
11
|
-
ErrorCode,
|
|
12
|
-
sendAndConfirmTransaction,
|
|
13
|
-
SolanaSdkError,
|
|
14
|
-
} from '../../utils';
|
|
15
|
-
import { createOrGetAssociatedTokenAccount } from '../../utils/tokenAccount';
|
|
16
|
-
|
|
17
|
-
export interface UnstakeLBTCParams {
|
|
18
|
-
/**
|
|
19
|
-
* Amount of LBTC to unstake in base units
|
|
20
|
-
*/
|
|
21
|
-
amount: string;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Bitcoin address where BTC should be sent after unstaking
|
|
25
|
-
*/
|
|
26
|
-
btcAddress: string;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Network to use
|
|
30
|
-
*/
|
|
31
|
-
network: SolanaNetwork;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Optional RPC endpoint to use
|
|
35
|
-
*/
|
|
36
|
-
rpcUrl?: string;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Unstake LBTC to receive BTC at the specified Bitcoin address
|
|
41
|
-
* @param provider - Solana wallet provider
|
|
42
|
-
* @param params - Parameters for unstaking LBTC
|
|
43
|
-
* @returns Transaction signature
|
|
44
|
-
*/
|
|
45
|
-
export async function unstakeLBTC(
|
|
46
|
-
provider: ISolanaWalletProvider,
|
|
47
|
-
params: UnstakeLBTCParams,
|
|
48
|
-
): Promise<string> {
|
|
49
|
-
try {
|
|
50
|
-
const { amount, btcAddress, network, rpcUrl } = params;
|
|
51
|
-
const env = networkToEnv[network] || DEFAULT_ENV;
|
|
52
|
-
const { treasuryAddress, lbtcTokenMint } = getConfig(env);
|
|
53
|
-
const connection = getConnection(network, rpcUrl);
|
|
54
|
-
|
|
55
|
-
// Validate provider has a connected wallet
|
|
56
|
-
if (!provider.publicKey) {
|
|
57
|
-
throw SolanaSdkError.wrap(
|
|
58
|
-
new Error('Wallet not connected'),
|
|
59
|
-
ErrorCode.UNSTAKE_REJECTED,
|
|
60
|
-
'Please connect your Solana wallet and ensure it is on the correct network.',
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Create a program instance
|
|
65
|
-
const programIdl = getLbtcIdl(network);
|
|
66
|
-
const program = new Program(programIdl, {
|
|
67
|
-
connection,
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
const scriptPubKey = Buffer.from(
|
|
71
|
-
(await getOutputScript(btcAddress, env)).replace(/^0x/, ''),
|
|
72
|
-
'hex',
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
const mint = new PublicKey(lbtcTokenMint);
|
|
76
|
-
|
|
77
|
-
const [configPDA] = PublicKey.findProgramAddressSync(
|
|
78
|
-
[Buffer.from('lbtc_config')],
|
|
79
|
-
new PublicKey(program.programId),
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
// Pre-flight check: verify config account exists
|
|
83
|
-
const configAccount = await connection.getAccountInfo(configPDA);
|
|
84
|
-
if (!configAccount) {
|
|
85
|
-
throw SolanaSdkError.wrap(
|
|
86
|
-
new Error(`LBTC program config not found on ${network}`),
|
|
87
|
-
ErrorCode.UNSTAKE_REJECTED,
|
|
88
|
-
`LBTC unstaking is not available on ${network}. The program may not be deployed or configured.`,
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const userTA = await createOrGetAssociatedTokenAccount({
|
|
93
|
-
provider,
|
|
94
|
-
connection,
|
|
95
|
-
ownerAddress: provider.publicKey.toBase58(),
|
|
96
|
-
mintAddress: mint.toBase58(),
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
// Pre-flight check: verify user has LBTC balance
|
|
100
|
-
const tokenBalance = await connection.getTokenAccountBalance(
|
|
101
|
-
new PublicKey(userTA),
|
|
102
|
-
);
|
|
103
|
-
const userBalance = BigInt(tokenBalance.value.amount);
|
|
104
|
-
const requestedAmount = BigInt(amount);
|
|
105
|
-
if (userBalance < requestedAmount) {
|
|
106
|
-
throw SolanaSdkError.wrap(
|
|
107
|
-
new Error('Insufficient LBTC balance'),
|
|
108
|
-
ErrorCode.UNSTAKE_REJECTED,
|
|
109
|
-
`Insufficient LBTC balance. You have ${tokenBalance.value.uiAmountString} LBTC but requested to unstake ${Number(amount) / 1e8} LBTC.`,
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const tx = await program.methods
|
|
114
|
-
.redeem(scriptPubKey, new BN(amount))
|
|
115
|
-
.accounts({
|
|
116
|
-
payer: provider.publicKey,
|
|
117
|
-
holder: userTA,
|
|
118
|
-
config: configPDA,
|
|
119
|
-
tokenProgram: TOKEN_PROGRAM_ID,
|
|
120
|
-
mint,
|
|
121
|
-
treasury: treasuryAddress,
|
|
122
|
-
})
|
|
123
|
-
.transaction();
|
|
124
|
-
|
|
125
|
-
const { signature } = await sendAndConfirmTransaction({
|
|
126
|
-
instruction: tx,
|
|
127
|
-
connection,
|
|
128
|
-
provider,
|
|
129
|
-
debugLabel: 'Unstake LBTC',
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
return signature;
|
|
133
|
-
} catch (error: unknown) {
|
|
134
|
-
throw SolanaSdkError.wrap(
|
|
135
|
-
error,
|
|
136
|
-
ErrorCode.UNSTAKE_REJECTED,
|
|
137
|
-
'LBTC unstake operation failed',
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
File without changes
|
|
File without changes
|