@lombard.finance/sdk 4.0.0 → 4.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/bridge/lib/ccip-config.d.ts.map +1 -1
- package/dist/bridge/lib/config.d.ts +3 -3
- package/dist/bridge/lib/config.d.ts.map +1 -1
- package/dist/common/chains.d.ts +2 -2
- package/dist/common/chains.d.ts.map +1 -1
- package/dist/common/feature-config.d.ts.map +1 -1
- package/dist/contract-functions/getBasculeDepositStatus/getBasculeDepositStatus.d.ts.map +1 -1
- package/dist/index2.cjs +6 -6
- package/dist/index2.js +792 -759
- package/dist/vaults/lib/config.d.ts +1 -1
- 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,497 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base Action Class
|
|
3
|
-
*
|
|
4
|
-
* Abstract base class for all action implementations.
|
|
5
|
-
* Provides:
|
|
6
|
-
* - Event emission capabilities
|
|
7
|
-
* - Status and error tracking (separated concerns)
|
|
8
|
-
* - Type-safe event handlers
|
|
9
|
-
* - Error handling utilities
|
|
10
|
-
*
|
|
11
|
-
* ## Error Design
|
|
12
|
-
*
|
|
13
|
-
* Status and error are orthogonal concerns:
|
|
14
|
-
* - `status` = "What step are you at?" (IDLE, PREPARING, READY, etc.)
|
|
15
|
-
* - `error` = "Did something go wrong?" (Error | null)
|
|
16
|
-
* - `isFailed` = Derived from `error !== null`
|
|
17
|
-
*
|
|
18
|
-
* When an error occurs:
|
|
19
|
-
* 1. Status stays at the step where error occurred (preserves context)
|
|
20
|
-
* 2. Error is stored and accessible via `error` property
|
|
21
|
-
* 3. `isFailed` returns true
|
|
22
|
-
* 4. Events are emitted for listeners
|
|
23
|
-
*
|
|
24
|
-
* This allows easy retry - just call the method again since status
|
|
25
|
-
* is already at the correct step.
|
|
26
|
-
*
|
|
27
|
-
* @module shared/actions/BaseAction
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
import type { StrategyProgress } from '../../core/types';
|
|
31
|
-
import type { Logger } from '../context/types';
|
|
32
|
-
import { LombardError, ValidationErrorCode, wrapError } from '../errors';
|
|
33
|
-
import {
|
|
34
|
-
createEventEmitter,
|
|
35
|
-
type EventEmitter,
|
|
36
|
-
type EventHandler,
|
|
37
|
-
} from '../monitoring/createEventEmitter';
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Log metadata for structured logging
|
|
41
|
-
*/
|
|
42
|
-
export interface LogMeta {
|
|
43
|
-
/** Action name (e.g., 'BtcStake', 'EvmUnstake') */
|
|
44
|
-
action?: string;
|
|
45
|
-
/** Current step (e.g., 'prepare', 'authorize', 'execute') */
|
|
46
|
-
step?: string;
|
|
47
|
-
/** Current status */
|
|
48
|
-
status?: string;
|
|
49
|
-
/** Operation duration in milliseconds */
|
|
50
|
-
duration?: number;
|
|
51
|
-
/** Error code if applicable */
|
|
52
|
-
errorCode?: string;
|
|
53
|
-
/** Chain identifier */
|
|
54
|
-
chain?: string;
|
|
55
|
-
/** Any additional context */
|
|
56
|
-
[key: string]: unknown;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Monitorable action interface
|
|
61
|
-
*
|
|
62
|
-
* All actions expose this interface for consistent progress tracking.
|
|
63
|
-
*
|
|
64
|
-
* ## Orthogonal Concerns
|
|
65
|
-
* - `status` - Which step in the flow (IDLE, NEEDS_AUTH, READY, etc.)
|
|
66
|
-
* - `isLoading` - Is an async operation in progress
|
|
67
|
-
* - `error` / `isFailed` - Did an error occur
|
|
68
|
-
*/
|
|
69
|
-
export interface MonitorableAction {
|
|
70
|
-
/** Current status of the action (step in the flow) */
|
|
71
|
-
readonly status: string;
|
|
72
|
-
|
|
73
|
-
/** Whether an async operation is in progress */
|
|
74
|
-
readonly isLoading: boolean;
|
|
75
|
-
|
|
76
|
-
/** Error that occurred (if any) - null means no error */
|
|
77
|
-
readonly error: LombardError | null;
|
|
78
|
-
|
|
79
|
-
/** Whether the action has failed (derived from error !== null) */
|
|
80
|
-
readonly isFailed: boolean;
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Register an event handler
|
|
84
|
-
*
|
|
85
|
-
* @param event - Event to listen for
|
|
86
|
-
* @param handler - Handler function
|
|
87
|
-
* @returns Unsubscribe function
|
|
88
|
-
*/
|
|
89
|
-
on<TEvent extends string>(
|
|
90
|
-
event: TEvent,
|
|
91
|
-
handler: (...args: unknown[]) => void,
|
|
92
|
-
): () => void;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Base action abstract class
|
|
97
|
-
*
|
|
98
|
-
* Provides event emission and error handling infrastructure for all actions.
|
|
99
|
-
*
|
|
100
|
-
* ## Error Handling Design
|
|
101
|
-
*
|
|
102
|
-
* Status and error are separate concerns:
|
|
103
|
-
* - On error, status stays at current step (so you know WHERE it failed)
|
|
104
|
-
* - Error is stored and `isFailed` returns true
|
|
105
|
-
* - Retry by calling the same method again
|
|
106
|
-
*
|
|
107
|
-
* @example
|
|
108
|
-
* ```typescript
|
|
109
|
-
* class MyAction extends BaseAction<MyEventMap, MyStatus> {
|
|
110
|
-
* async execute() {
|
|
111
|
-
* this.assertStatus('idle', 'execute');
|
|
112
|
-
* return this.act(
|
|
113
|
-
* async () => {
|
|
114
|
-
* // ... do work ...
|
|
115
|
-
* // isLoading is true during execution
|
|
116
|
-
* this.emitCompleted();
|
|
117
|
-
* },
|
|
118
|
-
* 'completed', // Success status
|
|
119
|
-
* );
|
|
120
|
-
* }
|
|
121
|
-
* }
|
|
122
|
-
* ```
|
|
123
|
-
*/
|
|
124
|
-
export abstract class BaseAction<
|
|
125
|
-
TEventMap extends Record<string, EventHandler<unknown[]>>,
|
|
126
|
-
TStatus extends string,
|
|
127
|
-
> implements MonitorableAction
|
|
128
|
-
{
|
|
129
|
-
/** Event emitter for this action */
|
|
130
|
-
protected readonly eventEmitter: EventEmitter<TEventMap>;
|
|
131
|
-
|
|
132
|
-
/** Current status (step in the flow) */
|
|
133
|
-
private _status: TStatus;
|
|
134
|
-
|
|
135
|
-
/** Tracked error - null means no error */
|
|
136
|
-
protected _error: LombardError | null = null;
|
|
137
|
-
|
|
138
|
-
/** Loading state - true when an async operation is in progress */
|
|
139
|
-
private _isLoading: boolean = false;
|
|
140
|
-
|
|
141
|
-
/** Optional logger for debugging and monitoring */
|
|
142
|
-
protected readonly logger?: Logger;
|
|
143
|
-
|
|
144
|
-
/** Operation timing for performance monitoring */
|
|
145
|
-
private _timing: Map<string, number> = new Map();
|
|
146
|
-
|
|
147
|
-
constructor(initialStatus: TStatus, logger?: Logger) {
|
|
148
|
-
this.eventEmitter = createEventEmitter<TEventMap>();
|
|
149
|
-
this._status = initialStatus;
|
|
150
|
-
this.logger = logger;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
154
|
-
// Logging
|
|
155
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Log a message with context
|
|
159
|
-
*
|
|
160
|
-
* Automatically includes action name and current status.
|
|
161
|
-
* No-op if logger is not configured.
|
|
162
|
-
*
|
|
163
|
-
* Uses explicit switch to avoid dynamic property access (security best practice).
|
|
164
|
-
*/
|
|
165
|
-
protected log(
|
|
166
|
-
level: 'debug' | 'info' | 'warn' | 'error',
|
|
167
|
-
message: string,
|
|
168
|
-
meta?: LogMeta,
|
|
169
|
-
): void {
|
|
170
|
-
if (!this.logger) return;
|
|
171
|
-
|
|
172
|
-
const enrichedMeta: LogMeta = {
|
|
173
|
-
action: this.constructor.name,
|
|
174
|
-
status: this._status,
|
|
175
|
-
...meta,
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
// Explicit method calls to avoid unsafe-dynamic-method security warning
|
|
179
|
-
switch (level) {
|
|
180
|
-
case 'debug':
|
|
181
|
-
this.logger.debug(message, enrichedMeta);
|
|
182
|
-
break;
|
|
183
|
-
case 'info':
|
|
184
|
-
this.logger.info(message, enrichedMeta);
|
|
185
|
-
break;
|
|
186
|
-
case 'warn':
|
|
187
|
-
this.logger.warn(message, enrichedMeta);
|
|
188
|
-
break;
|
|
189
|
-
case 'error':
|
|
190
|
-
this.logger.error(message, enrichedMeta);
|
|
191
|
-
break;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Get timing for an operation
|
|
197
|
-
*/
|
|
198
|
-
public getTiming(operation: string): number | undefined {
|
|
199
|
-
return this._timing.get(operation);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Get all operation timings
|
|
204
|
-
*/
|
|
205
|
-
public getAllTimings(): Record<string, number> {
|
|
206
|
-
return Object.fromEntries(this._timing);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Record timing for an operation
|
|
211
|
-
*/
|
|
212
|
-
protected recordTiming(operation: string, duration: number): void {
|
|
213
|
-
this._timing.set(operation, duration);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
217
|
-
// Public Getters
|
|
218
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
219
|
-
|
|
220
|
-
/** Current action status (which step in the flow) */
|
|
221
|
-
get status(): TStatus {
|
|
222
|
-
return this._status;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/** Error that occurred (if any) - null means no error */
|
|
226
|
-
get error(): LombardError | null {
|
|
227
|
-
return this._error;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/** Whether the action has failed (derived from error !== null) */
|
|
231
|
-
get isFailed(): boolean {
|
|
232
|
-
return this._error !== null;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/** Whether an async operation is in progress */
|
|
236
|
-
get isLoading(): boolean {
|
|
237
|
-
return this._isLoading;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
241
|
-
// Status Management
|
|
242
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Update the action status and emit status-change event
|
|
246
|
-
*/
|
|
247
|
-
protected updateStatus(status: TStatus): void {
|
|
248
|
-
this._status = status;
|
|
249
|
-
this.emitStatusChange(status);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Assert the action is in an expected status
|
|
254
|
-
*
|
|
255
|
-
* @param expected - Single status or array of allowed statuses
|
|
256
|
-
* @param action - Name of the action being performed (for error message)
|
|
257
|
-
* @throws LombardError if current status is not in expected list
|
|
258
|
-
*/
|
|
259
|
-
protected assertStatus(expected: TStatus | TStatus[], action: string): void {
|
|
260
|
-
const allowed = Array.isArray(expected) ? expected : [expected];
|
|
261
|
-
if (!allowed.includes(this._status)) {
|
|
262
|
-
throw new LombardError(
|
|
263
|
-
ValidationErrorCode.INVALID_STATE,
|
|
264
|
-
`Cannot ${action} while status is ${this._status}, allowed: ${allowed.join(', ')}`,
|
|
265
|
-
);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
270
|
-
// Error Handling
|
|
271
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* Clear any previous error
|
|
275
|
-
*
|
|
276
|
-
* Call this at the start of retry attempts to reset error state.
|
|
277
|
-
*/
|
|
278
|
-
protected clearError(): void {
|
|
279
|
-
this._error = null;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* Handle action failure
|
|
284
|
-
*
|
|
285
|
-
* Stores error, emits events, and throws.
|
|
286
|
-
* Status is NOT changed - it stays at the step where the error occurred.
|
|
287
|
-
* This allows callers to know exactly where the failure happened.
|
|
288
|
-
*
|
|
289
|
-
* @param error - The error that occurred
|
|
290
|
-
* @throws The wrapped LombardError
|
|
291
|
-
*/
|
|
292
|
-
protected handleFailure(error: unknown): never {
|
|
293
|
-
this._error = error instanceof LombardError ? error : wrapError(error);
|
|
294
|
-
this.emitError(this._error);
|
|
295
|
-
this.emitFailed();
|
|
296
|
-
throw this._error;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* Set loading state and emit event
|
|
301
|
-
*/
|
|
302
|
-
protected setLoading(loading: boolean): void {
|
|
303
|
-
this._isLoading = loading;
|
|
304
|
-
this.emitLoading(loading);
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
/**
|
|
308
|
-
* Perform an async operation with automatic state management
|
|
309
|
-
*
|
|
310
|
-
* This is the primary method for wrapping async operations in actions.
|
|
311
|
-
* Handles loading state, errors, and status transitions automatically.
|
|
312
|
-
*
|
|
313
|
-
* ## Automatic Behaviors
|
|
314
|
-
*
|
|
315
|
-
* - **isLoading**: Set to true before operation, false after (success or failure)
|
|
316
|
-
* - **error**: Cleared on start, set on failure
|
|
317
|
-
* - **status**: Optionally transitions to `successStatus` on success
|
|
318
|
-
*
|
|
319
|
-
* ## Design Philosophy: Orthogonal Concerns
|
|
320
|
-
*
|
|
321
|
-
* Status, loading, and error are independent:
|
|
322
|
-
* - `status` = "What step are you at?" (IDLE, NEEDS_AUTH, READY, etc.)
|
|
323
|
-
* - `isLoading` = "Is an operation in progress?" (true/false)
|
|
324
|
-
* - `error` = "Did something go wrong?" (Error | null)
|
|
325
|
-
*
|
|
326
|
-
* No transitional statuses (PREPARING, AUTHORIZING, etc.) needed!
|
|
327
|
-
* The UI can derive the display state:
|
|
328
|
-
* - IDLE + isLoading → "Preparing..."
|
|
329
|
-
* - NEEDS_AUTH + isLoading → "Authorizing..."
|
|
330
|
-
* - READY + isLoading → "Generating..."
|
|
331
|
-
*
|
|
332
|
-
* @param fn - Async function to execute
|
|
333
|
-
* @param successStatus - Status to transition to on success (optional)
|
|
334
|
-
* @returns Result of the operation
|
|
335
|
-
*
|
|
336
|
-
* @example Simple operation (no status change)
|
|
337
|
-
* ```typescript
|
|
338
|
-
* async execute() {
|
|
339
|
-
* return this.act(async () => {
|
|
340
|
-
* return this.depositAddress;
|
|
341
|
-
* });
|
|
342
|
-
* }
|
|
343
|
-
* ```
|
|
344
|
-
*
|
|
345
|
-
* @example Operation with status transition
|
|
346
|
-
* ```typescript
|
|
347
|
-
* async authorize(): Promise<void> {
|
|
348
|
-
* this.assertStatus([Status.NEEDS_AUTH, Status.READY], 'authorize');
|
|
349
|
-
* if (this.status === Status.READY) return;
|
|
350
|
-
*
|
|
351
|
-
* return this.act(
|
|
352
|
-
* async () => {
|
|
353
|
-
* const result = await this.signTransaction();
|
|
354
|
-
* this.authState.signature = result.signature;
|
|
355
|
-
* },
|
|
356
|
-
* Status.READY
|
|
357
|
-
* );
|
|
358
|
-
* }
|
|
359
|
-
* ```
|
|
360
|
-
*
|
|
361
|
-
* @example Flow visualization
|
|
362
|
-
* ```
|
|
363
|
-
* Success flow:
|
|
364
|
-
* status: NEEDS_AUTH -> NEEDS_AUTH -> READY
|
|
365
|
-
* isLoading: false -> true -> false
|
|
366
|
-
*
|
|
367
|
-
* Failure flow:
|
|
368
|
-
* status: NEEDS_AUTH -> NEEDS_AUTH (unchanged!)
|
|
369
|
-
* isLoading: false -> true -> false
|
|
370
|
-
* error: null -> "User rejected"
|
|
371
|
-
* ```
|
|
372
|
-
*/
|
|
373
|
-
protected async act<T>(
|
|
374
|
-
fn: () => Promise<T>,
|
|
375
|
-
successStatus?: TStatus,
|
|
376
|
-
): Promise<T> {
|
|
377
|
-
const startTime = performance.now();
|
|
378
|
-
const operationName = successStatus ?? 'operation';
|
|
379
|
-
|
|
380
|
-
this.log('debug', `Starting ${operationName}`, { step: String(operationName) });
|
|
381
|
-
this.clearError();
|
|
382
|
-
this.setLoading(true);
|
|
383
|
-
|
|
384
|
-
try {
|
|
385
|
-
const result = await fn();
|
|
386
|
-
const duration = performance.now() - startTime;
|
|
387
|
-
|
|
388
|
-
this.recordTiming(String(operationName), duration);
|
|
389
|
-
this.log('info', `Completed ${operationName}`, {
|
|
390
|
-
step: String(operationName),
|
|
391
|
-
duration: Math.round(duration),
|
|
392
|
-
});
|
|
393
|
-
|
|
394
|
-
if (successStatus !== undefined) {
|
|
395
|
-
this.updateStatus(successStatus);
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
return result;
|
|
399
|
-
} catch (error) {
|
|
400
|
-
const duration = performance.now() - startTime;
|
|
401
|
-
const lombError = error instanceof LombardError ? error : wrapError(error);
|
|
402
|
-
|
|
403
|
-
this.recordTiming(String(operationName), duration);
|
|
404
|
-
this.log('error', `Failed ${operationName}`, {
|
|
405
|
-
step: String(operationName),
|
|
406
|
-
duration: Math.round(duration),
|
|
407
|
-
errorCode: lombError.code,
|
|
408
|
-
errorMessage: lombError.message,
|
|
409
|
-
});
|
|
410
|
-
|
|
411
|
-
return this.handleFailure(error);
|
|
412
|
-
} finally {
|
|
413
|
-
this.setLoading(false);
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
418
|
-
// Event Handlers
|
|
419
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
420
|
-
|
|
421
|
-
/**
|
|
422
|
-
* Register an event handler
|
|
423
|
-
*
|
|
424
|
-
* @param event - Event to listen for
|
|
425
|
-
* @param handler - Handler function
|
|
426
|
-
* @returns Unsubscribe function
|
|
427
|
-
*/
|
|
428
|
-
on<TEvent extends keyof TEventMap>(
|
|
429
|
-
event: TEvent,
|
|
430
|
-
handler: TEventMap[TEvent],
|
|
431
|
-
): () => void {
|
|
432
|
-
return this.eventEmitter.on(event, handler);
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
436
|
-
// Event Emission
|
|
437
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
438
|
-
|
|
439
|
-
/** Emit a progress update */
|
|
440
|
-
protected emitProgress(progress: StrategyProgress<TStatus>): void {
|
|
441
|
-
(
|
|
442
|
-
this.eventEmitter as unknown as EventEmitter<
|
|
443
|
-
Record<'progress', EventHandler<[StrategyProgress<TStatus>]>>
|
|
444
|
-
>
|
|
445
|
-
).emit('progress', progress);
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
/** Emit a status change */
|
|
449
|
-
protected emitStatusChange(status: TStatus): void {
|
|
450
|
-
(
|
|
451
|
-
this.eventEmitter as unknown as EventEmitter<
|
|
452
|
-
Record<'status-change', EventHandler<[TStatus]>>
|
|
453
|
-
>
|
|
454
|
-
).emit('status-change', status);
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
/** Emit completion event */
|
|
458
|
-
protected emitCompleted(): void {
|
|
459
|
-
(
|
|
460
|
-
this.eventEmitter as unknown as EventEmitter<
|
|
461
|
-
Record<'completed', EventHandler<[]>>
|
|
462
|
-
>
|
|
463
|
-
).emit('completed');
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
/** Emit failed event */
|
|
467
|
-
protected emitFailed(): void {
|
|
468
|
-
(
|
|
469
|
-
this.eventEmitter as unknown as EventEmitter<
|
|
470
|
-
Record<'failed', EventHandler<[]>>
|
|
471
|
-
>
|
|
472
|
-
).emit('failed');
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
/** Emit error event */
|
|
476
|
-
protected emitError(error: LombardError): void {
|
|
477
|
-
(
|
|
478
|
-
this.eventEmitter as unknown as EventEmitter<
|
|
479
|
-
Record<'error', EventHandler<[LombardError]>>
|
|
480
|
-
>
|
|
481
|
-
).emit('error', error);
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
/** Emit loading state change */
|
|
485
|
-
protected emitLoading(isLoading: boolean): void {
|
|
486
|
-
(
|
|
487
|
-
this.eventEmitter as unknown as EventEmitter<
|
|
488
|
-
Record<'loading', EventHandler<[boolean]>>
|
|
489
|
-
>
|
|
490
|
-
).emit('loading', isLoading);
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
/** Clear all event listeners */
|
|
494
|
-
protected clearListeners(): void {
|
|
495
|
-
this.eventEmitter.clear();
|
|
496
|
-
}
|
|
497
|
-
}
|