From d97626f5431c555cd4e39063fb6d84b73e1de1e1 Mon Sep 17 00:00:00 2001 From: Bill Date: Mon, 23 Oct 2023 12:02:05 -0700 Subject: [PATCH] Fix auto-deposit (#93) --- package.json | 2 +- pnpm-lock.yaml | 8 ++++---- src/constants/account.ts | 2 +- src/hooks/useSubaccount.tsx | 15 +++++---------- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 382986b..4f72566 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7a386c0..779a5f1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -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: diff --git a/src/constants/account.ts b/src/constants/account.ts index 8035d10..c353fe9 100644 --- a/src/constants/account.ts +++ b/src/constants/account.ts @@ -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; diff --git a/src/hooks/useSubaccount.tsx b/src/hooks/useSubaccount.tsx index a529fbe..955572c 100644 --- a/src/hooks/useSubaccount.tsx +++ b/src/hooks/useSubaccount.tsx @@ -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; }