@lombard.finance/sdk 2.5.2 → 3.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/README.md +428 -399
- 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 +68 -8269
- package/dist/index.js.map +1 -1
- package/dist/index2.cjs +53 -0
- package/dist/index2.cjs.map +1 -0
- package/dist/index2.js +21672 -0
- package/dist/index2.js.map +1 -0
- package/package.json +5 -5
- 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 +15 -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 +8 -8
- 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 +14 -9
- package/src/api-functions/getUserStakeAndBakeSignature/getUserStakeAndBakeSignature.stories.tsx +61 -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/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} +2 -2
- package/src/common/blockchain-identifier.ts +107 -0
- package/src/common/chains.ts +72 -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 +64 -0
- package/src/{web3Sdk → contract-functions}/claimLBTC/claimLBTC.stories.tsx +22 -30
- package/src/contract-functions/claimLBTC/claimLBTC.ts +89 -0
- package/src/contract-functions/getBasculeDepositStatus/getBasculeDepositStatus.stories.tsx +50 -0
- package/src/contract-functions/getBasculeDepositStatus/getBasculeDepositStatus.ts +121 -0
- package/src/{web3Sdk → contract-functions}/getLBTCMintingFee/getLBTCMintingFee.stories.tsx +15 -11
- package/src/contract-functions/getLBTCMintingFee/getLBTCMintingFee.tsx +34 -0
- package/src/contract-functions/getLBTCTotalSupply/getLBTCTotalSupply.stories.tsx +49 -0
- package/src/contract-functions/getLBTCTotalSupply/getLBTCTotalSupply.ts +30 -0
- package/src/{web3Sdk → contract-functions}/getPermitNonce/getPermitNonce.stories.tsx +12 -22
- package/src/contract-functions/getPermitNonce/getPermitNonce.ts +39 -0
- package/src/{web3Sdk → contract-functions}/getShareValue/getShareValue.stories.tsx +11 -6
- package/src/contract-functions/getShareValue/getShareValue.ts +58 -0
- package/src/{web3Sdk → contract-functions}/getSharesByAddress/getSharesByAddress.stories.tsx +13 -8
- package/src/{web3Sdk → contract-functions}/getSharesByAddress/getSharesByAddress.ts +29 -28
- package/src/{web3Sdk → contract-functions}/getStakeAndBakeFee/getStakeAndBakeFee.stories.tsx +16 -16
- package/src/contract-functions/getStakeAndBakeFee/getStakeAndBakeFee.tsx +61 -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 +98 -0
- package/src/contract-functions/signStakeAndBake/index.ts +1 -0
- package/src/{web3Sdk → contract-functions}/signStakeAndBake/signStakeAndBake.stories.tsx +27 -40
- package/src/contract-functions/signStakeAndBake/signStakeAndBake.ts +140 -0
- package/src/contract-functions/unstakeLBTC/unstakeLBTC.stories.tsx +80 -0
- package/src/contract-functions/unstakeLBTC/unstakeLBTC.ts +65 -0
- package/src/index.ts +35 -10
- 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/tokens/abi/LBTC_ABI.json +1761 -0
- package/src/tokens/abi/LBTC_BASCULE_ABI.json +850 -0
- package/src/tokens/lbtc-addresses.ts +54 -0
- package/src/tokens/lbtc-contract.ts +89 -0
- package/src/tokens/tokens.ts +111 -0
- package/src/utils/env.ts +12 -0
- package/src/utils/hex.ts +2 -2
- package/src/utils/numbers.ts +5 -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 +144 -36
- package/src/vaults/lib/cancel-withdraw.stories.tsx +79 -0
- package/src/vaults/lib/deposit.stories.tsx +81 -0
- package/src/vaults/lib/deposit.ts +151 -0
- package/src/vaults/lib/get-vault-deposits.stories.tsx +15 -9
- package/src/vaults/lib/get-vault-deposits.ts +45 -22
- package/src/vaults/lib/get-vault-points.stories.tsx +13 -6
- package/src/vaults/lib/get-vault-points.ts +14 -10
- package/src/vaults/lib/get-vault-withdrawals.stories.tsx +15 -8
- package/src/vaults/lib/get-vault-withdrawals.ts +72 -38
- package/src/vaults/lib/withdraw.stories.tsx +81 -0
- package/src/vaults/lib/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/LBTC.json +0 -1761
- 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,224 @@
|
|
|
1
|
+
import BigNumber from 'bignumber.js';
|
|
2
|
+
import { isVedaVaultChain, Vault, VAULTS } from '..';
|
|
3
|
+
import { CommonWriteParameters } from '../../common/parameters';
|
|
4
|
+
import { makePublicClient } from '../../clients/public-client';
|
|
5
|
+
import { makeWalletClient } from '../../clients/wallet-client';
|
|
6
|
+
import {
|
|
7
|
+
fromBaseDenomination,
|
|
8
|
+
getTokenInfo,
|
|
9
|
+
toBaseDenomination,
|
|
10
|
+
Token,
|
|
11
|
+
} from '../../tokens/tokens';
|
|
12
|
+
import toBigInt from '../../utils/numbers';
|
|
13
|
+
import { CHAIN_ID_TO_VIEM_CHAIN_MAP } from '../../common/chains';
|
|
14
|
+
import { getErrorMessage } from '../../utils/err';
|
|
15
|
+
import { DAY } from '../../utils/time';
|
|
16
|
+
|
|
17
|
+
export type QueueWithdrawParameters = {
|
|
18
|
+
/** The amount to be withdrawn from the DeFi vault. */
|
|
19
|
+
amount: BigNumber.Value;
|
|
20
|
+
/**
|
|
21
|
+
* A flag determining whether the amount should be approved within
|
|
22
|
+
* the execution of this function. If set to `false` it will
|
|
23
|
+
* throw an error when the withdraw amount exceeds allowance.
|
|
24
|
+
*/
|
|
25
|
+
approve?: boolean;
|
|
26
|
+
/** The optional deposit asset. */
|
|
27
|
+
token?: Token;
|
|
28
|
+
/** The vault identifier. */
|
|
29
|
+
vaultKey?: Vault;
|
|
30
|
+
} & CommonWriteParameters;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Queues withdrawal from the DeFi vault.
|
|
34
|
+
* @param {QueueWithdrawParameters} parameters - The parameters.
|
|
35
|
+
* @param {BigNumber.Value} parameters.amount - The deposit amount.
|
|
36
|
+
* @param {boolean} parameters.approve - The optional flag determining whether approve actions should be performed.
|
|
37
|
+
* @param {Token} parameters.token - The optional deposit asset.
|
|
38
|
+
* @param {Vault} parameters.vaultKey - The vault identifier.
|
|
39
|
+
* @param {Address} parameters.account - The EVM account address.
|
|
40
|
+
* @param {ChainId} parameters.chainId - The chain id.
|
|
41
|
+
* @param {EIP1193Provider} parameters.provider - The EIP1193 provider.
|
|
42
|
+
* @param {string} parameters.rpcUrl - The optional rpc url.
|
|
43
|
+
*
|
|
44
|
+
* @returns {Promise<Hash>}
|
|
45
|
+
*/
|
|
46
|
+
export async function queueWithdraw({
|
|
47
|
+
amount: amountRaw,
|
|
48
|
+
approve = true,
|
|
49
|
+
token = 'LBTC',
|
|
50
|
+
vaultKey = Vault.Veda,
|
|
51
|
+
account,
|
|
52
|
+
chainId,
|
|
53
|
+
provider,
|
|
54
|
+
rpcUrl,
|
|
55
|
+
env,
|
|
56
|
+
}: QueueWithdrawParameters) {
|
|
57
|
+
const vault = VAULTS[vaultKey];
|
|
58
|
+
if (!vault) {
|
|
59
|
+
throw new Error(`Unknown vault key: ${vaultKey}`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (!isVedaVaultChain(chainId)) {
|
|
63
|
+
throw new Error(
|
|
64
|
+
`Unsupported chain id: ${chainId}. Please switch to one of the supported chains: ${vault.chains.join(', ')}`,
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const publicClient = makePublicClient({ chainId, rpcUrl });
|
|
69
|
+
const walletClient = makeWalletClient({ provider, chainId });
|
|
70
|
+
|
|
71
|
+
const withdrawToken = await getTokenInfo(token, chainId, env, rpcUrl);
|
|
72
|
+
if (!withdrawToken) {
|
|
73
|
+
throw new Error(`Unknown withdraw token: ${token}`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const amount = BigNumber(amountRaw);
|
|
77
|
+
const amountBase = toBigInt(toBaseDenomination(amount, vault.decimals));
|
|
78
|
+
|
|
79
|
+
const balanceRaw = await publicClient.readContract({
|
|
80
|
+
address: vault.lensContract.address,
|
|
81
|
+
abi: vault.lensContract.abi,
|
|
82
|
+
functionName: 'balanceOf',
|
|
83
|
+
args: [account, vault.vaultContract.address],
|
|
84
|
+
});
|
|
85
|
+
const balance = fromBaseDenomination(String(balanceRaw), vault.decimals);
|
|
86
|
+
|
|
87
|
+
const allowanceRaw = await publicClient.readContract({
|
|
88
|
+
address: vault.vaultContract.address,
|
|
89
|
+
abi: vault.vaultContract.abi,
|
|
90
|
+
functionName: 'allowance',
|
|
91
|
+
args: [account, vault.withdrawQueueContracts[chainId].address],
|
|
92
|
+
});
|
|
93
|
+
const allowance = fromBaseDenomination(String(allowanceRaw), vault.decimals);
|
|
94
|
+
|
|
95
|
+
// check if amount exceeds balance
|
|
96
|
+
if (amount.isGreaterThan(balance)) {
|
|
97
|
+
throw new Error(
|
|
98
|
+
`The withdraw amount exceeds the account's balance. \nWithdraw amount: ${amount.toFixed()} \nBalance: ${balance.toFixed()}`,
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// check if amount exceeds allowance
|
|
103
|
+
if (amount.isGreaterThan(allowance)) {
|
|
104
|
+
const exceededMessage = `The withdraw amount exceeds allowance. \nWithdraw amount: ${amount.toFixed()} \nAllowance: ${allowance.toFixed()}`;
|
|
105
|
+
if (!approve) {
|
|
106
|
+
throw new Error(exceededMessage);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// try to approve new amount
|
|
110
|
+
try {
|
|
111
|
+
console.info(`Trying to approve ${amountBase}`);
|
|
112
|
+
const { request } = await publicClient.simulateContract({
|
|
113
|
+
account,
|
|
114
|
+
chain: CHAIN_ID_TO_VIEM_CHAIN_MAP[chainId],
|
|
115
|
+
address: vault.vaultContract.address,
|
|
116
|
+
abi: vault.vaultContract.abi,
|
|
117
|
+
functionName: 'approve',
|
|
118
|
+
args: [vault.withdrawQueueContracts[chainId].address, amountBase],
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const txHash = await walletClient.writeContract(request);
|
|
122
|
+
console.info(`Approve tx hash: ${txHash}`);
|
|
123
|
+
console.info(`Approved ${amountBase} for ${vault.vaultContract.address}`);
|
|
124
|
+
} catch (err) {
|
|
125
|
+
const msg = getErrorMessage(err);
|
|
126
|
+
throw new Error(
|
|
127
|
+
`Could not approve ${amountBase} for ${vault.vaultContract.address}. \nReason: ${msg}`,
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// queue withdraw vault token to wihdraw token via the withdraw queue contract
|
|
133
|
+
const expiry = BigNumber(Date.now())
|
|
134
|
+
.dividedBy(1000)
|
|
135
|
+
.plus(BigNumber(vault.queueWithdrawDaysValid).multipliedBy(DAY / 1000))
|
|
136
|
+
.decimalPlaces(0, BigNumber.ROUND_DOWN); // expiry = now(seconds) + days(seconds)
|
|
137
|
+
|
|
138
|
+
const discount = BigNumber(vault.queueWithdrawDiscountPercent).multipliedBy(
|
|
139
|
+
10000, // 1% = 10000
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
const { request } = await publicClient.simulateContract({
|
|
143
|
+
account,
|
|
144
|
+
chain: CHAIN_ID_TO_VIEM_CHAIN_MAP[chainId],
|
|
145
|
+
address: vault.withdrawQueueContracts[chainId].address,
|
|
146
|
+
abi: vault.withdrawQueueContracts[chainId].abi,
|
|
147
|
+
functionName: 'safeUpdateAtomicRequest',
|
|
148
|
+
args: [
|
|
149
|
+
vault.vaultContract.address,
|
|
150
|
+
withdrawToken.address,
|
|
151
|
+
[expiry.toFixed(0), 0n, amountBase, false],
|
|
152
|
+
vault.accountantContract.address,
|
|
153
|
+
discount.toFixed(0),
|
|
154
|
+
],
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
const txHash = await walletClient.writeContract(request);
|
|
158
|
+
return txHash;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export type CancelWithdrawParameters = Pick<
|
|
162
|
+
QueueWithdrawParameters,
|
|
163
|
+
'token' | 'vaultKey'
|
|
164
|
+
> &
|
|
165
|
+
CommonWriteParameters;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Cancels queued withdrawal.
|
|
169
|
+
* @param {CancelWithdrawParameters} parameters - The parameters.
|
|
170
|
+
* @param {Token} parameters.token - The optional deposit asset.
|
|
171
|
+
* @param {Vault} parameters.vaultKey - The vault identifier.
|
|
172
|
+
* @param {Address} parameters.account - The EVM account address.
|
|
173
|
+
* @param {ChainId} parameters.chainId - The chain id.
|
|
174
|
+
* @param {EIP1193Provider} parameters.provider - The EIP1193 provider.
|
|
175
|
+
* @param {string} parameters.rpcUrl - The optional rpc url.
|
|
176
|
+
*
|
|
177
|
+
* @returns {Promise<Hash>}
|
|
178
|
+
* @returns
|
|
179
|
+
*/
|
|
180
|
+
export async function cancelWithdraw({
|
|
181
|
+
token = 'LBTC',
|
|
182
|
+
vaultKey = Vault.Veda,
|
|
183
|
+
account,
|
|
184
|
+
chainId,
|
|
185
|
+
provider,
|
|
186
|
+
rpcUrl,
|
|
187
|
+
env,
|
|
188
|
+
}: CancelWithdrawParameters) {
|
|
189
|
+
const vault = VAULTS[vaultKey];
|
|
190
|
+
if (!vault) {
|
|
191
|
+
throw new Error(`Unknown vault key: ${vaultKey}`);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (!isVedaVaultChain(chainId)) {
|
|
195
|
+
throw new Error(
|
|
196
|
+
`Unsupported chain id: ${chainId}. Please switch to one of the supported chains: ${vault.chains.join(', ')}`,
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const publicClient = makePublicClient({ chainId, rpcUrl });
|
|
201
|
+
const walletClient = makeWalletClient({ provider, chainId });
|
|
202
|
+
|
|
203
|
+
const withdrawToken = await getTokenInfo(token, chainId, env, rpcUrl);
|
|
204
|
+
if (!withdrawToken) {
|
|
205
|
+
throw new Error(`Unknown withdraw token: ${token}`);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// cancel withdrawal via withdraw queue contract
|
|
209
|
+
const { request } = await publicClient.simulateContract({
|
|
210
|
+
account,
|
|
211
|
+
chain: CHAIN_ID_TO_VIEM_CHAIN_MAP[chainId],
|
|
212
|
+
address: vault.withdrawQueueContracts[chainId].address,
|
|
213
|
+
abi: vault.withdrawQueueContracts[chainId].abi,
|
|
214
|
+
functionName: 'updateAtomicRequest',
|
|
215
|
+
args: [
|
|
216
|
+
vault.vaultContract.address,
|
|
217
|
+
withdrawToken.address,
|
|
218
|
+
[0, 0, 0, false],
|
|
219
|
+
],
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
const txHash = await walletClient.writeContract(request);
|
|
223
|
+
return txHash;
|
|
224
|
+
}
|
package/src/common/const.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { Env } from '@lombard.finance/sdk-common';
|
|
2
|
-
|
|
3
|
-
export const SUI_DEVNET_CHAIN = 'sui:devnet' as const;
|
|
4
|
-
export const SUI_TESTNET_CHAIN = 'sui:testnet' as const;
|
|
5
|
-
export const SUI_LOCALNET_CHAIN = 'sui:localnet' as const;
|
|
6
|
-
export const SUI_MAINNET_CHAIN = 'sui:mainnet' as const;
|
|
7
|
-
|
|
8
|
-
export type SuiChain =
|
|
9
|
-
| typeof SUI_DEVNET_CHAIN
|
|
10
|
-
| typeof SUI_TESTNET_CHAIN
|
|
11
|
-
| typeof SUI_LOCALNET_CHAIN
|
|
12
|
-
| typeof SUI_MAINNET_CHAIN;
|
|
13
|
-
|
|
14
|
-
export const OChainId = {
|
|
15
|
-
ethereum: 1,
|
|
16
|
-
holesky: 17000,
|
|
17
|
-
binanceSmartChain: 56,
|
|
18
|
-
binanceSmartChainTestnet: 97,
|
|
19
|
-
sepolia: 11155111,
|
|
20
|
-
base: 8453,
|
|
21
|
-
baseSepoliaTestnet: 84532,
|
|
22
|
-
berachain: 80094,
|
|
23
|
-
berachainBartioTestnet: 80084,
|
|
24
|
-
corn: 21000000,
|
|
25
|
-
swell: 1923,
|
|
26
|
-
sonic: 146,
|
|
27
|
-
sonicBlazeTestnet: 57054,
|
|
28
|
-
morph: 2818,
|
|
29
|
-
morphHolesky: 2810,
|
|
30
|
-
etherlink: 42793,
|
|
31
|
-
} as const;
|
|
32
|
-
|
|
33
|
-
export type TChainId = (typeof OChainId)[keyof typeof OChainId];
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Abstract EIP-1193 provider
|
|
37
|
-
*/
|
|
38
|
-
export interface IEIP1193Provider {
|
|
39
|
-
request: (args: unknown) => Promise<unknown>;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export const getEthNetworkByEnv = (env: Env) =>
|
|
43
|
-
env === Env.prod ? OChainId.ethereum : OChainId.holesky;
|
|
44
|
-
|
|
45
|
-
export const getBscNetworkByEnv = (env: Env) =>
|
|
46
|
-
env === Env.prod
|
|
47
|
-
? OChainId.binanceSmartChain
|
|
48
|
-
: OChainId.binanceSmartChainTestnet;
|
|
49
|
-
|
|
50
|
-
export const getBaseNetworkByEnv = (env: Env) =>
|
|
51
|
-
env === Env.prod ? OChainId.base : OChainId.baseSepoliaTestnet;
|
|
52
|
-
|
|
53
|
-
export const getSuiNetworkByEnv = (env: Env) =>
|
|
54
|
-
env === Env.prod ? 'sui:mainnet' : 'sui:testnet';
|
|
55
|
-
|
|
56
|
-
export const getSonicNetworkByEnv = (env: Env) =>
|
|
57
|
-
env === Env.prod ? OChainId.sonic : OChainId.sonicBlazeTestnet;
|
package/src/provider/Provider.ts
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import Web3, { Contract, ContractAbi, Transaction, utils } from 'web3';
|
|
2
|
-
import { IEIP1193Provider } from '../common/types/types';
|
|
3
|
-
import { IReadProviderParams, ReadProvider } from './ReadProvider';
|
|
4
|
-
import {
|
|
5
|
-
TRpcUrlConfig,
|
|
6
|
-
rpcUrlConfig as defaultRpcUrlConfig,
|
|
7
|
-
} from './rpcUrlConfig';
|
|
8
|
-
import { ISendOptions, IWeb3SendResult } from './types';
|
|
9
|
-
|
|
10
|
-
export interface IProviderParams extends IReadProviderParams {
|
|
11
|
-
/**
|
|
12
|
-
* The EIP-1193 provider instance.
|
|
13
|
-
*/
|
|
14
|
-
provider: IEIP1193Provider;
|
|
15
|
-
/**
|
|
16
|
-
* The сurrent account address.
|
|
17
|
-
*/
|
|
18
|
-
account: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Provider for interacting with a blockchain network.
|
|
23
|
-
*/
|
|
24
|
-
export class Provider extends ReadProvider {
|
|
25
|
-
web3: Web3;
|
|
26
|
-
account: string;
|
|
27
|
-
rpcConfig: TRpcUrlConfig = defaultRpcUrlConfig;
|
|
28
|
-
|
|
29
|
-
constructor({ provider, account, chainId, rpcUrlConfig }: IProviderParams) {
|
|
30
|
-
super({ chainId, rpcUrlConfig });
|
|
31
|
-
this.web3 = new Web3(provider);
|
|
32
|
-
this.account = account;
|
|
33
|
-
this.chainId = chainId;
|
|
34
|
-
this.rpcConfig = { ...defaultRpcUrlConfig, ...rpcUrlConfig };
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Signs a message using the current provider and account.
|
|
39
|
-
* @public
|
|
40
|
-
* @param message - The message to be signed.
|
|
41
|
-
* @returns A promise that resolves to the signed message as a string.
|
|
42
|
-
*/
|
|
43
|
-
public async signMessage(message: string) {
|
|
44
|
-
const { account } = this;
|
|
45
|
-
|
|
46
|
-
const messageHex = `0x${Buffer.from(message, 'utf8').toString('hex')}`;
|
|
47
|
-
|
|
48
|
-
const ethereum = this.web3.currentProvider;
|
|
49
|
-
if (!ethereum) {
|
|
50
|
-
throw new Error('Undefined provider');
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return ethereum.request({
|
|
54
|
-
method: 'personal_sign',
|
|
55
|
-
params: [messageHex, account],
|
|
56
|
-
}) as unknown as Promise<string>;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Custom replacement for web3js [send](https://docs.web3js.org/libdocs/Contract#send).
|
|
61
|
-
*
|
|
62
|
-
* @public
|
|
63
|
-
* @param {string} from - Address of the sender.
|
|
64
|
-
* @param {string} to - Address of the recipient.
|
|
65
|
-
* @param {ISendOptions} sendOptions - Options for sending transaction.
|
|
66
|
-
* @returns {Promise<IWeb3SendResult>} Promise with transaction hash and receipt promise.
|
|
67
|
-
*/
|
|
68
|
-
public async sendTransactionAsync(
|
|
69
|
-
from: string,
|
|
70
|
-
to: string,
|
|
71
|
-
sendOptions: ISendOptions,
|
|
72
|
-
): Promise<IWeb3SendResult> {
|
|
73
|
-
const { chainId, web3: web3Write } = this;
|
|
74
|
-
const web3Read = this.getReadWeb3();
|
|
75
|
-
|
|
76
|
-
const {
|
|
77
|
-
data,
|
|
78
|
-
estimate = false,
|
|
79
|
-
estimateFee = false,
|
|
80
|
-
extendedGasLimit,
|
|
81
|
-
gasLimit = '0',
|
|
82
|
-
value = '0',
|
|
83
|
-
gasLimitMultiplier = 1,
|
|
84
|
-
} = sendOptions;
|
|
85
|
-
let { nonce } = sendOptions;
|
|
86
|
-
|
|
87
|
-
if (!nonce) {
|
|
88
|
-
nonce = await web3Read.eth.getTransactionCount(from);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
console.log(`Nonce: ${nonce}`);
|
|
92
|
-
|
|
93
|
-
const tx: Transaction = {
|
|
94
|
-
from,
|
|
95
|
-
to,
|
|
96
|
-
value: utils.numberToHex(value),
|
|
97
|
-
data,
|
|
98
|
-
nonce,
|
|
99
|
-
chainId: utils.numberToHex(chainId),
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
if (estimate) {
|
|
103
|
-
try {
|
|
104
|
-
const estimatedGas = await web3Read.eth.estimateGas(tx);
|
|
105
|
-
|
|
106
|
-
const multipliedGasLimit = Math.round(
|
|
107
|
-
Number(estimatedGas) * gasLimitMultiplier,
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
if (extendedGasLimit) {
|
|
111
|
-
tx.gas = utils.numberToHex(multipliedGasLimit + extendedGasLimit);
|
|
112
|
-
} else {
|
|
113
|
-
tx.gas = utils.numberToHex(multipliedGasLimit);
|
|
114
|
-
}
|
|
115
|
-
} catch (e) {
|
|
116
|
-
throw new Error(
|
|
117
|
-
(e as Partial<Error>).message ??
|
|
118
|
-
'Failed to estimate gas limit for transaction.',
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
} else {
|
|
122
|
-
tx.gas = utils.numberToHex(gasLimit);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const { maxFeePerGas, maxPriorityFeePerGas } = estimateFee
|
|
126
|
-
? await this.getMaxFees().catch(() => sendOptions)
|
|
127
|
-
: sendOptions;
|
|
128
|
-
|
|
129
|
-
if (maxPriorityFeePerGas !== undefined) {
|
|
130
|
-
tx.maxPriorityFeePerGas = utils.numberToHex(maxPriorityFeePerGas);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (maxFeePerGas !== undefined) {
|
|
134
|
-
tx.maxFeePerGas = utils.numberToHex(maxFeePerGas);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (!tx.maxFeePerGas && !tx.maxPriorityFeePerGas) {
|
|
138
|
-
const safeGasPrice = await this.getSafeGasPriceWei();
|
|
139
|
-
tx.gasPrice = safeGasPrice.toString(10);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (!tx.maxFeePerGas && !tx.maxPriorityFeePerGas) {
|
|
143
|
-
const safeGasPrice = await this.getSafeGasPriceWei();
|
|
144
|
-
tx.gasPrice = safeGasPrice.toString(10);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
console.log('Sending transaction via Web3: ', tx);
|
|
148
|
-
|
|
149
|
-
return new Promise((resolve, reject) => {
|
|
150
|
-
const promise = web3Write.eth.sendTransaction(tx);
|
|
151
|
-
|
|
152
|
-
promise
|
|
153
|
-
.once('transactionHash', async (transactionHash: string) => {
|
|
154
|
-
console.log(`Just signed transaction has is: ${transactionHash}`);
|
|
155
|
-
|
|
156
|
-
resolve({
|
|
157
|
-
receiptPromise: promise,
|
|
158
|
-
transactionHash,
|
|
159
|
-
});
|
|
160
|
-
})
|
|
161
|
-
.catch(reject);
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
public createContract<AbiType extends ContractAbi>(
|
|
166
|
-
abi: AbiType,
|
|
167
|
-
address: string,
|
|
168
|
-
): Contract<AbiType> {
|
|
169
|
-
return new this.web3.eth.Contract<AbiType>(abi, address);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import BigNumber from 'bignumber.js';
|
|
2
|
-
import { Web3, Contract, ContractAbi } from 'web3';
|
|
3
|
-
import {
|
|
4
|
-
TRpcUrlConfig,
|
|
5
|
-
rpcUrlConfig as defaultRpcUrlConfig,
|
|
6
|
-
} from './rpcUrlConfig';
|
|
7
|
-
import { IGetMaxFeesResult } from './types';
|
|
8
|
-
import { getMaxPriorityFeePerGas } from './utils/getMaxPriorityFeePerGas';
|
|
9
|
-
|
|
10
|
-
const FEE_MULTIPLIER = 2;
|
|
11
|
-
const ADDITIONAL_SAFE_GAS_PRICE_WEI = 25_000;
|
|
12
|
-
|
|
13
|
-
export interface IReadProviderParams {
|
|
14
|
-
/**
|
|
15
|
-
* Chain ID of the network to interact with.
|
|
16
|
-
*/
|
|
17
|
-
chainId: number;
|
|
18
|
-
/**
|
|
19
|
-
* The RPC URL configuration. If not provided, the default configuration will be used.
|
|
20
|
-
*/
|
|
21
|
-
rpcUrlConfig?: TRpcUrlConfig;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export class ReadProvider {
|
|
25
|
-
chainId: number;
|
|
26
|
-
rpcConfig: TRpcUrlConfig;
|
|
27
|
-
|
|
28
|
-
constructor({ chainId, rpcUrlConfig }: IReadProviderParams) {
|
|
29
|
-
this.chainId = chainId;
|
|
30
|
-
this.rpcConfig = { ...defaultRpcUrlConfig, ...rpcUrlConfig };
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Returns web3 instance for read operations.
|
|
35
|
-
*
|
|
36
|
-
* @public
|
|
37
|
-
* @returns {Web3} Web3 instance.
|
|
38
|
-
*/
|
|
39
|
-
public getReadWeb3(): Web3 {
|
|
40
|
-
const rpcUrl = this.getRpcUrl();
|
|
41
|
-
const readWeb3 = new Web3();
|
|
42
|
-
const provider = new Web3.providers.HttpProvider(rpcUrl);
|
|
43
|
-
readWeb3.setProvider(provider);
|
|
44
|
-
return readWeb3;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Retrieves the RPC URL based on the current chain ID.
|
|
49
|
-
* @returns The RPC URL for the current chain ID.
|
|
50
|
-
* @throws Error if the RPC URL for the current chain ID is not found.
|
|
51
|
-
*/
|
|
52
|
-
getRpcUrl(): string {
|
|
53
|
-
const { chainId } = this;
|
|
54
|
-
const rpcUrl = this.rpcConfig?.[chainId];
|
|
55
|
-
|
|
56
|
-
if (!rpcUrl) {
|
|
57
|
-
console.error(
|
|
58
|
-
`You might need to add the rpcConfig for the ${chainId} chain ID when creating the provider.`,
|
|
59
|
-
);
|
|
60
|
-
throw new Error(`RPC URL for chainId ${chainId} not found`);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return rpcUrl;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Calculates max fees for transaction. Thess values are available for networks
|
|
68
|
-
* with EIP-1559 support.
|
|
69
|
-
*
|
|
70
|
-
* @public
|
|
71
|
-
* @note If current network is Binance Smart Chain, will return default values.
|
|
72
|
-
* @returns {Promise<IGetMaxFeesResult>} Max fees for transaction.
|
|
73
|
-
*/
|
|
74
|
-
public async getMaxFees(): Promise<IGetMaxFeesResult> {
|
|
75
|
-
const web3 = this.getReadWeb3();
|
|
76
|
-
const rpcUrl = this.getRpcUrl();
|
|
77
|
-
|
|
78
|
-
const [block, maxPriorityFeePerGas] = await Promise.all([
|
|
79
|
-
web3.eth.getBlock('latest'),
|
|
80
|
-
getMaxPriorityFeePerGas(rpcUrl),
|
|
81
|
-
]);
|
|
82
|
-
|
|
83
|
-
if (!block?.baseFeePerGas && typeof block?.baseFeePerGas !== 'bigint') {
|
|
84
|
-
return {};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const maxFeePerGas = new BigNumber(block.baseFeePerGas.toString(10))
|
|
88
|
-
.multipliedBy(FEE_MULTIPLIER)
|
|
89
|
-
.plus(maxPriorityFeePerGas);
|
|
90
|
-
|
|
91
|
-
return {
|
|
92
|
-
maxFeePerGas: +maxFeePerGas,
|
|
93
|
-
maxPriorityFeePerGas: +maxPriorityFeePerGas,
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Returns safe gas price for transaction.
|
|
99
|
-
*
|
|
100
|
-
* @public
|
|
101
|
-
* @returns {Promise<BigNumber>} Safe gas price.
|
|
102
|
-
*/
|
|
103
|
-
public async getSafeGasPriceWei(): Promise<BigNumber> {
|
|
104
|
-
const pureGasPriceWei = await this.getReadWeb3().eth.getGasPrice();
|
|
105
|
-
|
|
106
|
-
return new BigNumber(pureGasPriceWei.toString(10)).plus(
|
|
107
|
-
ADDITIONAL_SAFE_GAS_PRICE_WEI,
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Creates a contract instance with the given ABI and address.
|
|
113
|
-
*
|
|
114
|
-
* @template AbiType - The type of the contract ABI.
|
|
115
|
-
* @param {any} abi - The ABI of the contract.
|
|
116
|
-
* @param {string} address - The address of the contract.
|
|
117
|
-
* @returns {Contract<AbiType>} The contract instance.
|
|
118
|
-
*/
|
|
119
|
-
public createContract<AbiType extends ContractAbi>(
|
|
120
|
-
abi: AbiType,
|
|
121
|
-
address: string,
|
|
122
|
-
): Contract<AbiType> {
|
|
123
|
-
const web3 = this.getReadWeb3();
|
|
124
|
-
return new web3.eth.Contract<AbiType>(abi, address);
|
|
125
|
-
}
|
|
126
|
-
}
|
package/src/provider/index.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { OChainId } from '../common/types/types';
|
|
2
|
-
|
|
3
|
-
export type TRpcUrlConfig = Record<number, string>;
|
|
4
|
-
|
|
5
|
-
export const RPC_URL = 'https://bff.prod.lombard.finance/multi-rpc/proxy';
|
|
6
|
-
|
|
7
|
-
export const rpcUrlConfig: TRpcUrlConfig = {
|
|
8
|
-
[OChainId.ethereum]: `${RPC_URL}/eth`,
|
|
9
|
-
[OChainId.holesky]: `${RPC_URL}/eth_holesky`,
|
|
10
|
-
[OChainId.sepolia]: `${RPC_URL}/eth_sepolia`,
|
|
11
|
-
[OChainId.base]: `${RPC_URL}/base`,
|
|
12
|
-
[OChainId.baseSepoliaTestnet]: `${RPC_URL}/base_sepolia`,
|
|
13
|
-
[OChainId.binanceSmartChain]: 'https://bsc-dataseed.bnbchain.org',
|
|
14
|
-
[OChainId.binanceSmartChainTestnet]:
|
|
15
|
-
'https://bsc-testnet-dataseed.bnbchain.org',
|
|
16
|
-
[OChainId.corn]: `${RPC_URL}/corn_maizenet`,
|
|
17
|
-
[OChainId.sonic]: `${RPC_URL}/sonic_mainnet`,
|
|
18
|
-
[OChainId.sonicBlazeTestnet]: `${RPC_URL}/sonic_blaze_testnet`,
|
|
19
|
-
};
|
package/src/provider/types.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { core, eth, FMT_BYTES, FMT_NUMBER, TransactionReceipt } from 'web3';
|
|
2
|
-
|
|
3
|
-
export interface IGetMaxFeesResult {
|
|
4
|
-
maxPriorityFeePerGas?: number;
|
|
5
|
-
maxFeePerGas?: number;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export type PromiEvent<T> = core.Web3PromiEvent<
|
|
9
|
-
T,
|
|
10
|
-
eth.SendTransactionEvents<{
|
|
11
|
-
readonly number: FMT_NUMBER.BIGINT;
|
|
12
|
-
readonly bytes: FMT_BYTES.HEX;
|
|
13
|
-
}>
|
|
14
|
-
>;
|
|
15
|
-
|
|
16
|
-
export interface IWeb3SendResult {
|
|
17
|
-
receiptPromise: PromiEvent<TransactionReceipt>;
|
|
18
|
-
transactionHash: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface ISendOptions {
|
|
22
|
-
/**
|
|
23
|
-
* Txn data.
|
|
24
|
-
*/
|
|
25
|
-
data?: string;
|
|
26
|
-
/**
|
|
27
|
-
* Gas limit for transaction.
|
|
28
|
-
* @note When `estimate` is `true`, this value will be redefined by estimated gas limit.
|
|
29
|
-
*/
|
|
30
|
-
gasLimit?: string;
|
|
31
|
-
/**
|
|
32
|
-
* Multiplier for gas limit when estimating gas.
|
|
33
|
-
* When specified, gas limit will be calculated as `gasLimit * gasLimitMultiplier`.
|
|
34
|
-
* @note works only when `estimate` is `true`.
|
|
35
|
-
* @default 1
|
|
36
|
-
*/
|
|
37
|
-
gasLimitMultiplier?: number;
|
|
38
|
-
value?: string;
|
|
39
|
-
/**
|
|
40
|
-
* When `true`, will estimate gas limit for transaction.
|
|
41
|
-
* @note `gasLimit` option will be redefined by estimated gas limit.
|
|
42
|
-
*/
|
|
43
|
-
estimate?: boolean;
|
|
44
|
-
/**
|
|
45
|
-
* When `true`, will estimate max fees for transaction.
|
|
46
|
-
* @note `maxPriorityFeePerGas` and `maxFeePerGas` options will be redefined by estimated values.
|
|
47
|
-
* @note Please use only for networks with EIP-1559 support.
|
|
48
|
-
*/
|
|
49
|
-
estimateFee?: boolean;
|
|
50
|
-
nonce?: bigint;
|
|
51
|
-
/**
|
|
52
|
-
* Additional gas limit for transaction.
|
|
53
|
-
* @note When `estimate` is `true`, this value will be added to estimated gas limit.
|
|
54
|
-
*/
|
|
55
|
-
extendedGasLimit?: number;
|
|
56
|
-
maxPriorityFeePerGas?: number;
|
|
57
|
-
maxFeePerGas?: number;
|
|
58
|
-
}
|