@lombard.finance/sdk 2.5.2 → 3.2.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 +483 -396
- package/dist/ccip.cjs +2 -0
- package/dist/ccip.cjs.map +1 -0
- package/dist/ccip.js +147 -0
- package/dist/ccip.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +79 -8269
- package/dist/index.js.map +1 -1
- package/dist/index2.cjs +63 -0
- package/dist/index2.cjs.map +1 -0
- package/dist/index2.js +17989 -0
- package/dist/index2.js.map +1 -0
- package/package.json +10 -10
- package/src/{sdk → api-functions}/generateDepositBtcAddress/generateDepositBtcAddress.stories.tsx +15 -14
- package/src/{sdk → api-functions}/generateDepositBtcAddress/generateDepositBtcAddress.ts +18 -8
- package/src/{sdk → api-functions}/getDepositBtcAddress/getDepositBtcAddress.stories.tsx +23 -14
- package/src/{sdk → api-functions}/getDepositBtcAddress/getDepositBtcAddress.ts +16 -7
- package/src/{sdk → api-functions}/getDepositBtcAddress/getDepositBtcAddresses.stories.tsx +15 -14
- package/src/{sdk → api-functions}/getDepositsByAddress/getDepositsByAddress.stories.tsx +13 -12
- package/src/{sdk → api-functions}/getDepositsByAddress/getDepositsByAddress.ts +9 -9
- package/src/{sdk → api-functions}/getLBTCExchangeRate/getLBTCExchangeRate.stories.tsx +16 -10
- package/src/api-functions/getLBTCExchangeRate/getLBTCExchangeRate.ts +71 -0
- package/src/api-functions/getNetworkFeeSignature/getNetworkFeeSignature.stories.tsx +56 -0
- package/src/{sdk → api-functions}/getNetworkFeeSignature/getNetworkFeeSignature.ts +11 -5
- package/src/{sdk → api-functions}/getPointsByAddress/getPointsByAddress.stories.tsx +14 -13
- package/src/{sdk → api-functions}/getPointsByAddress/getPointsByAddress.ts +7 -4
- package/src/{sdk → api-functions}/getUnstakesByAddress/getUnstakesByAddress.stories.tsx +14 -13
- package/src/{sdk → api-functions}/getUnstakesByAddress/getUnstakesByAddress.ts +15 -10
- package/src/api-functions/getUserStakeAndBakeSignature/getUserStakeAndBakeSignature.stories.tsx +69 -0
- package/src/{sdk → api-functions}/getUserStakeAndBakeSignature/getUserStakeAndBakeSignature.ts +10 -6
- package/src/{sdk → api-functions}/index.ts +0 -3
- package/src/{sdk → api-functions}/setReferral/setReferral.ts +3 -3
- package/src/api-functions/storeNetworkFeeSignature/storeNetworkFeeSignature.stories.tsx +56 -0
- package/src/{sdk → api-functions}/storeNetworkFeeSignature/storeNetworkFeeSignature.ts +9 -7
- package/src/api-functions/storeStakeAndBakeSignature/storeStakeAndBakeSignature.stories.tsx +56 -0
- package/src/{sdk → api-functions}/storeStakeAndBakeSignature/storeStakeAndBakeSignature.ts +8 -6
- 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 +212 -0
- package/src/clients/public-client.ts +32 -0
- package/src/clients/rpc-url-config.ts +20 -0
- package/src/clients/wallet-client.ts +33 -0
- package/src/{sdk/apiConfig.ts → common/api-config.ts} +9 -3
- package/src/common/blockchain-identifier.ts +134 -0
- package/src/common/chains.ts +84 -0
- package/src/common/contract-info.ts +8 -0
- package/src/common/parameters.ts +51 -0
- package/src/contract-functions/approveLBTC/approveLBTC.stories.tsx +76 -0
- package/src/contract-functions/approveLBTC/approveLBTC.ts +65 -0
- package/src/{web3Sdk → contract-functions}/claimLBTC/claimLBTC.stories.tsx +22 -30
- package/src/contract-functions/claimLBTC/claimLBTC.ts +90 -0
- package/src/contract-functions/getBasculeDepositStatus/getBasculeDepositStatus.stories.tsx +50 -0
- package/src/contract-functions/getBasculeDepositStatus/getBasculeDepositStatus.ts +127 -0
- package/src/{web3Sdk → contract-functions}/getLBTCMintingFee/getLBTCMintingFee.stories.tsx +15 -11
- package/src/contract-functions/getLBTCMintingFee/getLBTCMintingFee.tsx +37 -0
- package/src/{vaults/lib/get-vault-points.stories.tsx → contract-functions/getLBTCTotalSupply/getLBTCTotalSupply.stories.tsx} +13 -16
- package/src/contract-functions/getLBTCTotalSupply/getLBTCTotalSupply.ts +34 -0
- package/src/{web3Sdk → contract-functions}/getPermitNonce/getPermitNonce.stories.tsx +12 -22
- package/src/contract-functions/getPermitNonce/getPermitNonce.ts +45 -0
- package/src/{web3Sdk → contract-functions}/getShareValue/getShareValue.stories.tsx +12 -7
- package/src/contract-functions/getShareValue/getShareValue.ts +58 -0
- package/src/{web3Sdk → contract-functions}/getSharesByAddress/getSharesByAddress.stories.tsx +14 -9
- package/src/{web3Sdk → contract-functions}/getSharesByAddress/getSharesByAddress.ts +29 -28
- package/src/{web3Sdk → contract-functions}/getStakeAndBakeFee/getStakeAndBakeFee.stories.tsx +29 -16
- package/src/contract-functions/getStakeAndBakeFee/getStakeAndBakeFee.tsx +65 -0
- package/src/{web3Sdk → contract-functions}/index.ts +8 -7
- package/src/contract-functions/signLbtcDestionationAddr/signLbtcDestinationAddr.ts +32 -0
- package/src/contract-functions/signLbtcDestionationAddr/signLbtcDestionationAddr.stories.tsx +63 -0
- package/src/contract-functions/signNetworkFee/signNetworkFee.stories.tsx +91 -0
- package/src/contract-functions/signNetworkFee/signNetworkFee.ts +99 -0
- package/src/contract-functions/signStakeAndBake/index.ts +1 -0
- package/src/{web3Sdk → contract-functions}/signStakeAndBake/signStakeAndBake.stories.tsx +29 -41
- package/src/contract-functions/signStakeAndBake/signStakeAndBake.ts +145 -0
- package/src/contract-functions/unstakeLBTC/unstakeLBTC.stories.tsx +80 -0
- package/src/contract-functions/unstakeLBTC/unstakeLBTC.ts +66 -0
- package/src/index.ts +40 -17
- package/src/metrics/get-lbtc-stats.stories.tsx +51 -0
- package/src/metrics/get-lbtc-stats.ts +38 -0
- package/src/rewards/index.ts +26 -0
- package/src/rewards/lib/claim-reward.stories.tsx +82 -0
- package/src/rewards/lib/claim-reward.ts +84 -0
- package/src/rewards/lib/get-reward-balances.stories.tsx +64 -0
- package/src/rewards/lib/get-reward-balances.ts +81 -0
- package/src/rewards/lib/get-reward-signing-data.stories.tsx +76 -0
- package/src/rewards/lib/get-reward-signing-data.ts +52 -0
- package/src/rewards/lib/get-reward-withdrawal-fee.stories.tsx +61 -0
- package/src/rewards/lib/get-reward-withdrawal-fee.ts +37 -0
- package/src/rewards/lib/get-reward-withdrawals.stories.tsx +60 -0
- package/src/rewards/lib/get-reward-withdrawals.ts +92 -0
- package/src/rewards/lib/reward-tokens.ts +7 -0
- package/src/stories/components/Button/Button.css +10 -0
- package/src/stories/components/Button/Button.tsx +15 -4
- package/src/stories/components/CodeBlock/CodeBlock.tsx +1 -0
- package/src/stories/components/ConnectButton/connect-button.tsx +100 -0
- package/src/stories/components/ConnectButton/index.ts +1 -0
- package/src/stories/components/decorators/function-type.tsx +63 -0
- package/src/stories/components/decorators/index.ts +2 -0
- package/src/stories/components/decorators/wagmi-decorator.tsx +79 -0
- package/src/stories/components/error-block.tsx +21 -0
- package/src/stories/constants.ts +3 -0
- package/src/stories/hooks/useConnection.ts +72 -0
- package/src/stories/hooks/useQuery.ts +2 -2
- package/src/{web3Sdk/abi/LBTC.json → tokens/abi/LBTC_ABI.json} +1 -1
- package/src/tokens/abi/LBTC_ABI.ts +1761 -0
- package/src/tokens/abi/LBTC_BASCULE_ABI.json +850 -0
- package/src/tokens/lbtc-addresses.ts +55 -0
- package/src/tokens/token-addresses.ts +32 -0
- package/src/tokens/tokens.ts +120 -0
- package/src/utils/env.ts +12 -0
- package/src/utils/hex.ts +2 -2
- package/src/utils/numbers.ts +8 -0
- package/src/{common/utils/convertSatoshi.ts → utils/satoshi.ts} +3 -3
- package/src/utils/time.ts +12 -0
- package/src/vaults/abi/VEDA_VAULT_BASE_ASSET_ABI.json +296 -0
- package/src/vaults/abi/VEDA_VAULT_BORING_WITHDRAW_QUEUE_ABI.json +502 -0
- package/src/vaults/abi/VEDA_VAULT_SPENDER_ABI.json +408 -0
- package/src/vaults/abi/VEDA_VAULT_TELLER_ABI.json +700 -0
- package/src/vaults/index.ts +36 -69
- 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/metrics/get-vault-points.stories.tsx +59 -0
- package/src/vaults/lib/{get-vault-points.ts → metrics/get-vault-points.ts} +14 -10
- 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/ops/cancel-withdraw.stories.tsx +79 -0
- package/src/vaults/lib/ops/deposit.stories.tsx +81 -0
- package/src/vaults/lib/ops/deposit.ts +151 -0
- package/src/vaults/lib/{get-vault-deposits.stories.tsx → ops/get-vault-deposits.stories.tsx} +20 -14
- package/src/vaults/lib/{get-vault-deposits.ts → ops/get-vault-deposits.ts} +45 -22
- package/src/vaults/lib/{get-vault-withdrawals.stories.tsx → ops/get-vault-withdrawals.stories.tsx} +20 -13
- package/src/vaults/lib/{get-vault-withdrawals.ts → ops/get-vault-withdrawals.ts} +72 -38
- package/src/vaults/lib/ops/withdraw.stories.tsx +81 -0
- package/src/vaults/lib/ops/withdraw.ts +224 -0
- package/src/common/const.ts +0 -5
- package/src/common/types/internalTypes.ts +0 -10
- package/src/common/types/types.ts +0 -57
- package/src/common/utils/isValidChain.ts +0 -5
- package/src/provider/Provider.ts +0 -171
- package/src/provider/ReadProvider.ts +0 -126
- package/src/provider/index.ts +0 -2
- package/src/provider/rpcUrlConfig.ts +0 -19
- package/src/provider/types.ts +0 -58
- package/src/provider/utils/getMaxPriorityFeePerGas.ts +0 -25
- package/src/sdk/getLBTCExchangeRate/getLBTCExchangeRate.ts +0 -65
- package/src/sdk/getNetworkFeeSignature/getNetworkFeeSignature.stories.tsx +0 -85
- package/src/sdk/getUserStakeAndBakeSignature/getUserStakeAndBakeSignature.stories.tsx +0 -86
- package/src/sdk/internalTypes.ts +0 -18
- package/src/sdk/storeNetworkFeeSignature/storeNetworkFeeSignature.stories.tsx +0 -86
- package/src/sdk/storeStakeAndBakeSignature/storeStakeAndBakeSignature.stories.tsx +0 -116
- package/src/sdk/utils/getChainIdByName.ts +0 -48
- package/src/sdk/utils/getChainNameById.ts +0 -41
- package/src/stories/const.ts +0 -1
- package/src/stories/hooks/useConnect.ts +0 -47
- package/src/stories/utils/connectInjectedWallet.ts +0 -12
- package/src/stories/utils/fromCamelCase.ts +0 -16
- package/src/stories/utils/getMetaTitle.ts +0 -7
- package/src/stories/utils/getWalletInfo.ts +0 -31
- package/src/web3Sdk/abi/BASCULE.json +0 -850
- package/src/web3Sdk/abi/IERC20.json +0 -222
- package/src/web3Sdk/abi/STAKE_AND_BAKE.json +0 -15
- package/src/web3Sdk/abi/index.ts +0 -6
- package/src/web3Sdk/approveLBTC/approveLBTC.stories.tsx +0 -77
- package/src/web3Sdk/approveLBTC/approveLBTC.ts +0 -48
- package/src/web3Sdk/claimLBTC/claimLBTC.ts +0 -86
- package/src/web3Sdk/const.ts +0 -2
- package/src/web3Sdk/getBasculeDepositStatus/getBasculeDepositStatus.stories.tsx +0 -89
- package/src/web3Sdk/getBasculeDepositStatus/getBasculeDepositStatus.ts +0 -75
- package/src/web3Sdk/getBasculeDepositStatus/utils/const.ts +0 -8
- package/src/web3Sdk/getBasculeDepositStatus/utils/throwBasculeDepositStatusError.ts +0 -21
- package/src/web3Sdk/getLBTCMintingFee/getLBTCMintingFee.tsx +0 -41
- package/src/web3Sdk/getLBTCTotalSupply/getLBTCTotalSupply.stories.tsx +0 -60
- package/src/web3Sdk/getLBTCTotalSupply/getLBTCTotalSupply.ts +0 -26
- package/src/web3Sdk/getPermitNonce/getPermitNonce.ts +0 -47
- package/src/web3Sdk/getShareValue/getShareValue.ts +0 -58
- package/src/web3Sdk/getStakeAndBakeFee/getStakeAndBakeFee.tsx +0 -48
- package/src/web3Sdk/lbtcAddressConfig.ts +0 -96
- package/src/web3Sdk/signLbtcDestionationAddr/signLbtcDestinationAddr.ts +0 -23
- package/src/web3Sdk/signLbtcDestionationAddr/signLbtcDestionationAddr.stories.tsx +0 -97
- package/src/web3Sdk/signNetworkFee/signNetworkFee.stories.tsx +0 -91
- package/src/web3Sdk/signNetworkFee/signNetworkFee.ts +0 -92
- package/src/web3Sdk/signStakeAndBake/contracts.ts +0 -80
- package/src/web3Sdk/signStakeAndBake/getTypedData.ts +0 -78
- package/src/web3Sdk/signStakeAndBake/index.ts +0 -3
- package/src/web3Sdk/signStakeAndBake/signStakeAndBake.ts +0 -105
- package/src/web3Sdk/signStakeAndBake/utils.ts +0 -23
- package/src/web3Sdk/types.ts +0 -16
- package/src/web3Sdk/unstakeLBTC/unstakeLBTC.stories.tsx +0 -77
- package/src/web3Sdk/unstakeLBTC/unstakeLBTC.ts +0 -51
- package/src/web3Sdk/utils/chainIdToEnv.ts +0 -12
- package/src/web3Sdk/utils/getBasculeTokenContract.ts +0 -21
- package/src/web3Sdk/utils/getGasMultiplier.ts +0 -20
- package/src/web3Sdk/utils/getLbtcTokenContract.ts +0 -36
- package/src/web3Sdk/utils/getRpcUrlConfigFromChain.ts +0 -34
- package/src/web3Sdk/utils/getTokenABI.ts +0 -12
- /package/src/{sdk → api-functions}/generateDepositBtcAddress/index.ts +0 -0
- /package/src/{sdk → api-functions}/getDepositBtcAddress/index.ts +0 -0
- /package/src/{sdk → api-functions}/getDepositsByAddress/index.ts +0 -0
- /package/src/{sdk → api-functions}/getLBTCExchangeRate/index.ts +0 -0
- /package/src/{sdk → api-functions}/getNetworkFeeSignature/index.ts +0 -0
- /package/src/{sdk → api-functions}/getPointsByAddress/index.ts +0 -0
- /package/src/{sdk → api-functions}/getUnstakesByAddress/index.ts +0 -0
- /package/src/{sdk → api-functions}/getUserStakeAndBakeSignature/index.ts +0 -0
- /package/src/{sdk → api-functions}/setReferral/index.ts +0 -0
- /package/src/{sdk → api-functions}/storeNetworkFeeSignature/index.ts +0 -0
- /package/src/{sdk → api-functions}/storeStakeAndBakeSignature/index.ts +0 -0
- /package/src/{sdk/const.ts → common/constants.ts} +0 -0
- /package/src/{web3Sdk → contract-functions}/approveLBTC/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/claimLBTC/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/getBasculeDepositStatus/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/getLBTCMintingFee/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/getLBTCTotalSupply/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/getPermitNonce/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/getShareValue/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/getSharesByAddress/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/getStakeAndBakeFee/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/signLbtcDestionationAddr/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/signNetworkFee/getTypedData.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/signNetworkFee/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/unstakeLBTC/index.ts +0 -0
- /package/src/{common/utils/getErrorMessage.ts → utils/err.ts} +0 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { makeWalletClient } from '../../clients/wallet-client';
|
|
2
|
+
import { CommonWriteParameters } from '../../common/parameters';
|
|
3
|
+
import {
|
|
4
|
+
isVedaVaultStakeAndBakeChain,
|
|
5
|
+
Vault,
|
|
6
|
+
VAULTS,
|
|
7
|
+
} from '../../vaults/lib/config';
|
|
8
|
+
import { getPermitNonce } from '../getPermitNonce/getPermitNonce';
|
|
9
|
+
import BigNumber from 'bignumber.js';
|
|
10
|
+
import { DAY, now, toUnix } from '../../utils/time';
|
|
11
|
+
import { getTokenContractInfo } from '../../tokens/tokens';
|
|
12
|
+
import { Token } from '../../tokens/token-addresses';
|
|
13
|
+
|
|
14
|
+
export interface ISignStakeAndBakeParams extends CommonWriteParameters {
|
|
15
|
+
/**
|
|
16
|
+
* The approved value that will be automatically claimed and deposited
|
|
17
|
+
* to the chosen vault.
|
|
18
|
+
*/
|
|
19
|
+
value: BigNumber.Value;
|
|
20
|
+
/**
|
|
21
|
+
* The expiration UNIX time of the signature.
|
|
22
|
+
* Defaults to 24 hours from the time of signing.
|
|
23
|
+
*/
|
|
24
|
+
expiry?: number;
|
|
25
|
+
/**
|
|
26
|
+
* The chosen DeFi vault to which the funds will be deposited.
|
|
27
|
+
*/
|
|
28
|
+
vaultKey?: Vault;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ISignStakeAndBakeResult {
|
|
32
|
+
/**
|
|
33
|
+
* The signature.
|
|
34
|
+
*/
|
|
35
|
+
signature: string;
|
|
36
|
+
/**
|
|
37
|
+
* The typed data used to generate the signature.
|
|
38
|
+
*/
|
|
39
|
+
typedData: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Signs the "stake and bake" signature that allows Lombard to claim specified
|
|
44
|
+
* amount of BTC (LBTC) and deposit that amount directly to the specified DeFi
|
|
45
|
+
* vault.
|
|
46
|
+
*
|
|
47
|
+
* In order for the "stake and bake" process to work a user has to store the
|
|
48
|
+
* signature to the Lombard's system, see: `storeStakeAndBakeSignature`
|
|
49
|
+
*
|
|
50
|
+
* @param {ISignStakeAndBakeParams} parameters - The parameters.
|
|
51
|
+
* @param {BigNumber.Value} parameters.value - The amount of BTC that's going to be claimed and deposited to the DeFi vault.
|
|
52
|
+
* @param {number} parameters.expiry = The optional expiration UNIX time of the signature.
|
|
53
|
+
* @param {Vault} parameters.vaultKey - The optional DeFi vault identifier.
|
|
54
|
+
* @param {Address} parameters.account - The EVM account address.
|
|
55
|
+
* @param {ChainId} parameters.chainId - The chain id.
|
|
56
|
+
* @param {EIP1193Provider} parameters.provider - The EIP1193 provider.
|
|
57
|
+
* @param {string} parameters.rpcUrl - The optional rpc url.
|
|
58
|
+
*
|
|
59
|
+
* @returns {Promise<ISignStakeAndBakeResult>} - The signature and typed data.
|
|
60
|
+
*/
|
|
61
|
+
export async function signStakeAndBake({
|
|
62
|
+
account,
|
|
63
|
+
expiry = toUnix(now() + DAY),
|
|
64
|
+
value,
|
|
65
|
+
vaultKey = Vault.Veda,
|
|
66
|
+
chainId,
|
|
67
|
+
provider,
|
|
68
|
+
rpcUrl,
|
|
69
|
+
env,
|
|
70
|
+
}: ISignStakeAndBakeParams): Promise<ISignStakeAndBakeResult> {
|
|
71
|
+
const vault = VAULTS[vaultKey];
|
|
72
|
+
if (!vault) {
|
|
73
|
+
throw new Error(`Unknown vault key: ${vaultKey}`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (!isVedaVaultStakeAndBakeChain(chainId)) {
|
|
77
|
+
throw new Error(
|
|
78
|
+
`Unsupported chain id: ${chainId}. Please switch to one of the supported chains: ${vault.stakeAndBakeChains.join(', ')}`,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const lbtcContract = getTokenContractInfo(Token.LBTC, chainId, env);
|
|
83
|
+
const walletClient = makeWalletClient({ chainId, provider });
|
|
84
|
+
const spenderContract = vault.spenderContracts[chainId];
|
|
85
|
+
|
|
86
|
+
const nonce = await getPermitNonce({
|
|
87
|
+
owner: account,
|
|
88
|
+
chainId,
|
|
89
|
+
rpcUrl,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const typedData: Parameters<typeof walletClient.signTypedData>[0] = {
|
|
93
|
+
account,
|
|
94
|
+
domain: {
|
|
95
|
+
name: 'Lombard Staked Bitcoin',
|
|
96
|
+
version: '1',
|
|
97
|
+
chainId: BigInt(chainId),
|
|
98
|
+
verifyingContract: lbtcContract.address,
|
|
99
|
+
},
|
|
100
|
+
types: {
|
|
101
|
+
EIP712Domain: [
|
|
102
|
+
{
|
|
103
|
+
name: 'name',
|
|
104
|
+
type: 'string',
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
name: 'version',
|
|
108
|
+
type: 'string',
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
name: 'chainId',
|
|
112
|
+
type: 'uint256',
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
name: 'verifyingContract',
|
|
116
|
+
type: 'address',
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
Permit: [
|
|
120
|
+
{ name: 'owner', type: 'address' },
|
|
121
|
+
{ name: 'spender', type: 'address' },
|
|
122
|
+
{ name: 'value', type: 'uint256' },
|
|
123
|
+
{ name: 'nonce', type: 'uint256' },
|
|
124
|
+
{ name: 'deadline', type: 'uint256' },
|
|
125
|
+
],
|
|
126
|
+
},
|
|
127
|
+
primaryType: 'Permit',
|
|
128
|
+
message: {
|
|
129
|
+
owner: account,
|
|
130
|
+
spender: spenderContract.address,
|
|
131
|
+
value: BigInt(BigNumber(value).toFixed()),
|
|
132
|
+
nonce: BigInt(nonce),
|
|
133
|
+
deadline: BigInt(expiry),
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const signature = await walletClient.signTypedData(typedData);
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
signature,
|
|
141
|
+
typedData: JSON.stringify(typedData, (_, v) =>
|
|
142
|
+
typeof v === 'bigint' ? v.toString() : v,
|
|
143
|
+
),
|
|
144
|
+
};
|
|
145
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { DEFAULT_ENV } from '@lombard.finance/sdk-common';
|
|
3
|
+
import { Button } from '../../stories/components/Button';
|
|
4
|
+
import { CodeBlock } from '../../stories/components/CodeBlock';
|
|
5
|
+
import useQuery from '../../stories/hooks/useQuery';
|
|
6
|
+
import { IUnstakeLBTCParams, unstakeLBTC } from './unstakeLBTC';
|
|
7
|
+
import { ConnectButton } from '../../stories/components/ConnectButton';
|
|
8
|
+
import {
|
|
9
|
+
canPerformAction,
|
|
10
|
+
useConnection,
|
|
11
|
+
} from '../../stories/hooks/useConnection';
|
|
12
|
+
import {
|
|
13
|
+
functionType,
|
|
14
|
+
wagmiDecorator,
|
|
15
|
+
} from '../../stories/components/decorators';
|
|
16
|
+
|
|
17
|
+
const meta = {
|
|
18
|
+
title: 'write/unstakeLBTC',
|
|
19
|
+
component: StoryView,
|
|
20
|
+
tags: ['autodocs'],
|
|
21
|
+
decorators: [wagmiDecorator, functionType('write')],
|
|
22
|
+
} satisfies Meta<typeof StoryView>;
|
|
23
|
+
|
|
24
|
+
export default meta;
|
|
25
|
+
|
|
26
|
+
type Story = StoryObj<typeof meta>;
|
|
27
|
+
|
|
28
|
+
export const WithParams: Story = {
|
|
29
|
+
args: {
|
|
30
|
+
amount: 0.00001,
|
|
31
|
+
btcAddress: '',
|
|
32
|
+
env: DEFAULT_ENV,
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
type ClaimLBTCProps = Pick<IUnstakeLBTCParams, 'btcAddress' | 'env' | 'amount'>;
|
|
37
|
+
|
|
38
|
+
export function StoryView(props: ClaimLBTCProps) {
|
|
39
|
+
const connection = useConnection();
|
|
40
|
+
|
|
41
|
+
const request = async () => {
|
|
42
|
+
if (!canPerformAction(connection)) {
|
|
43
|
+
alert('Not connected');
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return unstakeLBTC({
|
|
48
|
+
amount: props.amount,
|
|
49
|
+
btcAddress: props.btcAddress,
|
|
50
|
+
|
|
51
|
+
account: connection.account.address,
|
|
52
|
+
chainId: connection.account.chainId,
|
|
53
|
+
provider: connection.provider,
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const { data, error, isLoading, refetch } = useQuery(request, [], false);
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<>
|
|
61
|
+
<p>
|
|
62
|
+
This function unstakes the specified amount of LBTC and transfers the
|
|
63
|
+
equivalent amount of BTC to the provided BTC address.
|
|
64
|
+
</p>
|
|
65
|
+
|
|
66
|
+
<div className="mb-4">
|
|
67
|
+
<ConnectButton />
|
|
68
|
+
</div>
|
|
69
|
+
|
|
70
|
+
<Button
|
|
71
|
+
onClick={refetch}
|
|
72
|
+
disabled={isLoading || !connection.account.address}
|
|
73
|
+
isLoading={isLoading}
|
|
74
|
+
actionName={unstakeLBTC.name}
|
|
75
|
+
/>
|
|
76
|
+
|
|
77
|
+
<CodeBlock text={error || data} />
|
|
78
|
+
</>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { getOutputScript } from '@lombard.finance/sdk-common';
|
|
2
|
+
import { CommonWriteParameters } from '../../common/parameters';
|
|
3
|
+
import { toSatoshi } from '../../utils/satoshi';
|
|
4
|
+
import { makeWalletClient } from '../../clients/wallet-client';
|
|
5
|
+
import { makePublicClient } from '../../clients/public-client';
|
|
6
|
+
import { CHAIN_ID_TO_VIEM_CHAIN_MAP } from '../../common/chains';
|
|
7
|
+
import { Hex } from 'viem';
|
|
8
|
+
import BigNumber from 'bignumber.js';
|
|
9
|
+
import { getTokenContractInfo } from '../../tokens/tokens';
|
|
10
|
+
import { Token } from '../../tokens/token-addresses';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The unstake parameters.
|
|
14
|
+
*/
|
|
15
|
+
export interface IUnstakeLBTCParams extends CommonWriteParameters {
|
|
16
|
+
/**
|
|
17
|
+
* The BTC address to send the unstaked BTC to.
|
|
18
|
+
*/
|
|
19
|
+
btcAddress: string;
|
|
20
|
+
/**
|
|
21
|
+
* The amount of LBTC to unstake.
|
|
22
|
+
*/
|
|
23
|
+
amount: BigNumber.Value;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Unstakes (redeems) specified amount of LBTC and sends the equivalent amount
|
|
28
|
+
* of BTC to the provided BTC address.
|
|
29
|
+
* @param {IUnstakeLBTCParams} parameters - The unstake parameters.
|
|
30
|
+
* @param {string} parameters.btcAddress - The BTC address.
|
|
31
|
+
* @param {BigNumber.Value} parameters.amount - The amount of LBTC to unstake.
|
|
32
|
+
* @param {Address} parameters.account - The EVM address.
|
|
33
|
+
* @param {ChainId} parameters.chainId - The chain id.
|
|
34
|
+
* @param {EIP1193Provider} parameters.provider - The EIP1193 provider.
|
|
35
|
+
* @param {string} parameters.rpcUrl - The optional rpc url.
|
|
36
|
+
*/
|
|
37
|
+
export async function unstakeLBTC({
|
|
38
|
+
btcAddress,
|
|
39
|
+
amount,
|
|
40
|
+
account,
|
|
41
|
+
chainId,
|
|
42
|
+
provider,
|
|
43
|
+
rpcUrl,
|
|
44
|
+
env,
|
|
45
|
+
}: IUnstakeLBTCParams): Promise<Hex> {
|
|
46
|
+
const outputScript = getOutputScript(btcAddress, env);
|
|
47
|
+
const amountSat = toSatoshi(amount).toNumber();
|
|
48
|
+
|
|
49
|
+
const lbtcContract = getTokenContractInfo(Token.LBTC, chainId, env);
|
|
50
|
+
|
|
51
|
+
const publicClient = makePublicClient({ chainId, rpcUrl });
|
|
52
|
+
const walletClient = makeWalletClient({ provider, chainId });
|
|
53
|
+
|
|
54
|
+
const { request } = await publicClient.simulateContract({
|
|
55
|
+
address: lbtcContract.address,
|
|
56
|
+
account,
|
|
57
|
+
chain: CHAIN_ID_TO_VIEM_CHAIN_MAP[chainId],
|
|
58
|
+
abi: lbtcContract.abi,
|
|
59
|
+
functionName: 'redeem',
|
|
60
|
+
args: [outputScript, BigInt(amountSat)],
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const txHash = await walletClient.writeContract(request);
|
|
64
|
+
|
|
65
|
+
return txHash;
|
|
66
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,23 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
export * from
|
|
1
|
+
// API functions:
|
|
2
|
+
export * from './api-functions';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
export * from
|
|
6
|
-
export * from "./common/utils/isValidChain";
|
|
7
|
-
export type { Env as TEnv } from "@lombard.finance/sdk-common";
|
|
8
|
-
export { Env as OEnv } from "@lombard.finance/sdk-common";
|
|
4
|
+
// READ and WRITE functions:
|
|
5
|
+
export * from './contract-functions';
|
|
9
6
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
// Vault:
|
|
8
|
+
export * from './vaults';
|
|
9
|
+
|
|
10
|
+
// Rewards:
|
|
11
|
+
export * from './rewards';
|
|
14
12
|
|
|
13
|
+
// Utils:
|
|
14
|
+
export * from './common/api-config';
|
|
15
|
+
export * from './common/blockchain-identifier';
|
|
16
|
+
export * from './common/chains';
|
|
17
|
+
export {
|
|
18
|
+
SOLANA_DEVNET_CHAIN,
|
|
19
|
+
SOLANA_MAINNET_CHAIN,
|
|
20
|
+
SOLANA_TESTNET_CHAIN,
|
|
21
|
+
} from './common/chains';
|
|
15
22
|
export {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
23
|
+
SUI_DEVNET_CHAIN,
|
|
24
|
+
SUI_MAINNET_CHAIN,
|
|
25
|
+
SUI_TESTNET_CHAIN,
|
|
26
|
+
} from './common/chains';
|
|
27
|
+
export * from './tokens/lbtc-addresses';
|
|
28
|
+
export * from './utils/satoshi';
|
|
29
|
+
|
|
30
|
+
// Metrics:
|
|
31
|
+
export { getLBTCStats } from './metrics/get-lbtc-stats';
|
|
32
|
+
|
|
33
|
+
// Re-exports:
|
|
34
|
+
export type { Address, EIP1193Provider } from 'viem';
|
|
35
|
+
export { Env } from '@lombard.finance/sdk-common';
|
|
19
36
|
|
|
37
|
+
// Bridge:
|
|
20
38
|
export {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { getApiConfig } from '../common/api-config';
|
|
3
|
+
import { IEnvParam } from '../common/parameters';
|
|
4
|
+
import BigNumber from 'bignumber.js';
|
|
5
|
+
|
|
6
|
+
/** Gets the Lombard's TVL. */
|
|
7
|
+
export async function getLBTCStats(parameters?: IEnvParam) {
|
|
8
|
+
const env = parameters?.env;
|
|
9
|
+
|
|
10
|
+
const { bffApiUrl } = getApiConfig(env);
|
|
11
|
+
if (!bffApiUrl) {
|
|
12
|
+
throw new Error(
|
|
13
|
+
`Could not determine API endpoint for provided environment: ${env}`,
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const { data } = await axios.get<
|
|
18
|
+
{ price: number; supply: number; tvl: number }[]
|
|
19
|
+
>(`${bffApiUrl}/dune-api/query/getLBTCStats`);
|
|
20
|
+
|
|
21
|
+
const { data: holders } = await axios.get<number>(
|
|
22
|
+
`${bffApiUrl}/dune-api/query/lbtc-holders`,
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
const { data: historicalHolders } = await axios.get<number>(
|
|
26
|
+
`${bffApiUrl}/dune-api/query/getTotalLBTCUsers`,
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const stats = {
|
|
30
|
+
price: BigNumber(data[0].price),
|
|
31
|
+
supply: BigNumber(data[0].supply),
|
|
32
|
+
tvl: BigNumber(data[0].tvl),
|
|
33
|
+
holders: BigNumber(holders),
|
|
34
|
+
historicalHolders: BigNumber(historicalHolders),
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return stats;
|
|
38
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export { claimReward, type ClaimRewardParameters } from './lib/claim-reward';
|
|
2
|
+
|
|
3
|
+
export {
|
|
4
|
+
getRewardBalances,
|
|
5
|
+
type GetRewardBalancesParameters,
|
|
6
|
+
RewardBlockchainType,
|
|
7
|
+
} from './lib/get-reward-balances';
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
getRewardSigningData,
|
|
11
|
+
type GetRewardSigningDataParameters,
|
|
12
|
+
} from './lib/get-reward-signing-data';
|
|
13
|
+
|
|
14
|
+
export {
|
|
15
|
+
getRewardWithdrawalFee,
|
|
16
|
+
type GetRewardWithdrawalFeeParameters,
|
|
17
|
+
} from './lib/get-reward-withdrawal-fee';
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
getRewardWithdrawals,
|
|
21
|
+
type GetRewardsWithdrawalsParameters,
|
|
22
|
+
type RewardWithdrawal,
|
|
23
|
+
RewardWithdrawalStatus,
|
|
24
|
+
} from './lib/get-reward-withdrawals';
|
|
25
|
+
|
|
26
|
+
export { isRewardTokenSupported, RewardToken } from './lib/reward-tokens';
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import {
|
|
3
|
+
functionType,
|
|
4
|
+
wagmiDecorator,
|
|
5
|
+
} from '../../stories/components/decorators';
|
|
6
|
+
import { Button } from '../../stories/components/Button';
|
|
7
|
+
import { CodeBlock } from '../../stories/components/CodeBlock';
|
|
8
|
+
import { ErrorBlock } from '../../stories/components/error-block';
|
|
9
|
+
import useQuery from '../../stories/hooks/useQuery';
|
|
10
|
+
import { RewardToken } from './reward-tokens';
|
|
11
|
+
import { Env } from '@lombard.finance/sdk-common';
|
|
12
|
+
import { claimReward, ClaimRewardParameters } from './claim-reward';
|
|
13
|
+
import { ConnectButton } from '../../stories/components/ConnectButton';
|
|
14
|
+
import {
|
|
15
|
+
canPerformAction,
|
|
16
|
+
useConnection,
|
|
17
|
+
} from '../../stories/hooks/useConnection';
|
|
18
|
+
import { ChainId } from '../../common/chains';
|
|
19
|
+
import { EXAMPLE_BABYLON_ADDRESS } from '../../stories/constants';
|
|
20
|
+
|
|
21
|
+
const meta = {
|
|
22
|
+
title: 'rewards/claimReward',
|
|
23
|
+
component: StoryView,
|
|
24
|
+
tags: ['autodocs'],
|
|
25
|
+
decorators: [wagmiDecorator, functionType('write')],
|
|
26
|
+
} satisfies Meta<typeof StoryView>;
|
|
27
|
+
|
|
28
|
+
export default meta;
|
|
29
|
+
|
|
30
|
+
type Story = StoryObj<typeof meta>;
|
|
31
|
+
|
|
32
|
+
export const WithParams: Story = {
|
|
33
|
+
args: {
|
|
34
|
+
to: EXAMPLE_BABYLON_ADDRESS,
|
|
35
|
+
amount: '0.001',
|
|
36
|
+
rewardToken: RewardToken.BABY,
|
|
37
|
+
chainId: ChainId.ethereum,
|
|
38
|
+
env: Env.stage,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
type Props = Omit<ClaimRewardParameters, 'account' | 'provider'>;
|
|
43
|
+
|
|
44
|
+
export function StoryView(props: Props) {
|
|
45
|
+
const connection = useConnection();
|
|
46
|
+
|
|
47
|
+
const request = async () => {
|
|
48
|
+
if (!canPerformAction(connection)) {
|
|
49
|
+
alert('Please connect');
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return claimReward({
|
|
54
|
+
account: connection.account.address,
|
|
55
|
+
provider: connection.provider,
|
|
56
|
+
...props,
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const { data, error, isLoading, refetch } = useQuery(request, [], false);
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<>
|
|
64
|
+
<p>This function claims a reward earned by a user.</p>
|
|
65
|
+
|
|
66
|
+
<div className="mb-4">
|
|
67
|
+
<ConnectButton />
|
|
68
|
+
</div>
|
|
69
|
+
|
|
70
|
+
<Button
|
|
71
|
+
onClick={refetch}
|
|
72
|
+
disabled={isLoading || !canPerformAction(connection)}
|
|
73
|
+
isLoading={isLoading}
|
|
74
|
+
actionName={claimReward.name}
|
|
75
|
+
/>
|
|
76
|
+
|
|
77
|
+
<ErrorBlock>{error}</ErrorBlock>
|
|
78
|
+
|
|
79
|
+
<CodeBlock text={data} />
|
|
80
|
+
</>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import BigNumber from 'bignumber.js';
|
|
2
|
+
import { CommonWriteParameters } from '../../common/parameters';
|
|
3
|
+
import axios from 'axios';
|
|
4
|
+
import { getApiConfig } from '../../common/api-config';
|
|
5
|
+
import { makeWalletClient } from '../../clients/wallet-client';
|
|
6
|
+
import { getRewardWithdrawalFee } from './get-reward-withdrawal-fee';
|
|
7
|
+
import { getRewardSigningData } from './get-reward-signing-data';
|
|
8
|
+
import {
|
|
9
|
+
mapDataToRewardWithdrawal,
|
|
10
|
+
WithdrawalData,
|
|
11
|
+
} from './get-reward-withdrawals';
|
|
12
|
+
import { isRewardTokenSupported, RewardToken } from './reward-tokens';
|
|
13
|
+
|
|
14
|
+
type Response = {
|
|
15
|
+
withdrawal: WithdrawalData;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type ClaimRewardParameters = {
|
|
19
|
+
/** The reward token. */
|
|
20
|
+
rewardToken: RewardToken;
|
|
21
|
+
/** The amount of reward to be withdrawn (claimed). */
|
|
22
|
+
amount: BigNumber.Value;
|
|
23
|
+
/** The destination address. */
|
|
24
|
+
to: string;
|
|
25
|
+
} & CommonWriteParameters;
|
|
26
|
+
|
|
27
|
+
const REQUEST_WITHDRAW_URL =
|
|
28
|
+
'/api/v1/distribution/account/{from}/withdrawals/{to}';
|
|
29
|
+
|
|
30
|
+
/** Claims a reward. */
|
|
31
|
+
export async function claimReward({
|
|
32
|
+
account: from,
|
|
33
|
+
rewardToken,
|
|
34
|
+
amount,
|
|
35
|
+
to,
|
|
36
|
+
chainId,
|
|
37
|
+
provider,
|
|
38
|
+
env,
|
|
39
|
+
}: ClaimRewardParameters) {
|
|
40
|
+
if (!isRewardTokenSupported(rewardToken)) {
|
|
41
|
+
throw new Error(`Unknown reward token: ${RewardToken}`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const walletClient = makeWalletClient({
|
|
45
|
+
chainId,
|
|
46
|
+
provider,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const withdrawalFee = await getRewardWithdrawalFee({
|
|
50
|
+
address: from,
|
|
51
|
+
rewardToken,
|
|
52
|
+
env,
|
|
53
|
+
});
|
|
54
|
+
const signingData = await getRewardSigningData({
|
|
55
|
+
from,
|
|
56
|
+
to,
|
|
57
|
+
amount,
|
|
58
|
+
fee: withdrawalFee,
|
|
59
|
+
rewardToken,
|
|
60
|
+
env,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const signature = await walletClient.signMessage({
|
|
64
|
+
account: from,
|
|
65
|
+
message: signingData,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const payload = {
|
|
69
|
+
amount: BigNumber(amount).toFixed(),
|
|
70
|
+
fee: BigNumber(withdrawalFee).toFixed(),
|
|
71
|
+
signature,
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const { baseApiUrl } = getApiConfig(env);
|
|
75
|
+
const { data: withdrawData } = await axios.post<Response>(
|
|
76
|
+
REQUEST_WITHDRAW_URL.replace('{from}', from).replace('{to}', to),
|
|
77
|
+
payload,
|
|
78
|
+
{
|
|
79
|
+
baseURL: baseApiUrl,
|
|
80
|
+
},
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
return mapDataToRewardWithdrawal(withdrawData.withdrawal);
|
|
84
|
+
}
|