@lombard.finance/sdk 4.0.0 → 4.1.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/CHANGELOG.md +6 -0
- package/dist/common/feature-config.d.ts.map +1 -1
- package/dist/index2.cjs +6 -6
- package/dist/index2.js +762 -754
- package/package.json +7 -8
- package/src/__tests__/AssetNamespace.spec.ts +0 -234
- package/src/__tests__/helpers/createTestConfig.ts +0 -90
- package/src/__tests__/integration/automint-fee.integration.test.ts +0 -74
- package/src/__tests__/integration/btc-deposit.integration.test.ts +0 -109
- package/src/__tests__/integration/btc-stake-and-deploy.integration.test.ts +0 -96
- package/src/__tests__/integration/btc-stake.integration.test.ts +0 -466
- package/src/__tests__/integration/evm-actions.integration.test.ts +0 -932
- package/src/__tests__/integration/evm-deploy.integration.test.ts +0 -122
- package/src/__tests__/integration/evm-redeem.integration.test.ts +0 -157
- package/src/__tests__/integration/faq-patterns.integration.test.ts +0 -465
- package/src/__tests__/integration/getLBTCMintingFee.integration.test.ts +0 -195
- package/src/__tests__/real-wallet/btc/btc-stake.real.test.ts +0 -70
- package/src/__tests__/real-wallet/evm/evm-stake.real.test.ts +0 -47
- package/src/__tests__/real-wallet/evm/evm-unstake.real.test.ts +0 -49
- package/src/__tests__/real-wallet/non-evm/solana-unstake.real.test.ts +0 -19
- package/src/__tests__/real-wallet/non-evm/starknet-unstake.real.test.ts +0 -19
- package/src/__tests__/real-wallet/non-evm/sui-unstake.real.test.ts +0 -19
- package/src/__tests__/services/ApiService.test.ts +0 -62
- package/src/__tests__/services/BtcService.test.ts +0 -30
- package/src/__tests__/services/EvmService.test.ts +0 -39
- package/src/__tests__/setup.ts +0 -16
- package/src/__tests__/test-utils/eip1193-adapter.ts +0 -48
- package/src/__tests__/test-utils/evm-wallet.ts +0 -38
- package/src/__tests__/test-utils/solana-wallet.ts +0 -22
- package/src/__tests__/test-utils/starknet-wallet.ts +0 -9
- package/src/__tests__/test-utils/sui-wallet.ts +0 -14
- package/src/__tests__/test-utils/test-constraints.ts +0 -110
- package/src/__tests__/unit/btc/BtcDeposit.test.ts +0 -253
- package/src/__tests__/unit/btc/BtcDepositAndDeploy.test.ts +0 -174
- package/src/__tests__/unit/btc/BtcDepositConfig.test.ts +0 -143
- package/src/__tests__/unit/btc/BtcDepositStatusTransition.test.ts +0 -221
- package/src/__tests__/unit/btc/BtcStakeAndDeploy.test.ts +0 -194
- package/src/__tests__/unit/btc/ExistingSignatureHandling.test.ts +0 -301
- package/src/__tests__/unit/btc/StakeAndBakeRatioConversion.test.ts +0 -200
- package/src/__tests__/unit/btc/StakeAndBakeSignatureRestore.test.ts +0 -216
- package/src/__tests__/unit/btc/TokenParameterConsistency.test.ts +0 -184
- package/src/__tests__/unit/btc/btc-deposit-token.test.ts +0 -191
- package/src/__tests__/unit/catalog/AssetCatalog.test.ts +0 -293
- package/src/__tests__/unit/config/ChainConfig.test.ts +0 -47
- package/src/__tests__/unit/config/FeeAuthConfig.test.ts +0 -76
- package/src/__tests__/unit/contract-functions/getLBTCMintingFee.test.ts +0 -128
- package/src/__tests__/unit/core/chain-parsing.test.ts +0 -257
- package/src/__tests__/unit/defi/AvailableProtocols.test.ts +0 -100
- package/src/__tests__/unit/defi/DefiRegistry.test.ts +0 -25
- package/src/__tests__/unit/evm/EvmDeploy.test.ts +0 -224
- package/src/__tests__/unit/evm/EvmRedeem.test.ts +0 -207
- package/src/__tests__/unit/evm/EvmRedeemFeeAuth.test.ts +0 -93
- package/src/__tests__/unit/evm/EvmStake.test.ts +0 -207
- package/src/__tests__/unit/evm/EvmStakeFeeAuth.test.ts +0 -193
- package/src/__tests__/unit/evm/EvmUnstakeAllowance.test.ts +0 -69
- package/src/__tests__/unit/evm/EvmUnstakeConfig.test.ts +0 -203
- package/src/__tests__/unit/fee-signature-expiration.test.ts +0 -76
- package/src/__tests__/unit/modules/CapabilityRegistry.test.ts +0 -55
- package/src/__tests__/unit/shared/BaseAction.test.ts +0 -122
- package/src/__tests__/unit/shared/BaseBtcAction.test.ts +0 -114
- package/src/__tests__/unit/solana/SolanaUnstake.test.ts +0 -314
- package/src/__tests__/unit/starknet/StarknetUnstake.test.ts +0 -318
- package/src/__tests__/unit/sui/SuiUnstake.test.ts +0 -310
- package/src/__tests__/unit/utils/satoshi.test.ts +0 -27
- package/src/__tests__/unit/validation/address-validation.test.ts +0 -350
- package/src/api-functions/generateDepositBtcAddress/generateDepositBtcAddress.stories.tsx +0 -71
- package/src/api-functions/generateDepositBtcAddress/generateDepositBtcAddress.ts +0 -235
- package/src/api-functions/generateDepositBtcAddress/index.ts +0 -1
- package/src/api-functions/get-badges-by-address/get-badges-by-address.ts +0 -13
- package/src/api-functions/get-badges-by-address/index.ts +0 -1
- package/src/api-functions/getDepositAddressReferrer/getDepositAddressReferrer.ts +0 -38
- package/src/api-functions/getDepositAddressReferrer/index.ts +0 -1
- package/src/api-functions/getDepositBtcAddress/getDepositBtcAddress.stories.tsx +0 -59
- package/src/api-functions/getDepositBtcAddress/getDepositBtcAddress.test.ts +0 -265
- package/src/api-functions/getDepositBtcAddress/getDepositBtcAddress.ts +0 -167
- package/src/api-functions/getDepositBtcAddress/getDepositBtcAddresses.stories.tsx +0 -58
- package/src/api-functions/getDepositBtcAddress/index.ts +0 -1
- package/src/api-functions/getDepositBtcAddress/make-request.ts +0 -59
- package/src/api-functions/getDepositBtcAddress/types.ts +0 -106
- package/src/api-functions/getDepositsByAddress/getDepositsByAddress.stories.tsx +0 -51
- package/src/api-functions/getDepositsByAddress/getDepositsByAddress.ts +0 -502
- package/src/api-functions/getDepositsByAddress/index.ts +0 -1
- package/src/api-functions/getLBTCExchangeRate/get-exchange-ratio.stories.tsx +0 -48
- package/src/api-functions/getLBTCExchangeRate/get-exchange-ratio.ts +0 -59
- package/src/api-functions/getLBTCExchangeRate/getLBTCExchangeRate.stories.tsx +0 -55
- package/src/api-functions/getLBTCExchangeRate/getLBTCExchangeRate.ts +0 -75
- package/src/api-functions/getLBTCExchangeRate/index.ts +0 -2
- package/src/api-functions/getNetworkFeeSignature/getNetworkFeeSignature.stories.tsx +0 -59
- package/src/api-functions/getNetworkFeeSignature/getNetworkFeeSignature.ts +0 -116
- package/src/api-functions/getNetworkFeeSignature/index.ts +0 -1
- package/src/api-functions/getPointsByAddress/getPointsByAddress.stories.tsx +0 -51
- package/src/api-functions/getPointsByAddress/getPointsByAddress.ts +0 -304
- package/src/api-functions/getPointsByAddress/index.ts +0 -1
- package/src/api-functions/getUnstakesByAddress/getUnstakesByAddress.stories.tsx +0 -51
- package/src/api-functions/getUnstakesByAddress/getUnstakesByAddress.ts +0 -368
- package/src/api-functions/getUnstakesByAddress/index.ts +0 -1
- package/src/api-functions/getUserStakeAndBakeSignature/getUserStakeAndBakeSignature.stories.tsx +0 -70
- package/src/api-functions/getUserStakeAndBakeSignature/getUserStakeAndBakeSignature.ts +0 -91
- package/src/api-functions/getUserStakeAndBakeSignature/index.ts +0 -1
- package/src/api-functions/index.ts +0 -11
- package/src/api-functions/setReferral/index.ts +0 -1
- package/src/api-functions/setReferral/setReferral.ts +0 -67
- package/src/api-functions/storeNetworkFeeSignature/index.ts +0 -1
- package/src/api-functions/storeNetworkFeeSignature/storeNetworkFeeSignature.stories.tsx +0 -57
- package/src/api-functions/storeNetworkFeeSignature/storeNetworkFeeSignature.ts +0 -75
- package/src/api-functions/storeStakeAndBakeSignature/index.ts +0 -1
- package/src/api-functions/storeStakeAndBakeSignature/storeStakeAndBakeSignature.stories.tsx +0 -57
- package/src/api-functions/storeStakeAndBakeSignature/storeStakeAndBakeSignature.ts +0 -61
- package/src/bridge/abi/CCIP_BRIDGE_ADAPTER_ABI.json +0 -704
- package/src/bridge/abi/CCIP_ROUTER_ABI.json +0 -702
- package/src/bridge/abi/OFT_BRIDGE_ADAPTER_ABI.json +0 -912
- package/src/bridge/index.ts +0 -16
- package/src/bridge/lib/bridge.stories.tsx +0 -90
- package/src/bridge/lib/bridge.ts +0 -115
- package/src/bridge/lib/ccip-bridge.stories.tsx +0 -91
- package/src/bridge/lib/ccip-bridge.ts +0 -214
- package/src/bridge/lib/ccip-config.ts +0 -54
- package/src/bridge/lib/config.ts +0 -384
- package/src/bridge/lib/oft-bridge.stories.tsx +0 -90
- package/src/bridge/lib/oft-bridge.ts +0 -217
- package/src/chains/btc/BtcActions.ts +0 -192
- package/src/chains/btc/actions/deposit/BtcDeposit.ts +0 -388
- package/src/chains/btc/actions/deposit/config/evm.ts +0 -197
- package/src/chains/btc/actions/deposit/config/index.ts +0 -53
- package/src/chains/btc/actions/deposit/config/types.ts +0 -108
- package/src/chains/btc/actions/deposit/factory.ts +0 -53
- package/src/chains/btc/actions/deposit/index.ts +0 -23
- package/src/chains/btc/actions/deposit/types.ts +0 -120
- package/src/chains/btc/actions/depositAndDeploy/BtcDepositAndDeploy.ts +0 -366
- package/src/chains/btc/actions/depositAndDeploy/config/evm.ts +0 -105
- package/src/chains/btc/actions/depositAndDeploy/config/index.ts +0 -111
- package/src/chains/btc/actions/depositAndDeploy/config/types.ts +0 -67
- package/src/chains/btc/actions/depositAndDeploy/factory.ts +0 -38
- package/src/chains/btc/actions/depositAndDeploy/index.ts +0 -24
- package/src/chains/btc/actions/depositAndDeploy/types.ts +0 -120
- package/src/chains/btc/actions/index.ts +0 -14
- package/src/chains/btc/actions/shared/BaseBtcAction.ts +0 -495
- package/src/chains/btc/actions/shared/index.ts +0 -28
- package/src/chains/btc/actions/shared/tokenUtils.ts +0 -68
- package/src/chains/btc/actions/shared/validation.ts +0 -180
- package/src/chains/btc/actions/stake/BtcStake.ts +0 -433
- package/src/chains/btc/actions/stake/__tests__/BtcStake.test.ts +0 -247
- package/src/chains/btc/actions/stake/config/evm.ts +0 -183
- package/src/chains/btc/actions/stake/config/index.ts +0 -122
- package/src/chains/btc/actions/stake/config/solana.ts +0 -96
- package/src/chains/btc/actions/stake/config/starknet.ts +0 -66
- package/src/chains/btc/actions/stake/config/sui.ts +0 -61
- package/src/chains/btc/actions/stake/config/types.ts +0 -165
- package/src/chains/btc/actions/stake/factory.ts +0 -53
- package/src/chains/btc/actions/stake/index.ts +0 -22
- package/src/chains/btc/actions/stake/types.ts +0 -175
- package/src/chains/btc/actions/stakeAndDeploy/BtcStakeAndDeploy.ts +0 -415
- package/src/chains/btc/actions/stakeAndDeploy/config/evm.ts +0 -135
- package/src/chains/btc/actions/stakeAndDeploy/config/index.ts +0 -119
- package/src/chains/btc/actions/stakeAndDeploy/config/types.ts +0 -93
- package/src/chains/btc/actions/stakeAndDeploy/factory.ts +0 -54
- package/src/chains/btc/actions/stakeAndDeploy/index.ts +0 -26
- package/src/chains/btc/actions/stakeAndDeploy/types.ts +0 -118
- package/src/chains/btc/client/getCurrentBlockHeight.ts +0 -28
- package/src/chains/btc/client/mempool/error.ts +0 -24
- package/src/chains/btc/client/mempool/mempool.ts +0 -23
- package/src/chains/btc/index.ts +0 -71
- package/src/chains/evm/EvmActions.ts +0 -185
- package/src/chains/evm/actions/deploy/EvmDeploy.ts +0 -256
- package/src/chains/evm/actions/deploy/config/evm.ts +0 -80
- package/src/chains/evm/actions/deploy/config/index.ts +0 -8
- package/src/chains/evm/actions/deploy/config/types.ts +0 -43
- package/src/chains/evm/actions/deploy/factory.ts +0 -44
- package/src/chains/evm/actions/deploy/index.ts +0 -17
- package/src/chains/evm/actions/deploy/types.ts +0 -74
- package/src/chains/evm/actions/deposit/EvmDeposit.ts +0 -159
- package/src/chains/evm/actions/deposit/config/evm.ts +0 -100
- package/src/chains/evm/actions/deposit/config/index.ts +0 -8
- package/src/chains/evm/actions/deposit/config/types.ts +0 -39
- package/src/chains/evm/actions/deposit/factory.ts +0 -44
- package/src/chains/evm/actions/deposit/index.ts +0 -17
- package/src/chains/evm/actions/deposit/types.ts +0 -87
- package/src/chains/evm/actions/index.ts +0 -67
- package/src/chains/evm/actions/redeem/EvmRedeem.ts +0 -263
- package/src/chains/evm/actions/redeem/config/evm.ts +0 -85
- package/src/chains/evm/actions/redeem/config/index.ts +0 -8
- package/src/chains/evm/actions/redeem/config/types.ts +0 -39
- package/src/chains/evm/actions/redeem/factory.ts +0 -43
- package/src/chains/evm/actions/redeem/index.ts +0 -17
- package/src/chains/evm/actions/redeem/types.ts +0 -93
- package/src/chains/evm/actions/stake/EvmStake.ts +0 -339
- package/src/chains/evm/actions/stake/config/evm.ts +0 -89
- package/src/chains/evm/actions/stake/config/index.ts +0 -8
- package/src/chains/evm/actions/stake/config/types.ts +0 -89
- package/src/chains/evm/actions/stake/factory.ts +0 -52
- package/src/chains/evm/actions/stake/index.ts +0 -30
- package/src/chains/evm/actions/stake/types.ts +0 -104
- package/src/chains/evm/actions/unstake/EvmUnstake.ts +0 -258
- package/src/chains/evm/actions/unstake/config/evm.ts +0 -123
- package/src/chains/evm/actions/unstake/config/index.ts +0 -13
- package/src/chains/evm/actions/unstake/config/types.ts +0 -37
- package/src/chains/evm/actions/unstake/factory.ts +0 -44
- package/src/chains/evm/actions/unstake/index.ts +0 -22
- package/src/chains/evm/actions/unstake/types.ts +0 -87
- package/src/chains/evm/index.ts +0 -16
- package/src/chains/evm/shared/feeAuth.ts +0 -198
- package/src/chains/evm/shared/index.ts +0 -7
- package/src/chains/solana/SolanaActions.ts +0 -85
- package/src/chains/solana/actions/index.ts +0 -7
- package/src/chains/solana/actions/unstake/SolanaUnstake.ts +0 -151
- package/src/chains/solana/actions/unstake/config/btc.ts +0 -47
- package/src/chains/solana/actions/unstake/config/index.ts +0 -8
- package/src/chains/solana/actions/unstake/config/solana.ts +0 -47
- package/src/chains/solana/actions/unstake/config/types.ts +0 -35
- package/src/chains/solana/actions/unstake/factory.ts +0 -34
- package/src/chains/solana/actions/unstake/index.ts +0 -14
- package/src/chains/solana/actions/unstake/types.ts +0 -58
- package/src/chains/solana/index.ts +0 -8
- package/src/chains/starknet/StarknetActions.ts +0 -85
- package/src/chains/starknet/actions/index.ts +0 -7
- package/src/chains/starknet/actions/unstake/StarknetUnstake.ts +0 -128
- package/src/chains/starknet/actions/unstake/config/btc.ts +0 -43
- package/src/chains/starknet/actions/unstake/config/index.ts +0 -8
- package/src/chains/starknet/actions/unstake/config/starknet.ts +0 -43
- package/src/chains/starknet/actions/unstake/config/types.ts +0 -27
- package/src/chains/starknet/actions/unstake/factory.ts +0 -32
- package/src/chains/starknet/actions/unstake/index.ts +0 -14
- package/src/chains/starknet/actions/unstake/types.ts +0 -57
- package/src/chains/starknet/index.ts +0 -8
- package/src/chains/sui/SuiActions.ts +0 -82
- package/src/chains/sui/actions/index.ts +0 -7
- package/src/chains/sui/actions/unstake/SuiUnstake.ts +0 -146
- package/src/chains/sui/actions/unstake/config/btc.ts +0 -43
- package/src/chains/sui/actions/unstake/config/index.ts +0 -8
- package/src/chains/sui/actions/unstake/config/sui.ts +0 -43
- package/src/chains/sui/actions/unstake/config/types.ts +0 -27
- package/src/chains/sui/actions/unstake/factory.ts +0 -32
- package/src/chains/sui/actions/unstake/index.ts +0 -14
- package/src/chains/sui/actions/unstake/types.ts +0 -57
- package/src/chains/sui/index.ts +0 -8
- package/src/client/ApiNamespace.ts +0 -302
- package/src/client/AssetNamespace.ts +0 -112
- package/src/client/LombardSDK.ts +0 -212
- package/src/client/PartnerConfiguration.ts +0 -50
- package/src/client/createConfig.ts +0 -90
- package/src/client/createLombardSDK.ts +0 -130
- package/src/clients/evm-signer-adapter.ts +0 -313
- package/src/clients/public-client.ts +0 -49
- package/src/clients/rpc-url-config.ts +0 -64
- package/src/clients/wallet-client.ts +0 -34
- package/src/common/api-config.ts +0 -48
- package/src/common/blockchain-identifier.ts +0 -217
- package/src/common/chains.stories.tsx +0 -68
- package/src/common/chains.ts +0 -449
- package/src/common/constants.ts +0 -1
- package/src/common/contract-info.ts +0 -9
- package/src/common/feature-config.ts +0 -79
- package/src/common/fee-requirements.ts +0 -34
- package/src/common/parameters.ts +0 -89
- package/src/config/defaults.ts +0 -49
- package/src/config/index.ts +0 -12
- package/src/config/providers.ts +0 -81
- package/src/config/types.ts +0 -216
- package/src/config/validation.ts +0 -69
- package/src/contract-functions/approveLBTC/approveLBTC.stories.tsx +0 -79
- package/src/contract-functions/approveLBTC/approveLBTC.ts +0 -66
- package/src/contract-functions/approveLBTC/index.ts +0 -1
- package/src/contract-functions/approveToken/approveToken.ts +0 -126
- package/src/contract-functions/approveToken/index.ts +0 -1
- package/src/contract-functions/claimLBTC/claimLBTC.stories.tsx +0 -82
- package/src/contract-functions/claimLBTC/claimLBTC.ts +0 -159
- package/src/contract-functions/claimLBTC/index.ts +0 -1
- package/src/contract-functions/claimUnstakeRedeem/claimUnstakeRedeem.ts +0 -95
- package/src/contract-functions/claimUnstakeRedeem/index.ts +0 -1
- package/src/contract-functions/deposit/depositToken.stories.tsx +0 -83
- package/src/contract-functions/deposit/depositToken.ts +0 -214
- package/src/contract-functions/deposit/index.ts +0 -1
- package/src/contract-functions/getBasculeDepositStatus/decodeBasculeDepositStatus.ts +0 -170
- package/src/contract-functions/getBasculeDepositStatus/getBasculeDepositStatus.stories.tsx +0 -62
- package/src/contract-functions/getBasculeDepositStatus/getBasculeDepositStatus.ts +0 -211
- package/src/contract-functions/getBasculeDepositStatus/index.ts +0 -2
- package/src/contract-functions/getLBTCMintingFee/getLBTCMintingFee.stories.tsx +0 -61
- package/src/contract-functions/getLBTCMintingFee/getLBTCMintingFee.ts +0 -193
- package/src/contract-functions/getLBTCMintingFee/index.ts +0 -1
- package/src/contract-functions/getLBTCTotalSupply/getLBTCTotalSupply.stories.tsx +0 -51
- package/src/contract-functions/getLBTCTotalSupply/getLBTCTotalSupply.ts +0 -40
- package/src/contract-functions/getLBTCTotalSupply/index.ts +0 -1
- package/src/contract-functions/getPermitNonce/getPermitNonce.stories.tsx +0 -56
- package/src/contract-functions/getPermitNonce/getPermitNonce.ts +0 -50
- package/src/contract-functions/getPermitNonce/index.ts +0 -1
- package/src/contract-functions/getShareValue/getShareValue.stories.tsx +0 -58
- package/src/contract-functions/getShareValue/getShareValue.ts +0 -59
- package/src/contract-functions/getShareValue/index.ts +0 -1
- package/src/contract-functions/getSharesByAddress/getSharesByAddress.stories.tsx +0 -65
- package/src/contract-functions/getSharesByAddress/getSharesByAddress.ts +0 -86
- package/src/contract-functions/getSharesByAddress/index.ts +0 -4
- package/src/contract-functions/getStakeAndBakeFee/__tests__/getStakeAndBakeFee.test.ts +0 -167
- package/src/contract-functions/getStakeAndBakeFee/getStakeAndBakeFee.stories.tsx +0 -180
- package/src/contract-functions/getStakeAndBakeFee/getStakeAndBakeFee.tsx +0 -101
- package/src/contract-functions/getStakeAndBakeFee/index.ts +0 -1
- package/src/contract-functions/index.ts +0 -21
- package/src/contract-functions/signLbtcDestionationAddr/index.ts +0 -1
- package/src/contract-functions/signLbtcDestionationAddr/signLbtcDestinationAddr.ts +0 -32
- package/src/contract-functions/signLbtcDestionationAddr/signLbtcDestionationAddr.stories.tsx +0 -64
- package/src/contract-functions/signNetworkFee/getTypedData.ts +0 -41
- package/src/contract-functions/signNetworkFee/index.ts +0 -1
- package/src/contract-functions/signNetworkFee/signNetworkFee.stories.tsx +0 -94
- package/src/contract-functions/signNetworkFee/signNetworkFee.ts +0 -106
- package/src/contract-functions/signStakeAndBake/__tests__/signStakeAndBake.test.ts +0 -888
- package/src/contract-functions/signStakeAndBake/handleApprove.ts +0 -81
- package/src/contract-functions/signStakeAndBake/handlePermit.ts +0 -28
- package/src/contract-functions/signStakeAndBake/index.ts +0 -2
- package/src/contract-functions/signStakeAndBake/signStakeAndBake.stories.tsx +0 -202
- package/src/contract-functions/signStakeAndBake/signStakeAndBake.ts +0 -160
- package/src/contract-functions/signStakeAndBake/typed-data-builder.ts +0 -137
- package/src/contract-functions/signStakeAndBake/utils.ts +0 -61
- package/src/contract-functions/signStakeAndBake/validation.ts +0 -124
- package/src/contract-functions/unstakeLBTC/index.ts +0 -1
- package/src/contract-functions/unstakeLBTC/unstakeLBTC.stories.tsx +0 -92
- package/src/contract-functions/unstakeLBTC/unstakeLBTC.ts +0 -396
- package/src/contracts/abis/index.ts +0 -29
- package/src/contracts/index.ts +0 -63
- package/src/contracts/types.ts +0 -143
- package/src/contracts/utils.ts +0 -288
- package/src/core/assets/catalog.ts +0 -343
- package/src/core/assets/index.ts +0 -40
- package/src/core/assets/types.ts +0 -142
- package/src/core/assets/utils.ts +0 -287
- package/src/core/chains/catalog.ts +0 -396
- package/src/core/chains/index.ts +0 -39
- package/src/core/chains/types.ts +0 -193
- package/src/core/chains/utils.ts +0 -245
- package/src/core/index.ts +0 -72
- package/src/core/types.ts +0 -126
- package/src/debug-api/btc-script-to-address.ts +0 -20
- package/src/debug-api/btc-tx-info.ts +0 -32
- package/src/debug-api/evm-by-btc-address.ts +0 -26
- package/src/debug-api/index.ts +0 -3
- package/src/defi/README.md +0 -517
- package/src/defi/defi-registry.stories.tsx +0 -527
- package/src/defi/defi-registry.ts +0 -295
- package/src/defi/index.ts +0 -17
- package/src/index.ts +0 -336
- package/src/metrics/get-additional-rewards.ts +0 -69
- package/src/metrics/get-lbtc-apy.ts +0 -74
- package/src/metrics/get-lbtc-stats.stories.tsx +0 -57
- package/src/metrics/get-lbtc-stats.ts +0 -59
- package/src/metrics/get-positions-summary.stories.tsx +0 -58
- package/src/metrics/get-positions-summary.ts +0 -132
- package/src/modules/CapabilityRegistry.ts +0 -125
- package/src/modules/apiModule.ts +0 -51
- package/src/modules/btcModule.ts +0 -43
- package/src/modules/evmModule.ts +0 -48
- package/src/modules/index.ts +0 -60
- package/src/referrals/ReferralsClient.ts +0 -34
- package/src/referrals/index.ts +0 -1
- package/src/services/ApiService.ts +0 -152
- package/src/services/BtcService.ts +0 -29
- package/src/services/EvmService.ts +0 -127
- package/src/services/index.ts +0 -43
- package/src/shared/__tests__/errors.test.ts +0 -185
- package/src/shared/__tests__/events.test.ts +0 -120
- package/src/shared/__tests__/types.test.ts +0 -155
- package/src/shared/actions/BaseAction.ts +0 -497
- package/src/shared/actions/__tests__/BaseAction.test.ts +0 -292
- package/src/shared/actions/index.ts +0 -9
- package/src/shared/constants/statusConstants.ts +0 -108
- package/src/shared/context/ContextBuilder.ts +0 -149
- package/src/shared/context/index.ts +0 -8
- package/src/shared/context/types.ts +0 -156
- package/src/shared/deposits/depositStatus.ts +0 -402
- package/src/shared/deposits/index.ts +0 -29
- package/src/shared/errors.ts +0 -405
- package/src/shared/events.ts +0 -260
- package/src/shared/evm/switchChain.ts +0 -109
- package/src/shared/index.ts +0 -54
- package/src/shared/monitoring/__tests__/createEventEmitter.test.ts +0 -150
- package/src/shared/monitoring/createEventEmitter.ts +0 -160
- package/src/shared/monitoring/createProgressEmitter.ts +0 -46
- package/src/shared/monitoring/depositMonitor.ts +0 -211
- package/src/shared/monitoring/index.ts +0 -25
- package/src/shared/validation/index.ts +0 -411
- package/src/stories/arg-types.ts +0 -38
- package/src/stories/components/Badge.tsx +0 -27
- package/src/stories/components/Button/Button.css +0 -10
- package/src/stories/components/Button/Button.tsx +0 -52
- package/src/stories/components/Button/index.ts +0 -1
- package/src/stories/components/Card.tsx +0 -18
- package/src/stories/components/CodeBlock/CodeBlock.tsx +0 -27
- package/src/stories/components/CodeBlock/CodeBlockStyles.css +0 -3
- package/src/stories/components/CodeBlock/index.ts +0 -1
- package/src/stories/components/ConnectButton/connect-button.tsx +0 -248
- package/src/stories/components/ConnectButton/index.ts +0 -1
- package/src/stories/components/JsonPreview.tsx +0 -84
- package/src/stories/components/Spinner/Spinner.tsx +0 -27
- package/src/stories/components/Spinner/index.ts +0 -1
- package/src/stories/components/StatsCard.tsx +0 -30
- package/src/stories/components/StatusIndicator.tsx +0 -37
- package/src/stories/components/TreeNode.tsx +0 -47
- package/src/stories/components/decorators/function-type.tsx +0 -63
- package/src/stories/components/decorators/index.ts +0 -2
- package/src/stories/components/decorators/wagmi-decorator.tsx +0 -92
- package/src/stories/components/error-block.tsx +0 -21
- package/src/stories/components/index.ts +0 -11
- package/src/stories/constants.ts +0 -3
- package/src/stories/hooks/useConnection.ts +0 -63
- package/src/stories/hooks/useQuery.ts +0 -57
- package/src/tokens/__tests__/token-addresses.test.ts +0 -551
- package/src/tokens/abi/ASSET_ROUTER_ABI.ts +0 -1966
- package/src/tokens/abi/BRIDGE_TOKEN_ADAPTER_ABI.ts +0 -1405
- package/src/tokens/abi/BTCK_ABI.ts +0 -1092
- package/src/tokens/abi/KATANA_BASCULE_ABI.ts +0 -653
- package/src/tokens/abi/LBTC_ABI.json +0 -1761
- package/src/tokens/abi/LBTC_ABI.ts +0 -1761
- package/src/tokens/abi/LBTC_BASCULE_ABI.json +0 -850
- package/src/tokens/abi/NATIVE_LBTC_ABI.ts +0 -1147
- package/src/tokens/abi/STLBTC_ABI.ts +0 -1062
- package/src/tokens/cross-chain-addresses.stories.tsx +0 -236
- package/src/tokens/denomination-utils.stories.tsx +0 -176
- package/src/tokens/getLbtcContractAddresses.stories.tsx +0 -158
- package/src/tokens/getTokenByAddress.stories.tsx +0 -172
- package/src/tokens/getTokenContractInfo.stories.tsx +0 -148
- package/src/tokens/getTokenInfo.stories.tsx +0 -133
- package/src/tokens/isUpgradedContract.stories.tsx +0 -124
- package/src/tokens/lbtc-addresses.ts +0 -18
- package/src/tokens/token-addresses.ts +0 -477
- package/src/tokens/tokens.ts +0 -249
- package/src/tokens/types.ts +0 -80
- package/src/utils/array.ts +0 -31
- package/src/utils/block.ts +0 -23
- package/src/utils/chain.ts +0 -152
- package/src/utils/consoleLogger.ts +0 -140
- package/src/utils/ensureNotSanctionedAddress.ts +0 -11
- package/src/utils/env.ts +0 -20
- package/src/utils/err.ts +0 -83
- package/src/utils/evmAccount.ts +0 -47
- package/src/utils/gas.ts +0 -36
- package/src/utils/hex.ts +0 -9
- package/src/utils/http.ts +0 -224
- package/src/utils/numbers.ts +0 -37
- package/src/utils/pagination.ts +0 -70
- package/src/utils/satoshi.ts +0 -41
- package/src/utils/time.ts +0 -12
- package/src/utils/transaction-executor.ts +0 -299
- package/src/vaults/abi/SILO_VAULT_SPENDER_ABI.json +0 -793
- package/src/vaults/abi/VEDA_VAULT_ABI.json +0 -452
- package/src/vaults/abi/VEDA_VAULT_ACCOUNTANT_ABI.json +0 -591
- package/src/vaults/abi/VEDA_VAULT_BASE_ASSET_ABI.json +0 -296
- package/src/vaults/abi/VEDA_VAULT_BORING_WITHDRAW_QUEUE_ABI.json +0 -502
- package/src/vaults/abi/VEDA_VAULT_LENS_ABI.json +0 -175
- package/src/vaults/abi/VEDA_VAULT_SPENDER_ABI.json +0 -408
- package/src/vaults/abi/VEDA_VAULT_TELLER_ABI.json +0 -700
- package/src/vaults/abi/index.ts +0 -4
- package/src/vaults/index.ts +0 -46
- package/src/vaults/lib/config.ts +0 -184
- package/src/vaults/lib/metrics/get-vault-apy.stories.tsx +0 -58
- package/src/vaults/lib/metrics/get-vault-apy.ts +0 -176
- package/src/vaults/lib/metrics/get-vault-points.stories.tsx +0 -60
- package/src/vaults/lib/metrics/get-vault-points.ts +0 -74
- package/src/vaults/lib/metrics/get-vault-tvl.stories.tsx +0 -58
- package/src/vaults/lib/metrics/get-vault-tvl.ts +0 -121
- package/src/vaults/lib/ops/cancel-withdraw.stories.tsx +0 -80
- package/src/vaults/lib/ops/deposit.stories.tsx +0 -82
- package/src/vaults/lib/ops/deposit.ts +0 -152
- package/src/vaults/lib/ops/get-vault-deposits.stories.tsx +0 -65
- package/src/vaults/lib/ops/get-vault-deposits.ts +0 -209
- package/src/vaults/lib/ops/get-vault-withdrawals.stories.tsx +0 -67
- package/src/vaults/lib/ops/get-vault-withdrawals.ts +0 -349
- package/src/vaults/lib/ops/withdraw.stories.tsx +0 -82
- package/src/vaults/lib/ops/withdraw.ts +0 -225
- package/src/version.ts +0 -56
- package/src/vite-env.d.ts +0 -1
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* EVM Chain Switching Utility
|
|
3
|
-
*
|
|
4
|
-
* Helper to ensure wallet is on the correct chain before signing.
|
|
5
|
-
* Uses EIP-3326 (wallet_switchEthereumChain) and EIP-3085 (wallet_addEthereumChain).
|
|
6
|
-
*
|
|
7
|
-
* @module shared/evm/switchChain
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import type { EIP1193Provider } from 'viem';
|
|
11
|
-
|
|
12
|
-
import { addChain, type ChainId } from '../../common/chains';
|
|
13
|
-
import { LombardError, ValidationErrorCode } from '../errors';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Request to switch wallet to the target chain
|
|
17
|
-
* If chain is not available, attempts to add it first.
|
|
18
|
-
*
|
|
19
|
-
* @param provider - EIP-1193 provider
|
|
20
|
-
* @param targetChainId - Chain ID to switch to
|
|
21
|
-
* @throws LombardError if chain switching fails
|
|
22
|
-
*/
|
|
23
|
-
export async function requestChainSwitch(
|
|
24
|
-
provider: EIP1193Provider,
|
|
25
|
-
targetChainId: ChainId,
|
|
26
|
-
): Promise<void> {
|
|
27
|
-
try {
|
|
28
|
-
await provider.request({
|
|
29
|
-
method: 'wallet_switchEthereumChain',
|
|
30
|
-
params: [{ chainId: `0x${targetChainId.toString(16)}` }],
|
|
31
|
-
});
|
|
32
|
-
} catch (error) {
|
|
33
|
-
const err = error as { code?: number; message?: string };
|
|
34
|
-
|
|
35
|
-
// 4902 = chain not added - try to add it automatically
|
|
36
|
-
if (err.code === 4902) {
|
|
37
|
-
try {
|
|
38
|
-
await addChain({ provider, chainId: targetChainId });
|
|
39
|
-
// After adding, try to switch again
|
|
40
|
-
await provider.request({
|
|
41
|
-
method: 'wallet_switchEthereumChain',
|
|
42
|
-
params: [{ chainId: `0x${targetChainId.toString(16)}` }],
|
|
43
|
-
});
|
|
44
|
-
return;
|
|
45
|
-
} catch (addError) {
|
|
46
|
-
const addErr = addError as { code?: number; message?: string };
|
|
47
|
-
|
|
48
|
-
// User rejected adding chain
|
|
49
|
-
if (addErr.code === 4001) {
|
|
50
|
-
throw new LombardError(
|
|
51
|
-
ValidationErrorCode.INVALID_PARAMETER,
|
|
52
|
-
'User rejected adding chain to wallet.',
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
throw new LombardError(
|
|
57
|
-
ValidationErrorCode.INVALID_CHAIN,
|
|
58
|
-
`Failed to add chain ${targetChainId} to wallet: ${addErr.message || 'Unknown error'}`,
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// User rejected
|
|
64
|
-
if (err.code === 4001) {
|
|
65
|
-
throw new LombardError(
|
|
66
|
-
ValidationErrorCode.INVALID_PARAMETER,
|
|
67
|
-
'User rejected chain switch request.',
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
throw new LombardError(
|
|
72
|
-
ValidationErrorCode.INVALID_CHAIN,
|
|
73
|
-
`Failed to switch to chain ${targetChainId}: ${err.message || 'Unknown error'}`,
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Get current chain ID from wallet
|
|
80
|
-
*
|
|
81
|
-
* @param provider - EIP-1193 provider
|
|
82
|
-
* @returns Current chain ID as number
|
|
83
|
-
*/
|
|
84
|
-
export async function getCurrentChainId(
|
|
85
|
-
provider: EIP1193Provider,
|
|
86
|
-
): Promise<number> {
|
|
87
|
-
const chainIdHex = (await provider.request({
|
|
88
|
-
method: 'eth_chainId',
|
|
89
|
-
})) as string;
|
|
90
|
-
return parseInt(chainIdHex, 16);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Ensure wallet is on the correct chain, switching if necessary
|
|
95
|
-
*
|
|
96
|
-
* @param provider - EIP-1193 provider
|
|
97
|
-
* @param targetChainId - Required chain ID
|
|
98
|
-
* @throws LombardError if chain switching fails
|
|
99
|
-
*/
|
|
100
|
-
export async function ensureCorrectChain(
|
|
101
|
-
provider: EIP1193Provider,
|
|
102
|
-
targetChainId: ChainId,
|
|
103
|
-
): Promise<void> {
|
|
104
|
-
const currentChainId = await getCurrentChainId(provider);
|
|
105
|
-
|
|
106
|
-
if (currentChainId !== targetChainId) {
|
|
107
|
-
await requestChainSwitch(provider, targetChainId);
|
|
108
|
-
}
|
|
109
|
-
}
|
package/src/shared/index.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared utilities for the Lombard SDK
|
|
3
|
-
*
|
|
4
|
-
* This module exports events, errors, monitoring utilities, and validation schemas.
|
|
5
|
-
* For types like Chain, AssetId, etc., import from '@lombard.finance/sdk/core'.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
// Events
|
|
9
|
-
export * from './events';
|
|
10
|
-
|
|
11
|
-
// Errors
|
|
12
|
-
export * from './errors';
|
|
13
|
-
|
|
14
|
-
// Deposit utilities
|
|
15
|
-
export {
|
|
16
|
-
calcConfirmations,
|
|
17
|
-
type ConfirmationProgress,
|
|
18
|
-
depositRequiresAction,
|
|
19
|
-
type DepositStatus,
|
|
20
|
-
type DepositStatusDisplay,
|
|
21
|
-
getConfirmationProgress,
|
|
22
|
-
getDepositStatus,
|
|
23
|
-
getDepositStatusDisplay,
|
|
24
|
-
isDepositClaimable,
|
|
25
|
-
isDepositPending,
|
|
26
|
-
isDepositTerminal,
|
|
27
|
-
MIN_CLAIM_AMOUNT_BTC,
|
|
28
|
-
REQUIRED_CONFIRMATIONS,
|
|
29
|
-
type StatusSeverity,
|
|
30
|
-
} from './deposits';
|
|
31
|
-
|
|
32
|
-
// Monitoring utilities
|
|
33
|
-
export {
|
|
34
|
-
createPollingMonitor,
|
|
35
|
-
type DepositInfo,
|
|
36
|
-
monitorDeposit,
|
|
37
|
-
type MonitorOptions,
|
|
38
|
-
type MonitorProgress,
|
|
39
|
-
} from './monitoring';
|
|
40
|
-
|
|
41
|
-
// Validation schemas (selective exports for public API)
|
|
42
|
-
export {
|
|
43
|
-
addressSchemasByChainType,
|
|
44
|
-
bitcoinAddressSchema,
|
|
45
|
-
// Schemas
|
|
46
|
-
btcAmountSchema,
|
|
47
|
-
evmAddressSchema,
|
|
48
|
-
solanaAddressSchema,
|
|
49
|
-
starknetAddressSchema,
|
|
50
|
-
suiAddressSchema,
|
|
51
|
-
// Helpers
|
|
52
|
-
validate,
|
|
53
|
-
validateOrThrow,
|
|
54
|
-
} from './validation';
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for strongly-typed event emitter factory
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
6
|
-
|
|
7
|
-
import type { StrategyProgress } from '../../../core/types';
|
|
8
|
-
import { DepositEvent, type DepositEventMap } from '../../events';
|
|
9
|
-
import { createEventEmitter } from '../createEventEmitter';
|
|
10
|
-
|
|
11
|
-
describe('createEventEmitter', () => {
|
|
12
|
-
it('should create an event emitter', () => {
|
|
13
|
-
const emitter = createEventEmitter<DepositEventMap>();
|
|
14
|
-
expect(emitter).toBeDefined();
|
|
15
|
-
expect(typeof emitter.on).toBe('function');
|
|
16
|
-
expect(typeof emitter.emit).toBe('function');
|
|
17
|
-
expect(typeof emitter.off).toBe('function');
|
|
18
|
-
expect(typeof emitter.clear).toBe('function');
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('should register and call event handlers', () => {
|
|
22
|
-
const emitter = createEventEmitter<DepositEventMap>();
|
|
23
|
-
const handler = vi.fn();
|
|
24
|
-
|
|
25
|
-
emitter.on(DepositEvent.StatusChange, handler);
|
|
26
|
-
emitter.emit(DepositEvent.StatusChange, 'ready');
|
|
27
|
-
|
|
28
|
-
expect(handler).toHaveBeenCalledOnce();
|
|
29
|
-
expect(handler).toHaveBeenCalledWith('ready');
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('should support multiple handlers for same event', () => {
|
|
33
|
-
const emitter = createEventEmitter<DepositEventMap>();
|
|
34
|
-
const handler1 = vi.fn();
|
|
35
|
-
const handler2 = vi.fn();
|
|
36
|
-
|
|
37
|
-
emitter.on(DepositEvent.Completed, handler1);
|
|
38
|
-
emitter.on(DepositEvent.Completed, handler2);
|
|
39
|
-
emitter.emit(DepositEvent.Completed);
|
|
40
|
-
|
|
41
|
-
expect(handler1).toHaveBeenCalledOnce();
|
|
42
|
-
expect(handler2).toHaveBeenCalledOnce();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('should remove specific handler with off()', () => {
|
|
46
|
-
const emitter = createEventEmitter<DepositEventMap>();
|
|
47
|
-
const handler1 = vi.fn();
|
|
48
|
-
const handler2 = vi.fn();
|
|
49
|
-
|
|
50
|
-
const unsub1 = emitter.on(DepositEvent.Completed, handler1);
|
|
51
|
-
emitter.on(DepositEvent.Completed, handler2);
|
|
52
|
-
|
|
53
|
-
unsub1(); // Remove first handler
|
|
54
|
-
emitter.emit(DepositEvent.Completed);
|
|
55
|
-
|
|
56
|
-
expect(handler1).not.toHaveBeenCalled();
|
|
57
|
-
expect(handler2).toHaveBeenCalledOnce();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('should remove handler with returned unsubscribe function', () => {
|
|
61
|
-
const emitter = createEventEmitter<DepositEventMap>();
|
|
62
|
-
const handler = vi.fn();
|
|
63
|
-
|
|
64
|
-
const unsubscribe = emitter.on(DepositEvent.StatusChange, handler);
|
|
65
|
-
unsubscribe();
|
|
66
|
-
emitter.emit(DepositEvent.StatusChange, 'ready');
|
|
67
|
-
|
|
68
|
-
expect(handler).not.toHaveBeenCalled();
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('should clear all handlers', () => {
|
|
72
|
-
const emitter = createEventEmitter<DepositEventMap>();
|
|
73
|
-
const handler1 = vi.fn();
|
|
74
|
-
const handler2 = vi.fn();
|
|
75
|
-
const handler3 = vi.fn();
|
|
76
|
-
|
|
77
|
-
emitter.on(DepositEvent.StatusChange, handler1);
|
|
78
|
-
emitter.on(DepositEvent.Completed, handler2);
|
|
79
|
-
emitter.on(DepositEvent.Progress, handler3);
|
|
80
|
-
|
|
81
|
-
emitter.clear();
|
|
82
|
-
|
|
83
|
-
emitter.emit(DepositEvent.StatusChange, 'ready');
|
|
84
|
-
emitter.emit(DepositEvent.Completed);
|
|
85
|
-
emitter.emit(DepositEvent.Progress, { status: 'ready', steps: {} });
|
|
86
|
-
|
|
87
|
-
expect(handler1).not.toHaveBeenCalled();
|
|
88
|
-
expect(handler2).not.toHaveBeenCalled();
|
|
89
|
-
expect(handler3).not.toHaveBeenCalled();
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('should handle progress events with correct types', () => {
|
|
93
|
-
const emitter = createEventEmitter<DepositEventMap>();
|
|
94
|
-
const handler = vi.fn((progress: StrategyProgress<string>) => {
|
|
95
|
-
expect(progress.status).toBeDefined();
|
|
96
|
-
expect(progress.steps).toBeDefined();
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
emitter.on(DepositEvent.Progress, handler);
|
|
100
|
-
emitter.emit(DepositEvent.Progress, {
|
|
101
|
-
status: 'executing',
|
|
102
|
-
steps: {
|
|
103
|
-
approval: 'complete',
|
|
104
|
-
execution: 'pending',
|
|
105
|
-
},
|
|
106
|
-
confirmations: 2,
|
|
107
|
-
requiredConfirmations: 6,
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
expect(handler).toHaveBeenCalledOnce();
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('should not throw if emitting with no handlers', () => {
|
|
114
|
-
const emitter = createEventEmitter<DepositEventMap>();
|
|
115
|
-
|
|
116
|
-
expect(() => {
|
|
117
|
-
emitter.emit(DepositEvent.Completed);
|
|
118
|
-
emitter.emit(DepositEvent.StatusChange, 'ready');
|
|
119
|
-
}).not.toThrow();
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('should handle handler errors gracefully', () => {
|
|
123
|
-
// Mock console.error to suppress expected error output
|
|
124
|
-
const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
125
|
-
|
|
126
|
-
const emitter = createEventEmitter<DepositEventMap>();
|
|
127
|
-
const errorHandler = vi.fn(() => {
|
|
128
|
-
throw new Error('Handler error');
|
|
129
|
-
});
|
|
130
|
-
const normalHandler = vi.fn();
|
|
131
|
-
|
|
132
|
-
emitter.on(DepositEvent.Completed, errorHandler);
|
|
133
|
-
emitter.on(DepositEvent.Completed, normalHandler);
|
|
134
|
-
|
|
135
|
-
// Should not throw and should still call other handlers
|
|
136
|
-
expect(() => {
|
|
137
|
-
emitter.emit(DepositEvent.Completed);
|
|
138
|
-
}).not.toThrow();
|
|
139
|
-
|
|
140
|
-
expect(errorHandler).toHaveBeenCalled();
|
|
141
|
-
expect(normalHandler).toHaveBeenCalled();
|
|
142
|
-
// Verify error was logged
|
|
143
|
-
expect(consoleSpy).toHaveBeenCalledWith(
|
|
144
|
-
'Error in event handler for "completed":',
|
|
145
|
-
expect.any(Error),
|
|
146
|
-
);
|
|
147
|
-
|
|
148
|
-
consoleSpy.mockRestore();
|
|
149
|
-
});
|
|
150
|
-
});
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Strongly-typed event emitter factory
|
|
3
|
-
*
|
|
4
|
-
* Creates lightweight event emitters with full TypeScript type safety.
|
|
5
|
-
* Unlike EventEmitter3, this implementation:
|
|
6
|
-
* - Is specifically tailored for strategy events
|
|
7
|
-
* - Has minimal overhead
|
|
8
|
-
* - Provides perfect type inference
|
|
9
|
-
* - Handles errors gracefully
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Event handler function type
|
|
14
|
-
*/
|
|
15
|
-
export type EventHandler<TArgs extends unknown[] = unknown[]> = (
|
|
16
|
-
...args: TArgs
|
|
17
|
-
) => void;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Event emitter interface
|
|
21
|
-
*/
|
|
22
|
-
export interface EventEmitter<
|
|
23
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Event emitter requires bivariant `any` for generic event handler constraint
|
|
24
|
-
TEventMap extends Record<string, EventHandler<any>>,
|
|
25
|
-
> {
|
|
26
|
-
/**
|
|
27
|
-
* Register an event handler
|
|
28
|
-
*
|
|
29
|
-
* @param event - Event name
|
|
30
|
-
* @param handler - Handler function
|
|
31
|
-
* @returns Unsubscribe function
|
|
32
|
-
*/
|
|
33
|
-
on<TEvent extends keyof TEventMap>(
|
|
34
|
-
event: TEvent,
|
|
35
|
-
handler: TEventMap[TEvent],
|
|
36
|
-
): () => void;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Emit an event to all registered handlers
|
|
40
|
-
*
|
|
41
|
-
* @param event - Event name
|
|
42
|
-
* @param data - Event data (if any)
|
|
43
|
-
*/
|
|
44
|
-
emit<TEvent extends keyof TEventMap>(
|
|
45
|
-
event: TEvent,
|
|
46
|
-
...args: Parameters<TEventMap[TEvent]>
|
|
47
|
-
): void;
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Remove a specific event handler
|
|
51
|
-
*
|
|
52
|
-
* @param event - Event name
|
|
53
|
-
* @param handler - Handler function to remove
|
|
54
|
-
*/
|
|
55
|
-
off<TEvent extends keyof TEventMap>(
|
|
56
|
-
event: TEvent,
|
|
57
|
-
handler: TEventMap[TEvent],
|
|
58
|
-
): void;
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Clear all event handlers
|
|
62
|
-
*/
|
|
63
|
-
clear(): void;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Create a strongly-typed event emitter
|
|
68
|
-
*
|
|
69
|
-
* @returns Event emitter instance
|
|
70
|
-
*
|
|
71
|
-
* @example
|
|
72
|
-
* ```typescript
|
|
73
|
-
* const emitter = createEventEmitter<DepositEventMap>();
|
|
74
|
-
*
|
|
75
|
-
* // Register handler
|
|
76
|
-
* const unsubscribe = emitter.on(DepositEvent.Progress, (progress) => {
|
|
77
|
-
* console.log(progress.status);
|
|
78
|
-
* });
|
|
79
|
-
*
|
|
80
|
-
* // Emit event
|
|
81
|
-
* emitter.emit(DepositEvent.Progress, { status: 'ready', steps: {} });
|
|
82
|
-
*
|
|
83
|
-
* // Unsubscribe
|
|
84
|
-
* unsubscribe();
|
|
85
|
-
* ```
|
|
86
|
-
*/
|
|
87
|
-
export function createEventEmitter<
|
|
88
|
-
TEventMap extends Record<string, EventHandler>,
|
|
89
|
-
>(): EventEmitter<TEventMap> {
|
|
90
|
-
// Store handlers in a Map for efficient lookup
|
|
91
|
-
const handlers = new Map<keyof TEventMap, Set<EventHandler>>();
|
|
92
|
-
|
|
93
|
-
return {
|
|
94
|
-
on<TEvent extends keyof TEventMap>(
|
|
95
|
-
event: TEvent,
|
|
96
|
-
handler: TEventMap[TEvent],
|
|
97
|
-
): () => void {
|
|
98
|
-
// Get or create handler set for this event
|
|
99
|
-
let eventHandlers = handlers.get(event);
|
|
100
|
-
if (!eventHandlers) {
|
|
101
|
-
eventHandlers = new Set();
|
|
102
|
-
handlers.set(event, eventHandlers);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// Add handler
|
|
106
|
-
eventHandlers.add(handler as EventHandler);
|
|
107
|
-
|
|
108
|
-
// Return unsubscribe function
|
|
109
|
-
return () => {
|
|
110
|
-
eventHandlers?.delete(handler as EventHandler);
|
|
111
|
-
// Clean up empty sets
|
|
112
|
-
if (eventHandlers && eventHandlers.size === 0) {
|
|
113
|
-
handlers.delete(event);
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
},
|
|
117
|
-
|
|
118
|
-
emit<TEvent extends keyof TEventMap>(
|
|
119
|
-
event: TEvent,
|
|
120
|
-
...args: Parameters<TEventMap[TEvent]>
|
|
121
|
-
): void {
|
|
122
|
-
const eventHandlers = handlers.get(event);
|
|
123
|
-
if (!eventHandlers || eventHandlers.size === 0) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// Call all handlers for this event
|
|
128
|
-
// Wrap in try-catch to prevent one handler from breaking others
|
|
129
|
-
for (const handler of eventHandlers) {
|
|
130
|
-
try {
|
|
131
|
-
handler(...args);
|
|
132
|
-
} catch (error) {
|
|
133
|
-
// Log error but don't throw - one handler failing shouldn't break others
|
|
134
|
-
console.error(
|
|
135
|
-
`Error in event handler for "${String(event)}":`,
|
|
136
|
-
error,
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
},
|
|
141
|
-
|
|
142
|
-
off<TEvent extends keyof TEventMap>(
|
|
143
|
-
event: TEvent,
|
|
144
|
-
handler: TEventMap[TEvent],
|
|
145
|
-
): void {
|
|
146
|
-
const eventHandlers = handlers.get(event);
|
|
147
|
-
if (eventHandlers) {
|
|
148
|
-
eventHandlers.delete(handler as EventHandler);
|
|
149
|
-
// Clean up empty sets
|
|
150
|
-
if (eventHandlers.size === 0) {
|
|
151
|
-
handlers.delete(event);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
},
|
|
155
|
-
|
|
156
|
-
clear(): void {
|
|
157
|
-
handlers.clear();
|
|
158
|
-
},
|
|
159
|
-
};
|
|
160
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Progress Emitter Utility
|
|
3
|
-
*
|
|
4
|
-
* Creates a lightweight event emitter for progress updates.
|
|
5
|
-
* Used by strategy implementations to notify listeners of state changes.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export interface ProgressEmitter<T> {
|
|
9
|
-
subscribe(callback: (progress: T) => void): () => void;
|
|
10
|
-
emit(progress: T): void;
|
|
11
|
-
clear(): void;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Creates a progress emitter
|
|
16
|
-
*
|
|
17
|
-
* @returns ProgressEmitter instance with subscribe, emit, and clear methods
|
|
18
|
-
*/
|
|
19
|
-
export function createProgressEmitter<T>(): ProgressEmitter<T> {
|
|
20
|
-
const listeners = new Set<(progress: T) => void>();
|
|
21
|
-
|
|
22
|
-
return {
|
|
23
|
-
subscribe(callback: (progress: T) => void): () => void {
|
|
24
|
-
listeners.add(callback);
|
|
25
|
-
|
|
26
|
-
// Return unsubscribe function
|
|
27
|
-
return () => {
|
|
28
|
-
listeners.delete(callback);
|
|
29
|
-
};
|
|
30
|
-
},
|
|
31
|
-
|
|
32
|
-
emit(progress: T): void {
|
|
33
|
-
for (const listener of listeners) {
|
|
34
|
-
try {
|
|
35
|
-
listener(progress);
|
|
36
|
-
} catch (error) {
|
|
37
|
-
console.error('Error in progress listener:', error);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
clear(): void {
|
|
43
|
-
listeners.clear();
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
}
|