Fix auto-deposit (#93)

This commit is contained in:
Bill 2023-10-23 12:02:05 -07:00 committed by GitHub
parent 835f82dbcc
commit d97626f543
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 16 deletions

View File

@ -39,7 +39,7 @@
"@cosmjs/proto-signing": "^0.31.0",
"@cosmjs/stargate": "^0.31.0",
"@cosmjs/tendermint-rpc": "^0.31.0",
"@dydxprotocol/v4-abacus": "^0.7.2",
"@dydxprotocol/v4-abacus": "^0.7.6",
"@dydxprotocol/v4-client-js": "^0.40.3",
"@dydxprotocol/v4-localization": "^0.1.30",
"@ethersproject/providers": "^5.7.2",

8
pnpm-lock.yaml generated
View File

@ -27,8 +27,8 @@ dependencies:
specifier: ^0.31.0
version: 0.31.0
'@dydxprotocol/v4-abacus':
specifier: ^0.7.2
version: 0.7.2
specifier: ^0.7.6
version: 0.7.6
'@dydxprotocol/v4-client-js':
specifier: ^0.40.3
version: 0.40.3
@ -979,8 +979,8 @@ packages:
resolution: {integrity: sha512-RpfLEtTlyIxeNPGKcokS+p3BZII/Q3bYxryFRglh5H3A3T8q9fsLYm72VYAMEOOIBLEa8o93kFLiBDUWKrwXZA==}
dev: true
/@dydxprotocol/v4-abacus@0.7.2:
resolution: {integrity: sha512-5foamomN82FH6ko3EuzwFlSoAEY6Sal8fDgvZo2RsB19Ks6SFgFDeeOcEDdfoa3DNwvl8yW0C9cfxeQ+BfU8uA==}
/@dydxprotocol/v4-abacus@0.7.6:
resolution: {integrity: sha512-FdDXRaFMfxhyrJJs0dNrb1KG6X95lPHelua1yCn/SVgzwGaAqlJczrzmdh98INntuRAgIxOu69R5mCGyekumyg==}
dev: false
/@dydxprotocol/v4-client-js@0.40.3:

View File

@ -44,4 +44,4 @@ export type EvmDerivedAddresses = {
};
};
export const AMOUNT_RESERVED_FOR_GAS_USDC = 100_000;
export const AMOUNT_RESERVED_FOR_GAS_USDC = 0.1;

View File

@ -74,13 +74,12 @@ export const useSubaccountContext = ({ localDydxWallet }: { localDydxWallet?: Lo
() => ({
depositToSubaccount: async ({
subaccountClient,
assetId = 0,
amount,
}: {
subaccountClient: SubaccountClient;
assetId?: number;
amount: Long;
}) => await compositeClient?.validatorClient.post.deposit(subaccountClient, assetId, amount),
amount: number;
}) => await compositeClient?.depositToSubaccount(subaccountClient, amount.toString()),
withdrawFromSubaccount: async ({
subaccountClient,
@ -201,13 +200,9 @@ export const useSubaccountContext = ({ localDydxWallet }: { localDydxWallet?: Lo
async (balance: AccountBalance) => {
if (!localDydxWallet) return;
const amountAfterDust = MustBigNumber(balance.amount)
.minus(AMOUNT_RESERVED_FOR_GAS_USDC) // keep 0.1 USDC in user's wallet for gas
.toString();
const amount = parseFloat(balance.amount) - AMOUNT_RESERVED_FOR_GAS_USDC;
const amount = Long.fromString(amountAfterDust || '0');
if (amount.greaterThan(Long.ZERO)) {
if (amount > 0) {
const subaccountClient = new SubaccountClient(localDydxWallet, 0);
await depositToSubaccount({ amount, subaccountClient });
}
@ -225,7 +220,7 @@ export const useSubaccountContext = ({ localDydxWallet }: { localDydxWallet?: Lo
}, [usdcCoinBalance]);
const deposit = useCallback(
async (amount: Long) => {
async (amount: number) => {
if (!subaccountClient) {
return;
}