@lombard.finance/sdk 2.5.2 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +483 -396
- package/dist/ccip.cjs +2 -0
- package/dist/ccip.cjs.map +1 -0
- package/dist/ccip.js +147 -0
- package/dist/ccip.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +79 -8269
- package/dist/index.js.map +1 -1
- package/dist/index2.cjs +63 -0
- package/dist/index2.cjs.map +1 -0
- package/dist/index2.js +17989 -0
- package/dist/index2.js.map +1 -0
- package/package.json +10 -10
- package/src/{sdk → api-functions}/generateDepositBtcAddress/generateDepositBtcAddress.stories.tsx +15 -14
- package/src/{sdk → api-functions}/generateDepositBtcAddress/generateDepositBtcAddress.ts +18 -8
- package/src/{sdk → api-functions}/getDepositBtcAddress/getDepositBtcAddress.stories.tsx +23 -14
- package/src/{sdk → api-functions}/getDepositBtcAddress/getDepositBtcAddress.ts +16 -7
- package/src/{sdk → api-functions}/getDepositBtcAddress/getDepositBtcAddresses.stories.tsx +15 -14
- package/src/{sdk → api-functions}/getDepositsByAddress/getDepositsByAddress.stories.tsx +13 -12
- package/src/{sdk → api-functions}/getDepositsByAddress/getDepositsByAddress.ts +9 -9
- package/src/{sdk → api-functions}/getLBTCExchangeRate/getLBTCExchangeRate.stories.tsx +16 -10
- package/src/api-functions/getLBTCExchangeRate/getLBTCExchangeRate.ts +71 -0
- package/src/api-functions/getNetworkFeeSignature/getNetworkFeeSignature.stories.tsx +56 -0
- package/src/{sdk → api-functions}/getNetworkFeeSignature/getNetworkFeeSignature.ts +11 -5
- package/src/{sdk → api-functions}/getPointsByAddress/getPointsByAddress.stories.tsx +14 -13
- package/src/{sdk → api-functions}/getPointsByAddress/getPointsByAddress.ts +7 -4
- package/src/{sdk → api-functions}/getUnstakesByAddress/getUnstakesByAddress.stories.tsx +14 -13
- package/src/{sdk → api-functions}/getUnstakesByAddress/getUnstakesByAddress.ts +15 -10
- package/src/api-functions/getUserStakeAndBakeSignature/getUserStakeAndBakeSignature.stories.tsx +69 -0
- package/src/{sdk → api-functions}/getUserStakeAndBakeSignature/getUserStakeAndBakeSignature.ts +10 -6
- package/src/{sdk → api-functions}/index.ts +0 -3
- package/src/{sdk → api-functions}/setReferral/setReferral.ts +3 -3
- package/src/api-functions/storeNetworkFeeSignature/storeNetworkFeeSignature.stories.tsx +56 -0
- package/src/{sdk → api-functions}/storeNetworkFeeSignature/storeNetworkFeeSignature.ts +9 -7
- package/src/api-functions/storeStakeAndBakeSignature/storeStakeAndBakeSignature.stories.tsx +56 -0
- package/src/{sdk → api-functions}/storeStakeAndBakeSignature/storeStakeAndBakeSignature.ts +8 -6
- package/src/bridge/abi/CCIP_BRIDGE_ADAPTER_ABI.json +704 -0
- package/src/bridge/abi/OFT_BRIDGE_ADAPTER_ABI.json +912 -0
- package/src/bridge/index.ts +11 -0
- package/src/bridge/lib/bridge.stories.tsx +89 -0
- package/src/bridge/lib/bridge.ts +101 -0
- package/src/bridge/lib/ccip-bridge.stories.tsx +90 -0
- package/src/bridge/lib/ccip-bridge.ts +163 -0
- package/src/bridge/lib/config.ts +338 -0
- package/src/bridge/lib/oft-bridge.stories.tsx +89 -0
- package/src/bridge/lib/oft-bridge.ts +212 -0
- package/src/clients/public-client.ts +32 -0
- package/src/clients/rpc-url-config.ts +20 -0
- package/src/clients/wallet-client.ts +33 -0
- package/src/{sdk/apiConfig.ts → common/api-config.ts} +9 -3
- package/src/common/blockchain-identifier.ts +134 -0
- package/src/common/chains.ts +84 -0
- package/src/common/contract-info.ts +8 -0
- package/src/common/parameters.ts +51 -0
- package/src/contract-functions/approveLBTC/approveLBTC.stories.tsx +76 -0
- package/src/contract-functions/approveLBTC/approveLBTC.ts +65 -0
- package/src/{web3Sdk → contract-functions}/claimLBTC/claimLBTC.stories.tsx +22 -30
- package/src/contract-functions/claimLBTC/claimLBTC.ts +90 -0
- package/src/contract-functions/getBasculeDepositStatus/getBasculeDepositStatus.stories.tsx +50 -0
- package/src/contract-functions/getBasculeDepositStatus/getBasculeDepositStatus.ts +127 -0
- package/src/{web3Sdk → contract-functions}/getLBTCMintingFee/getLBTCMintingFee.stories.tsx +15 -11
- package/src/contract-functions/getLBTCMintingFee/getLBTCMintingFee.tsx +37 -0
- package/src/{vaults/lib/get-vault-points.stories.tsx → contract-functions/getLBTCTotalSupply/getLBTCTotalSupply.stories.tsx} +13 -16
- package/src/contract-functions/getLBTCTotalSupply/getLBTCTotalSupply.ts +34 -0
- package/src/{web3Sdk → contract-functions}/getPermitNonce/getPermitNonce.stories.tsx +12 -22
- package/src/contract-functions/getPermitNonce/getPermitNonce.ts +45 -0
- package/src/{web3Sdk → contract-functions}/getShareValue/getShareValue.stories.tsx +12 -7
- package/src/contract-functions/getShareValue/getShareValue.ts +58 -0
- package/src/{web3Sdk → contract-functions}/getSharesByAddress/getSharesByAddress.stories.tsx +14 -9
- package/src/{web3Sdk → contract-functions}/getSharesByAddress/getSharesByAddress.ts +29 -28
- package/src/{web3Sdk → contract-functions}/getStakeAndBakeFee/getStakeAndBakeFee.stories.tsx +29 -16
- package/src/contract-functions/getStakeAndBakeFee/getStakeAndBakeFee.tsx +65 -0
- package/src/{web3Sdk → contract-functions}/index.ts +8 -7
- package/src/contract-functions/signLbtcDestionationAddr/signLbtcDestinationAddr.ts +32 -0
- package/src/contract-functions/signLbtcDestionationAddr/signLbtcDestionationAddr.stories.tsx +63 -0
- package/src/contract-functions/signNetworkFee/signNetworkFee.stories.tsx +91 -0
- package/src/contract-functions/signNetworkFee/signNetworkFee.ts +99 -0
- package/src/contract-functions/signStakeAndBake/index.ts +1 -0
- package/src/{web3Sdk → contract-functions}/signStakeAndBake/signStakeAndBake.stories.tsx +29 -41
- package/src/contract-functions/signStakeAndBake/signStakeAndBake.ts +145 -0
- package/src/contract-functions/unstakeLBTC/unstakeLBTC.stories.tsx +80 -0
- package/src/contract-functions/unstakeLBTC/unstakeLBTC.ts +66 -0
- package/src/index.ts +40 -17
- package/src/metrics/get-lbtc-stats.stories.tsx +51 -0
- package/src/metrics/get-lbtc-stats.ts +38 -0
- package/src/rewards/index.ts +26 -0
- package/src/rewards/lib/claim-reward.stories.tsx +82 -0
- package/src/rewards/lib/claim-reward.ts +84 -0
- package/src/rewards/lib/get-reward-balances.stories.tsx +64 -0
- package/src/rewards/lib/get-reward-balances.ts +81 -0
- package/src/rewards/lib/get-reward-signing-data.stories.tsx +76 -0
- package/src/rewards/lib/get-reward-signing-data.ts +52 -0
- package/src/rewards/lib/get-reward-withdrawal-fee.stories.tsx +61 -0
- package/src/rewards/lib/get-reward-withdrawal-fee.ts +37 -0
- package/src/rewards/lib/get-reward-withdrawals.stories.tsx +60 -0
- package/src/rewards/lib/get-reward-withdrawals.ts +92 -0
- package/src/rewards/lib/reward-tokens.ts +7 -0
- package/src/stories/components/Button/Button.css +10 -0
- package/src/stories/components/Button/Button.tsx +15 -4
- package/src/stories/components/CodeBlock/CodeBlock.tsx +1 -0
- package/src/stories/components/ConnectButton/connect-button.tsx +100 -0
- package/src/stories/components/ConnectButton/index.ts +1 -0
- package/src/stories/components/decorators/function-type.tsx +63 -0
- package/src/stories/components/decorators/index.ts +2 -0
- package/src/stories/components/decorators/wagmi-decorator.tsx +79 -0
- package/src/stories/components/error-block.tsx +21 -0
- package/src/stories/constants.ts +3 -0
- package/src/stories/hooks/useConnection.ts +72 -0
- package/src/stories/hooks/useQuery.ts +2 -2
- package/src/{web3Sdk/abi/LBTC.json → tokens/abi/LBTC_ABI.json} +1 -1
- package/src/tokens/abi/LBTC_ABI.ts +1761 -0
- package/src/tokens/abi/LBTC_BASCULE_ABI.json +850 -0
- package/src/tokens/lbtc-addresses.ts +55 -0
- package/src/tokens/token-addresses.ts +32 -0
- package/src/tokens/tokens.ts +120 -0
- package/src/utils/env.ts +12 -0
- package/src/utils/hex.ts +2 -2
- package/src/utils/numbers.ts +8 -0
- package/src/{common/utils/convertSatoshi.ts → utils/satoshi.ts} +3 -3
- package/src/utils/time.ts +12 -0
- package/src/vaults/abi/VEDA_VAULT_BASE_ASSET_ABI.json +296 -0
- package/src/vaults/abi/VEDA_VAULT_BORING_WITHDRAW_QUEUE_ABI.json +502 -0
- package/src/vaults/abi/VEDA_VAULT_SPENDER_ABI.json +408 -0
- package/src/vaults/abi/VEDA_VAULT_TELLER_ABI.json +700 -0
- package/src/vaults/index.ts +36 -69
- package/src/vaults/lib/config.ts +196 -0
- package/src/vaults/lib/metrics/get-vault-apy.stories.tsx +57 -0
- package/src/vaults/lib/metrics/get-vault-apy.ts +132 -0
- package/src/vaults/lib/metrics/get-vault-points.stories.tsx +59 -0
- package/src/vaults/lib/{get-vault-points.ts → metrics/get-vault-points.ts} +14 -10
- package/src/vaults/lib/metrics/get-vault-tvl.stories.tsx +57 -0
- package/src/vaults/lib/metrics/get-vault-tvl.ts +119 -0
- package/src/vaults/lib/ops/cancel-withdraw.stories.tsx +79 -0
- package/src/vaults/lib/ops/deposit.stories.tsx +81 -0
- package/src/vaults/lib/ops/deposit.ts +151 -0
- package/src/vaults/lib/{get-vault-deposits.stories.tsx → ops/get-vault-deposits.stories.tsx} +20 -14
- package/src/vaults/lib/{get-vault-deposits.ts → ops/get-vault-deposits.ts} +45 -22
- package/src/vaults/lib/{get-vault-withdrawals.stories.tsx → ops/get-vault-withdrawals.stories.tsx} +20 -13
- package/src/vaults/lib/{get-vault-withdrawals.ts → ops/get-vault-withdrawals.ts} +72 -38
- package/src/vaults/lib/ops/withdraw.stories.tsx +81 -0
- package/src/vaults/lib/ops/withdraw.ts +224 -0
- package/src/common/const.ts +0 -5
- package/src/common/types/internalTypes.ts +0 -10
- package/src/common/types/types.ts +0 -57
- package/src/common/utils/isValidChain.ts +0 -5
- package/src/provider/Provider.ts +0 -171
- package/src/provider/ReadProvider.ts +0 -126
- package/src/provider/index.ts +0 -2
- package/src/provider/rpcUrlConfig.ts +0 -19
- package/src/provider/types.ts +0 -58
- package/src/provider/utils/getMaxPriorityFeePerGas.ts +0 -25
- package/src/sdk/getLBTCExchangeRate/getLBTCExchangeRate.ts +0 -65
- package/src/sdk/getNetworkFeeSignature/getNetworkFeeSignature.stories.tsx +0 -85
- package/src/sdk/getUserStakeAndBakeSignature/getUserStakeAndBakeSignature.stories.tsx +0 -86
- package/src/sdk/internalTypes.ts +0 -18
- package/src/sdk/storeNetworkFeeSignature/storeNetworkFeeSignature.stories.tsx +0 -86
- package/src/sdk/storeStakeAndBakeSignature/storeStakeAndBakeSignature.stories.tsx +0 -116
- package/src/sdk/utils/getChainIdByName.ts +0 -48
- package/src/sdk/utils/getChainNameById.ts +0 -41
- package/src/stories/const.ts +0 -1
- package/src/stories/hooks/useConnect.ts +0 -47
- package/src/stories/utils/connectInjectedWallet.ts +0 -12
- package/src/stories/utils/fromCamelCase.ts +0 -16
- package/src/stories/utils/getMetaTitle.ts +0 -7
- package/src/stories/utils/getWalletInfo.ts +0 -31
- package/src/web3Sdk/abi/BASCULE.json +0 -850
- package/src/web3Sdk/abi/IERC20.json +0 -222
- package/src/web3Sdk/abi/STAKE_AND_BAKE.json +0 -15
- package/src/web3Sdk/abi/index.ts +0 -6
- package/src/web3Sdk/approveLBTC/approveLBTC.stories.tsx +0 -77
- package/src/web3Sdk/approveLBTC/approveLBTC.ts +0 -48
- package/src/web3Sdk/claimLBTC/claimLBTC.ts +0 -86
- package/src/web3Sdk/const.ts +0 -2
- package/src/web3Sdk/getBasculeDepositStatus/getBasculeDepositStatus.stories.tsx +0 -89
- package/src/web3Sdk/getBasculeDepositStatus/getBasculeDepositStatus.ts +0 -75
- package/src/web3Sdk/getBasculeDepositStatus/utils/const.ts +0 -8
- package/src/web3Sdk/getBasculeDepositStatus/utils/throwBasculeDepositStatusError.ts +0 -21
- package/src/web3Sdk/getLBTCMintingFee/getLBTCMintingFee.tsx +0 -41
- package/src/web3Sdk/getLBTCTotalSupply/getLBTCTotalSupply.stories.tsx +0 -60
- package/src/web3Sdk/getLBTCTotalSupply/getLBTCTotalSupply.ts +0 -26
- package/src/web3Sdk/getPermitNonce/getPermitNonce.ts +0 -47
- package/src/web3Sdk/getShareValue/getShareValue.ts +0 -58
- package/src/web3Sdk/getStakeAndBakeFee/getStakeAndBakeFee.tsx +0 -48
- package/src/web3Sdk/lbtcAddressConfig.ts +0 -96
- package/src/web3Sdk/signLbtcDestionationAddr/signLbtcDestinationAddr.ts +0 -23
- package/src/web3Sdk/signLbtcDestionationAddr/signLbtcDestionationAddr.stories.tsx +0 -97
- package/src/web3Sdk/signNetworkFee/signNetworkFee.stories.tsx +0 -91
- package/src/web3Sdk/signNetworkFee/signNetworkFee.ts +0 -92
- package/src/web3Sdk/signStakeAndBake/contracts.ts +0 -80
- package/src/web3Sdk/signStakeAndBake/getTypedData.ts +0 -78
- package/src/web3Sdk/signStakeAndBake/index.ts +0 -3
- package/src/web3Sdk/signStakeAndBake/signStakeAndBake.ts +0 -105
- package/src/web3Sdk/signStakeAndBake/utils.ts +0 -23
- package/src/web3Sdk/types.ts +0 -16
- package/src/web3Sdk/unstakeLBTC/unstakeLBTC.stories.tsx +0 -77
- package/src/web3Sdk/unstakeLBTC/unstakeLBTC.ts +0 -51
- package/src/web3Sdk/utils/chainIdToEnv.ts +0 -12
- package/src/web3Sdk/utils/getBasculeTokenContract.ts +0 -21
- package/src/web3Sdk/utils/getGasMultiplier.ts +0 -20
- package/src/web3Sdk/utils/getLbtcTokenContract.ts +0 -36
- package/src/web3Sdk/utils/getRpcUrlConfigFromChain.ts +0 -34
- package/src/web3Sdk/utils/getTokenABI.ts +0 -12
- /package/src/{sdk → api-functions}/generateDepositBtcAddress/index.ts +0 -0
- /package/src/{sdk → api-functions}/getDepositBtcAddress/index.ts +0 -0
- /package/src/{sdk → api-functions}/getDepositsByAddress/index.ts +0 -0
- /package/src/{sdk → api-functions}/getLBTCExchangeRate/index.ts +0 -0
- /package/src/{sdk → api-functions}/getNetworkFeeSignature/index.ts +0 -0
- /package/src/{sdk → api-functions}/getPointsByAddress/index.ts +0 -0
- /package/src/{sdk → api-functions}/getUnstakesByAddress/index.ts +0 -0
- /package/src/{sdk → api-functions}/getUserStakeAndBakeSignature/index.ts +0 -0
- /package/src/{sdk → api-functions}/setReferral/index.ts +0 -0
- /package/src/{sdk → api-functions}/storeNetworkFeeSignature/index.ts +0 -0
- /package/src/{sdk → api-functions}/storeStakeAndBakeSignature/index.ts +0 -0
- /package/src/{sdk/const.ts → common/constants.ts} +0 -0
- /package/src/{web3Sdk → contract-functions}/approveLBTC/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/claimLBTC/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/getBasculeDepositStatus/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/getLBTCMintingFee/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/getLBTCTotalSupply/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/getPermitNonce/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/getShareValue/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/getSharesByAddress/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/getStakeAndBakeFee/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/signLbtcDestionationAddr/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/signNetworkFee/getTypedData.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/signNetworkFee/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/unstakeLBTC/index.ts +0 -0
- /package/src/{common/utils/getErrorMessage.ts → utils/err.ts} +0 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Address } from 'viem';
|
|
2
|
+
import { ChainId } from '../common/chains';
|
|
3
|
+
import { Env, DEFAULT_ENV } from '@lombard.finance/sdk-common';
|
|
4
|
+
|
|
5
|
+
type LbtcContractAddresses = Partial<Record<ChainId, Address>>;
|
|
6
|
+
|
|
7
|
+
const STAGE_LBTC_CONTRACTS = {
|
|
8
|
+
[ChainId.baseSepoliaTestnet]: '0x731eFa688F3679688cf60A3993b8658138953ED6',
|
|
9
|
+
[ChainId.berachainBartioTestnet]:
|
|
10
|
+
'0xc47e4b3124597FDF8DD07843D4a7052F2eE80C30',
|
|
11
|
+
[ChainId.binanceSmartChainTestnet]:
|
|
12
|
+
'0x731eFa688F3679688cf60A3993b8658138953ED6',
|
|
13
|
+
[ChainId.holesky]: '0xED7bfd5C1790576105Af4649817f6d35A75CD818',
|
|
14
|
+
[ChainId.sepolia]: '0xc47e4b3124597fdf8dd07843d4a7052f2ee80c30',
|
|
15
|
+
[ChainId.sonicBlazeTestnet]: '0x731eFa688F3679688cf60A3993b8658138953ED6',
|
|
16
|
+
} as const;
|
|
17
|
+
|
|
18
|
+
const TESTNET_LBTC_CONTRACTS = {
|
|
19
|
+
[ChainId.berachainBartioTestnet]:
|
|
20
|
+
'0xc47e4b3124597FDF8DD07843D4a7052F2eE80C30',
|
|
21
|
+
[ChainId.binanceSmartChainTestnet]:
|
|
22
|
+
'0x107Fc7d90484534704dD2A9e24c7BD45DB4dD1B5',
|
|
23
|
+
[ChainId.holesky]: '0x38A13AB20D15ffbE5A7312d2336EF1552580a4E2',
|
|
24
|
+
[ChainId.sepolia]: '0xc47e4b3124597fdf8dd07843d4a7052f2ee80c30',
|
|
25
|
+
[ChainId.sonicBlazeTestnet]: '0x107Fc7d90484534704dD2A9e24c7BD45DB4dD1B5',
|
|
26
|
+
} as const;
|
|
27
|
+
|
|
28
|
+
const LBTC_CONTRACTS = {
|
|
29
|
+
[ChainId.ethereum]: '0x8236a87084f8b84306f72007f36f2618a5634494',
|
|
30
|
+
[ChainId.base]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
|
|
31
|
+
[ChainId.berachain]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
|
|
32
|
+
[ChainId.binanceSmartChain]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
|
|
33
|
+
[ChainId.corn]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
|
|
34
|
+
[ChainId.morph]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
|
|
35
|
+
[ChainId.sonic]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
|
|
36
|
+
[ChainId.swell]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
|
|
37
|
+
} as const;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Gets the collection of LBTC contract addresses based on the provided
|
|
41
|
+
* environment.
|
|
42
|
+
*/
|
|
43
|
+
export function getLbtcContractAddresses(
|
|
44
|
+
env: Env = DEFAULT_ENV,
|
|
45
|
+
): LbtcContractAddresses {
|
|
46
|
+
switch (env) {
|
|
47
|
+
case Env.testnet:
|
|
48
|
+
return TESTNET_LBTC_CONTRACTS;
|
|
49
|
+
case Env.dev:
|
|
50
|
+
case Env.stage:
|
|
51
|
+
return STAGE_LBTC_CONTRACTS;
|
|
52
|
+
case Env.prod:
|
|
53
|
+
return LBTC_CONTRACTS;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Address } from 'viem';
|
|
2
|
+
import { ChainId } from '../common/chains';
|
|
3
|
+
|
|
4
|
+
export enum Token {
|
|
5
|
+
LBTC = 'LBTC',
|
|
6
|
+
BTCB = 'BTCB',
|
|
7
|
+
cbBTC = 'cbBTC',
|
|
8
|
+
eBTC = 'eBTC',
|
|
9
|
+
wBTC = 'wBTC',
|
|
10
|
+
wBTCN = 'wBTCN',
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const TOKEN_ADDRESSES: Partial<
|
|
14
|
+
Record<Token, Partial<Record<ChainId, Address>>>
|
|
15
|
+
> = {
|
|
16
|
+
[Token.BTCB]: {
|
|
17
|
+
[ChainId.binanceSmartChain]: '0x7130d2a12b9bcbfae4f2634d864a1ee1ce3ead9c',
|
|
18
|
+
},
|
|
19
|
+
[Token.cbBTC]: {
|
|
20
|
+
[ChainId.ethereum]: '0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf',
|
|
21
|
+
[ChainId.base]: '0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf',
|
|
22
|
+
},
|
|
23
|
+
[Token.eBTC]: {
|
|
24
|
+
[ChainId.ethereum]: '0x657e8c867d8b37dcc18fa4caead9c45eb088c642',
|
|
25
|
+
},
|
|
26
|
+
[Token.wBTC]: {
|
|
27
|
+
[ChainId.ethereum]: '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
28
|
+
},
|
|
29
|
+
[Token.wBTCN]: {
|
|
30
|
+
[ChainId.corn]: '0xda5dDd7270381A7C2717aD10D1c0ecB19e3CDFb2',
|
|
31
|
+
},
|
|
32
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { Env } from '@lombard.finance/sdk-common';
|
|
2
|
+
import { ChainId } from '../common/chains';
|
|
3
|
+
import { makePublicClient } from '../clients/public-client';
|
|
4
|
+
import BigNumber from 'bignumber.js';
|
|
5
|
+
import { Abi, Address, erc20Abi, PublicClient } from 'viem';
|
|
6
|
+
import { TOKEN_ADDRESSES, Token } from './token-addresses';
|
|
7
|
+
import { getLbtcContractAddresses } from './lbtc-addresses';
|
|
8
|
+
import { LBTC_ABI } from './abi/LBTC_ABI';
|
|
9
|
+
|
|
10
|
+
export type TokenInfo = {
|
|
11
|
+
address: Address;
|
|
12
|
+
abi: Abi;
|
|
13
|
+
symbol: string;
|
|
14
|
+
decimals: number;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export function getTokenContractInfo(
|
|
18
|
+
token: Token,
|
|
19
|
+
chainId: ChainId,
|
|
20
|
+
env?: Env,
|
|
21
|
+
) {
|
|
22
|
+
if (token === Token.LBTC) {
|
|
23
|
+
const addresses = getLbtcContractAddresses(env);
|
|
24
|
+
const contractAddress = addresses[chainId];
|
|
25
|
+
if (!contractAddress) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
`Could not determine the LBTC contract address for given chain id: ${chainId} (env: ${env})`,
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
return { abi: LBTC_ABI, address: contractAddress, chainId };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const address = TOKEN_ADDRESSES[token]?.[chainId];
|
|
34
|
+
if (!address) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
`Could not determine the ${token} contract address for given chain id: ${chainId}`,
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
abi: erc20Abi,
|
|
42
|
+
address,
|
|
43
|
+
chainId,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const retrieveTokenProperties = async (
|
|
48
|
+
publicClient: PublicClient,
|
|
49
|
+
tokenContractInfo: { abi: Abi; address: Address; chainId: ChainId },
|
|
50
|
+
) => {
|
|
51
|
+
const [symbolResult, decimalsResult] = await publicClient.multicall({
|
|
52
|
+
contracts: [
|
|
53
|
+
{
|
|
54
|
+
...tokenContractInfo,
|
|
55
|
+
functionName: 'symbol',
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
...tokenContractInfo,
|
|
59
|
+
functionName: 'decimals',
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
if (
|
|
65
|
+
symbolResult.status === 'success' &&
|
|
66
|
+
decimalsResult.status === 'success'
|
|
67
|
+
) {
|
|
68
|
+
return {
|
|
69
|
+
address: tokenContractInfo.address,
|
|
70
|
+
abi: tokenContractInfo.abi as Abi,
|
|
71
|
+
symbol: String(symbolResult.result),
|
|
72
|
+
decimals: Number(decimalsResult.result),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export async function getTokenInfo(
|
|
78
|
+
token: Token,
|
|
79
|
+
chainId: ChainId,
|
|
80
|
+
env?: Env,
|
|
81
|
+
rpcUrl?: string,
|
|
82
|
+
): Promise<TokenInfo | undefined> {
|
|
83
|
+
const tokenContractInfo = getTokenContractInfo(token, chainId, env);
|
|
84
|
+
if (!tokenContractInfo) return;
|
|
85
|
+
|
|
86
|
+
const publicClient = makePublicClient({ chainId, rpcUrl });
|
|
87
|
+
return retrieveTokenProperties(publicClient, tokenContractInfo);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export async function getAssetInfo(
|
|
91
|
+
address: Address,
|
|
92
|
+
chainId: ChainId,
|
|
93
|
+
rpcUrl?: string,
|
|
94
|
+
): Promise<TokenInfo | undefined> {
|
|
95
|
+
const publicClient = makePublicClient({ chainId, rpcUrl });
|
|
96
|
+
return retrieveTokenProperties(publicClient, {
|
|
97
|
+
abi: erc20Abi,
|
|
98
|
+
address,
|
|
99
|
+
chainId,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Utils:
|
|
104
|
+
// TODO: Move to utils
|
|
105
|
+
|
|
106
|
+
export function toBaseDenomination(
|
|
107
|
+
input: BigNumber.Value,
|
|
108
|
+
decimalPlaces: number,
|
|
109
|
+
) {
|
|
110
|
+
return BigNumber(input)
|
|
111
|
+
.multipliedBy(BigNumber(10).pow(decimalPlaces))
|
|
112
|
+
.decimalPlaces(0, BigNumber.ROUND_HALF_UP);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function fromBaseDenomination(
|
|
116
|
+
input: BigNumber.Value,
|
|
117
|
+
decimalPlaces: number,
|
|
118
|
+
) {
|
|
119
|
+
return BigNumber(input).dividedBy(BigNumber(10).pow(decimalPlaces));
|
|
120
|
+
}
|
package/src/utils/env.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ChainId } from '../common/chains';
|
|
2
|
+
import { Env } from '@lombard.finance/sdk-common';
|
|
3
|
+
|
|
4
|
+
const PROD_NATIVE_MINT_CHAINS = [
|
|
5
|
+
ChainId.ethereum,
|
|
6
|
+
ChainId.base,
|
|
7
|
+
ChainId.binanceSmartChain,
|
|
8
|
+
] as ChainId[];
|
|
9
|
+
|
|
10
|
+
export const determineEnv = (chainId: ChainId): Env => {
|
|
11
|
+
return PROD_NATIVE_MINT_CHAINS.includes(chainId) ? Env.prod : Env.stage;
|
|
12
|
+
};
|
package/src/utils/hex.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
2
|
|
|
3
|
-
const BTC_DECIMALS = 8;
|
|
3
|
+
export const BTC_DECIMALS = 8;
|
|
4
4
|
export const SATOSHI_SCALE = BigNumber(10).pow(BTC_DECIMALS);
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -8,7 +8,7 @@ export const SATOSHI_SCALE = BigNumber(10).pow(BTC_DECIMALS);
|
|
|
8
8
|
* @param amount - Satoshi amount
|
|
9
9
|
* @returns BTC amount
|
|
10
10
|
*/
|
|
11
|
-
export function fromSatoshi(amount:
|
|
11
|
+
export function fromSatoshi(amount: BigNumber.Value) {
|
|
12
12
|
return BigNumber(amount).dividedBy(SATOSHI_SCALE);
|
|
13
13
|
}
|
|
14
14
|
|
|
@@ -18,7 +18,7 @@ export function fromSatoshi(amount: number | string | BigNumber) {
|
|
|
18
18
|
* @param amount - BTC amount
|
|
19
19
|
* @returns Satoshi amount
|
|
20
20
|
*/
|
|
21
|
-
export function toSatoshi(amount:
|
|
21
|
+
export function toSatoshi(amount: BigNumber.Value) {
|
|
22
22
|
return BigNumber(amount)
|
|
23
23
|
.multipliedBy(SATOSHI_SCALE)
|
|
24
24
|
.decimalPlaces(0, BigNumber.ROUND_HALF_UP);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const SECOND = 1000;
|
|
2
|
+
export const MINUTE = 60 * SECOND;
|
|
3
|
+
export const HOUR = 60 * MINUTE;
|
|
4
|
+
export const DAY = 24 * HOUR;
|
|
5
|
+
|
|
6
|
+
export function now() {
|
|
7
|
+
return Date.now();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function toUnix(ms: number) {
|
|
11
|
+
return Math.round(ms / 1000);
|
|
12
|
+
}
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"constant": true,
|
|
4
|
+
"inputs": [],
|
|
5
|
+
"name": "mintingFinished",
|
|
6
|
+
"outputs": [{ "name": "", "type": "bool" }],
|
|
7
|
+
"payable": false,
|
|
8
|
+
"stateMutability": "view",
|
|
9
|
+
"type": "function"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"constant": true,
|
|
13
|
+
"inputs": [],
|
|
14
|
+
"name": "name",
|
|
15
|
+
"outputs": [{ "name": "", "type": "string" }],
|
|
16
|
+
"payable": false,
|
|
17
|
+
"stateMutability": "view",
|
|
18
|
+
"type": "function"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"constant": false,
|
|
22
|
+
"inputs": [
|
|
23
|
+
{ "name": "_spender", "type": "address" },
|
|
24
|
+
{ "name": "_value", "type": "uint256" }
|
|
25
|
+
],
|
|
26
|
+
"name": "approve",
|
|
27
|
+
"outputs": [{ "name": "", "type": "bool" }],
|
|
28
|
+
"payable": false,
|
|
29
|
+
"stateMutability": "nonpayable",
|
|
30
|
+
"type": "function"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"constant": false,
|
|
34
|
+
"inputs": [{ "name": "_token", "type": "address" }],
|
|
35
|
+
"name": "reclaimToken",
|
|
36
|
+
"outputs": [],
|
|
37
|
+
"payable": false,
|
|
38
|
+
"stateMutability": "nonpayable",
|
|
39
|
+
"type": "function"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"constant": true,
|
|
43
|
+
"inputs": [],
|
|
44
|
+
"name": "totalSupply",
|
|
45
|
+
"outputs": [{ "name": "", "type": "uint256" }],
|
|
46
|
+
"payable": false,
|
|
47
|
+
"stateMutability": "view",
|
|
48
|
+
"type": "function"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"constant": false,
|
|
52
|
+
"inputs": [
|
|
53
|
+
{ "name": "_from", "type": "address" },
|
|
54
|
+
{ "name": "_to", "type": "address" },
|
|
55
|
+
{ "name": "_value", "type": "uint256" }
|
|
56
|
+
],
|
|
57
|
+
"name": "transferFrom",
|
|
58
|
+
"outputs": [{ "name": "", "type": "bool" }],
|
|
59
|
+
"payable": false,
|
|
60
|
+
"stateMutability": "nonpayable",
|
|
61
|
+
"type": "function"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"constant": true,
|
|
65
|
+
"inputs": [],
|
|
66
|
+
"name": "decimals",
|
|
67
|
+
"outputs": [{ "name": "", "type": "uint8" }],
|
|
68
|
+
"payable": false,
|
|
69
|
+
"stateMutability": "view",
|
|
70
|
+
"type": "function"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"constant": false,
|
|
74
|
+
"inputs": [],
|
|
75
|
+
"name": "unpause",
|
|
76
|
+
"outputs": [],
|
|
77
|
+
"payable": false,
|
|
78
|
+
"stateMutability": "nonpayable",
|
|
79
|
+
"type": "function"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"constant": false,
|
|
83
|
+
"inputs": [
|
|
84
|
+
{ "name": "_to", "type": "address" },
|
|
85
|
+
{ "name": "_amount", "type": "uint256" }
|
|
86
|
+
],
|
|
87
|
+
"name": "mint",
|
|
88
|
+
"outputs": [{ "name": "", "type": "bool" }],
|
|
89
|
+
"payable": false,
|
|
90
|
+
"stateMutability": "nonpayable",
|
|
91
|
+
"type": "function"
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"constant": false,
|
|
95
|
+
"inputs": [{ "name": "value", "type": "uint256" }],
|
|
96
|
+
"name": "burn",
|
|
97
|
+
"outputs": [],
|
|
98
|
+
"payable": false,
|
|
99
|
+
"stateMutability": "nonpayable",
|
|
100
|
+
"type": "function"
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"constant": false,
|
|
104
|
+
"inputs": [],
|
|
105
|
+
"name": "claimOwnership",
|
|
106
|
+
"outputs": [],
|
|
107
|
+
"payable": false,
|
|
108
|
+
"stateMutability": "nonpayable",
|
|
109
|
+
"type": "function"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"constant": true,
|
|
113
|
+
"inputs": [],
|
|
114
|
+
"name": "paused",
|
|
115
|
+
"outputs": [{ "name": "", "type": "bool" }],
|
|
116
|
+
"payable": false,
|
|
117
|
+
"stateMutability": "view",
|
|
118
|
+
"type": "function"
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"constant": false,
|
|
122
|
+
"inputs": [
|
|
123
|
+
{ "name": "_spender", "type": "address" },
|
|
124
|
+
{ "name": "_subtractedValue", "type": "uint256" }
|
|
125
|
+
],
|
|
126
|
+
"name": "decreaseApproval",
|
|
127
|
+
"outputs": [{ "name": "success", "type": "bool" }],
|
|
128
|
+
"payable": false,
|
|
129
|
+
"stateMutability": "nonpayable",
|
|
130
|
+
"type": "function"
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
"constant": true,
|
|
134
|
+
"inputs": [{ "name": "_owner", "type": "address" }],
|
|
135
|
+
"name": "balanceOf",
|
|
136
|
+
"outputs": [{ "name": "", "type": "uint256" }],
|
|
137
|
+
"payable": false,
|
|
138
|
+
"stateMutability": "view",
|
|
139
|
+
"type": "function"
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
"constant": false,
|
|
143
|
+
"inputs": [],
|
|
144
|
+
"name": "renounceOwnership",
|
|
145
|
+
"outputs": [],
|
|
146
|
+
"payable": false,
|
|
147
|
+
"stateMutability": "nonpayable",
|
|
148
|
+
"type": "function"
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"constant": false,
|
|
152
|
+
"inputs": [],
|
|
153
|
+
"name": "finishMinting",
|
|
154
|
+
"outputs": [{ "name": "", "type": "bool" }],
|
|
155
|
+
"payable": false,
|
|
156
|
+
"stateMutability": "nonpayable",
|
|
157
|
+
"type": "function"
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
"constant": false,
|
|
161
|
+
"inputs": [],
|
|
162
|
+
"name": "pause",
|
|
163
|
+
"outputs": [],
|
|
164
|
+
"payable": false,
|
|
165
|
+
"stateMutability": "nonpayable",
|
|
166
|
+
"type": "function"
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
"constant": true,
|
|
170
|
+
"inputs": [],
|
|
171
|
+
"name": "owner",
|
|
172
|
+
"outputs": [{ "name": "", "type": "address" }],
|
|
173
|
+
"payable": false,
|
|
174
|
+
"stateMutability": "view",
|
|
175
|
+
"type": "function"
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
"constant": true,
|
|
179
|
+
"inputs": [],
|
|
180
|
+
"name": "symbol",
|
|
181
|
+
"outputs": [{ "name": "", "type": "string" }],
|
|
182
|
+
"payable": false,
|
|
183
|
+
"stateMutability": "view",
|
|
184
|
+
"type": "function"
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
"constant": false,
|
|
188
|
+
"inputs": [
|
|
189
|
+
{ "name": "_to", "type": "address" },
|
|
190
|
+
{ "name": "_value", "type": "uint256" }
|
|
191
|
+
],
|
|
192
|
+
"name": "transfer",
|
|
193
|
+
"outputs": [{ "name": "", "type": "bool" }],
|
|
194
|
+
"payable": false,
|
|
195
|
+
"stateMutability": "nonpayable",
|
|
196
|
+
"type": "function"
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
"constant": false,
|
|
200
|
+
"inputs": [
|
|
201
|
+
{ "name": "_spender", "type": "address" },
|
|
202
|
+
{ "name": "_addedValue", "type": "uint256" }
|
|
203
|
+
],
|
|
204
|
+
"name": "increaseApproval",
|
|
205
|
+
"outputs": [{ "name": "success", "type": "bool" }],
|
|
206
|
+
"payable": false,
|
|
207
|
+
"stateMutability": "nonpayable",
|
|
208
|
+
"type": "function"
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
"constant": true,
|
|
212
|
+
"inputs": [
|
|
213
|
+
{ "name": "_owner", "type": "address" },
|
|
214
|
+
{ "name": "_spender", "type": "address" }
|
|
215
|
+
],
|
|
216
|
+
"name": "allowance",
|
|
217
|
+
"outputs": [{ "name": "", "type": "uint256" }],
|
|
218
|
+
"payable": false,
|
|
219
|
+
"stateMutability": "view",
|
|
220
|
+
"type": "function"
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
"constant": true,
|
|
224
|
+
"inputs": [],
|
|
225
|
+
"name": "pendingOwner",
|
|
226
|
+
"outputs": [{ "name": "", "type": "address" }],
|
|
227
|
+
"payable": false,
|
|
228
|
+
"stateMutability": "view",
|
|
229
|
+
"type": "function"
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
"constant": false,
|
|
233
|
+
"inputs": [{ "name": "newOwner", "type": "address" }],
|
|
234
|
+
"name": "transferOwnership",
|
|
235
|
+
"outputs": [],
|
|
236
|
+
"payable": false,
|
|
237
|
+
"stateMutability": "nonpayable",
|
|
238
|
+
"type": "function"
|
|
239
|
+
},
|
|
240
|
+
{ "anonymous": false, "inputs": [], "name": "Pause", "type": "event" },
|
|
241
|
+
{ "anonymous": false, "inputs": [], "name": "Unpause", "type": "event" },
|
|
242
|
+
{
|
|
243
|
+
"anonymous": false,
|
|
244
|
+
"inputs": [
|
|
245
|
+
{ "indexed": true, "name": "burner", "type": "address" },
|
|
246
|
+
{ "indexed": false, "name": "value", "type": "uint256" }
|
|
247
|
+
],
|
|
248
|
+
"name": "Burn",
|
|
249
|
+
"type": "event"
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
"anonymous": false,
|
|
253
|
+
"inputs": [
|
|
254
|
+
{ "indexed": true, "name": "to", "type": "address" },
|
|
255
|
+
{ "indexed": false, "name": "amount", "type": "uint256" }
|
|
256
|
+
],
|
|
257
|
+
"name": "Mint",
|
|
258
|
+
"type": "event"
|
|
259
|
+
},
|
|
260
|
+
{ "anonymous": false, "inputs": [], "name": "MintFinished", "type": "event" },
|
|
261
|
+
{
|
|
262
|
+
"anonymous": false,
|
|
263
|
+
"inputs": [{ "indexed": true, "name": "previousOwner", "type": "address" }],
|
|
264
|
+
"name": "OwnershipRenounced",
|
|
265
|
+
"type": "event"
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
"anonymous": false,
|
|
269
|
+
"inputs": [
|
|
270
|
+
{ "indexed": true, "name": "previousOwner", "type": "address" },
|
|
271
|
+
{ "indexed": true, "name": "newOwner", "type": "address" }
|
|
272
|
+
],
|
|
273
|
+
"name": "OwnershipTransferred",
|
|
274
|
+
"type": "event"
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
"anonymous": false,
|
|
278
|
+
"inputs": [
|
|
279
|
+
{ "indexed": true, "name": "owner", "type": "address" },
|
|
280
|
+
{ "indexed": true, "name": "spender", "type": "address" },
|
|
281
|
+
{ "indexed": false, "name": "value", "type": "uint256" }
|
|
282
|
+
],
|
|
283
|
+
"name": "Approval",
|
|
284
|
+
"type": "event"
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
"anonymous": false,
|
|
288
|
+
"inputs": [
|
|
289
|
+
{ "indexed": true, "name": "from", "type": "address" },
|
|
290
|
+
{ "indexed": true, "name": "to", "type": "address" },
|
|
291
|
+
{ "indexed": false, "name": "value", "type": "uint256" }
|
|
292
|
+
],
|
|
293
|
+
"name": "Transfer",
|
|
294
|
+
"type": "event"
|
|
295
|
+
}
|
|
296
|
+
]
|