Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2ca1c94e55 | ||
|
|
6abb2dd7c0 | ||
|
|
f7a362db34 | ||
|
|
5cb0624c0c |
@@ -1,9 +1,6 @@
|
||||
Copyright (C) 2023 dYdX Trading Inc.
|
||||
|
||||
Subject to your compliance with applicable law and the v4 Terms of Use, available at dydx.exchange/legal, you are granted the right to use the Program or Licensed Work (defined below) under the terms of the GNU Affero General Public License as set forth below; provided, however, that if you violate any such applicable law in your use of the Program or Licensed Work, all of your rights and licenses to use (including any rights to reproduce, distribute, install or modify) the Program or Licensed Work will automatically and immediately terminate.
|
||||
|
||||
|
||||
The “Program” or “Licensed Work” shall mean any of the following: dydxprotocol/cosmos-sdk, dydxprotocol/cometbft, dydxprotocol/v4-chain, dydxprotocol/v4-clients, dydxprotocol/v4-web, dydxprotocol/v4-abacus, dydxprotocol/v4-localization, dydxprotocol/v4-documentation, and any dYdX or dYdX Trading Inc. repository reflecting a copy of, or link to, this license.
|
||||
Subject to your compliance with applicable law, you are granted the right to use the Licensed Work (defined below) under the terms of the GNU Affero General Public License as set forth below; provided, however, that if you violate any such applicable law in your use of the Licensed Work, all of your rights and licenses to use (including any rights to reproduce, distribute, install or modify) the Licensed Work will automatically and immediately terminate.
|
||||
|
||||
|
||||
The GNU Affero General Public License
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
{
|
||||
"apps": {
|
||||
"iOS": {
|
||||
"scheme": "dydxv4"
|
||||
}
|
||||
},
|
||||
"deployments": {
|
||||
"MAINNET": {
|
||||
"environments": [
|
||||
@@ -208,8 +203,8 @@
|
||||
"endpoints": {
|
||||
"indexers": [
|
||||
{
|
||||
"api": "https://indexer.v4dev4.dydx.exchange",
|
||||
"socket": "wss://indexer.v4dev4.dydx.exchange"
|
||||
"api": "http://indexer.v4dev4.dydx.exchange",
|
||||
"socket": "ws://indexer.v4dev4.dydx.exchange"
|
||||
}
|
||||
],
|
||||
"validators": [
|
||||
|
||||
+54
-91
@@ -48,7 +48,7 @@ export const useSubaccount = () => useContext(SubaccountContext);
|
||||
|
||||
export const useSubaccountContext = ({ localDydxWallet }: { localDydxWallet?: LocalWallet }) => {
|
||||
const dispatch = useDispatch();
|
||||
const { usdcDenom, usdcDecimals } = useTokenConfigs();
|
||||
const { usdcDenom } = useTokenConfigs();
|
||||
const { compositeClient, faucetClient } = useDydxClient();
|
||||
|
||||
const { getFaucetFunds } = useMemo(
|
||||
@@ -79,34 +79,16 @@ export const useSubaccountContext = ({ localDydxWallet }: { localDydxWallet?: Lo
|
||||
subaccountClient: SubaccountClient;
|
||||
assetId?: number;
|
||||
amount: number;
|
||||
}) => {
|
||||
try {
|
||||
return await compositeClient?.depositToSubaccount(
|
||||
subaccountClient,
|
||||
amount.toFixed(usdcDecimals)
|
||||
);
|
||||
} catch (error) {
|
||||
log('useSubaccount/depositToSubaccount', error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
}) => await compositeClient?.depositToSubaccount(subaccountClient, amount.toString()),
|
||||
|
||||
withdrawFromSubaccount: async ({
|
||||
subaccountClient,
|
||||
amount,
|
||||
}: {
|
||||
subaccountClient: SubaccountClient;
|
||||
amount: number;
|
||||
}) => {
|
||||
try {
|
||||
return await compositeClient?.withdrawFromSubaccount(
|
||||
subaccountClient,
|
||||
amount.toFixed(usdcDecimals)
|
||||
);
|
||||
} catch (error) {
|
||||
log('useSubaccount/withdrawFromSubaccount', error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
}) => await compositeClient?.withdrawFromSubaccount(subaccountClient, amount.toString()),
|
||||
|
||||
transferFromSubaccountToAddress: async ({
|
||||
subaccountClient,
|
||||
assetId = 0,
|
||||
@@ -117,33 +99,27 @@ export const useSubaccountContext = ({ localDydxWallet }: { localDydxWallet?: Lo
|
||||
assetId?: number;
|
||||
amount: number;
|
||||
recipient: string;
|
||||
}) => {
|
||||
try {
|
||||
return await compositeClient?.validatorClient.post.send(
|
||||
subaccountClient?.wallet,
|
||||
() =>
|
||||
new Promise((resolve) => {
|
||||
const msg =
|
||||
compositeClient?.validatorClient.post.composer.composeMsgWithdrawFromSubaccount(
|
||||
subaccountClient.address,
|
||||
subaccountClient.subaccountNumber,
|
||||
assetId,
|
||||
Long.fromNumber(amount * QUANTUM_MULTIPLIER),
|
||||
recipient
|
||||
);
|
||||
}) =>
|
||||
await compositeClient?.validatorClient.post.send(
|
||||
subaccountClient?.wallet,
|
||||
() =>
|
||||
new Promise((resolve) => {
|
||||
const msg =
|
||||
compositeClient?.validatorClient.post.composer.composeMsgWithdrawFromSubaccount(
|
||||
subaccountClient.address,
|
||||
subaccountClient.subaccountNumber,
|
||||
assetId,
|
||||
Long.fromNumber(amount * QUANTUM_MULTIPLIER),
|
||||
recipient
|
||||
);
|
||||
|
||||
resolve([msg]);
|
||||
}),
|
||||
false,
|
||||
undefined,
|
||||
undefined,
|
||||
Method.BroadcastTxCommit
|
||||
);
|
||||
} catch (error) {
|
||||
log('useSubaccount/transferFromSubaccountToAddress', error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
resolve([msg]);
|
||||
}),
|
||||
false,
|
||||
undefined,
|
||||
undefined,
|
||||
Method.BroadcastTxCommit
|
||||
),
|
||||
|
||||
transferNativeToken: async ({
|
||||
subaccountClient,
|
||||
@@ -153,30 +129,24 @@ export const useSubaccountContext = ({ localDydxWallet }: { localDydxWallet?: Lo
|
||||
subaccountClient: SubaccountClient;
|
||||
amount: number;
|
||||
recipient: string;
|
||||
}) => {
|
||||
try {
|
||||
return await compositeClient?.validatorClient.post.send(
|
||||
subaccountClient.wallet,
|
||||
() =>
|
||||
new Promise((resolve) => {
|
||||
const msg = compositeClient?.sendTokenMessage(
|
||||
subaccountClient.wallet,
|
||||
amount.toString(),
|
||||
recipient
|
||||
);
|
||||
}) =>
|
||||
await compositeClient?.validatorClient.post.send(
|
||||
subaccountClient.wallet,
|
||||
() =>
|
||||
new Promise((resolve) => {
|
||||
const msg = compositeClient?.sendTokenMessage(
|
||||
subaccountClient.wallet,
|
||||
amount.toString(),
|
||||
recipient,
|
||||
);
|
||||
|
||||
resolve([msg]);
|
||||
}),
|
||||
false,
|
||||
compositeClient?.validatorClient?.post.defaultDydxGasPrice,
|
||||
undefined,
|
||||
Method.BroadcastTxCommit
|
||||
);
|
||||
} catch (error) {
|
||||
log('useSubaccount/transferNativeToken', error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
resolve([msg]);
|
||||
}),
|
||||
false,
|
||||
compositeClient?.validatorClient?.post.defaultDydxGasPrice,
|
||||
undefined,
|
||||
Method.BroadcastTxCommit
|
||||
),
|
||||
|
||||
sendSquidWithdrawFromSubaccount: async ({
|
||||
subaccountClient,
|
||||
@@ -188,27 +158,20 @@ export const useSubaccountContext = ({ localDydxWallet }: { localDydxWallet?: Lo
|
||||
payload: string;
|
||||
}) => {
|
||||
if (!compositeClient) throw new Error('client not initialized');
|
||||
try {
|
||||
const transaction = JSON.parse(payload);
|
||||
|
||||
const msg = compositeClient.withdrawFromSubaccountMessage(
|
||||
subaccountClient,
|
||||
amount.toFixed(usdcDecimals)
|
||||
);
|
||||
const ibcMsg: EncodeObject = {
|
||||
typeUrl: transaction.msgTypeUrl,
|
||||
value: transaction.msg,
|
||||
};
|
||||
const transaction = JSON.parse(payload);
|
||||
|
||||
return await compositeClient.send(
|
||||
subaccountClient.wallet,
|
||||
() => Promise.resolve([msg, ibcMsg]),
|
||||
false
|
||||
);
|
||||
} catch (error) {
|
||||
log('useSubaccount/sendSquidWithdrawFromSubaccount', error);
|
||||
throw error;
|
||||
}
|
||||
const msg = compositeClient.withdrawFromSubaccountMessage(subaccountClient, amount.toString());
|
||||
const ibcMsg: EncodeObject = {
|
||||
typeUrl: transaction.msgTypeUrl,
|
||||
value: transaction.msg,
|
||||
};
|
||||
|
||||
return await compositeClient.send(
|
||||
subaccountClient.wallet,
|
||||
() => Promise.resolve([msg, ibcMsg]),
|
||||
false
|
||||
);
|
||||
},
|
||||
}),
|
||||
[compositeClient]
|
||||
|
||||
@@ -19,10 +19,8 @@ export const useTokenConfigs = (): {
|
||||
},
|
||||
};
|
||||
usdcDenom: string;
|
||||
usdcDecimals: number;
|
||||
usdcLabel: string;
|
||||
chainTokenDenom: string;
|
||||
chainTokenDecimals: number;
|
||||
chainTokenLabel: string;
|
||||
} => {
|
||||
const { selectedNetwork } = useSelectedNetwork();
|
||||
@@ -31,10 +29,8 @@ export const useTokenConfigs = (): {
|
||||
return {
|
||||
tokensConfigs,
|
||||
usdcDenom: tokensConfigs[DydxChainAsset.USDC].denom,
|
||||
usdcDecimals: tokensConfigs[DydxChainAsset.USDC].decimals,
|
||||
usdcLabel: tokensConfigs[DydxChainAsset.USDC].name,
|
||||
chainTokenDenom: tokensConfigs[DydxChainAsset.CHAINTOKEN].denom,
|
||||
chainTokenDecimals: tokensConfigs[DydxChainAsset.CHAINTOKEN].decimals,
|
||||
chainTokenLabel: tokensConfigs[DydxChainAsset.CHAINTOKEN].name,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -131,7 +131,7 @@ export const AccountDetailsAndHistory = () => {
|
||||
key: 'BuyingPower',
|
||||
labelKey: STRING_KEYS.BUYING_POWER,
|
||||
type: OutputType.Fiat,
|
||||
value: MustBigNumber(buyingPower?.current).lt(0) ? undefined : buyingPower?.current, // show '-' when buying power is negative
|
||||
value: buyingPower?.current,
|
||||
},
|
||||
].filter(isTruthy);
|
||||
|
||||
|
||||
@@ -151,10 +151,7 @@ export const AccountInfoConnectedState = () => {
|
||||
),
|
||||
label: stringGetter({ key: STRING_KEYS.BUYING_POWER }),
|
||||
type: OutputType.Fiat,
|
||||
value:
|
||||
MustBigNumber(buyingPower?.current).lt(0) && buyingPower?.postOrder === null
|
||||
? undefined
|
||||
: buyingPower,
|
||||
value: buyingPower,
|
||||
},
|
||||
].map(
|
||||
({
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { type Dispatch, type SetStateAction, useState, type ReactNode } from 'react';
|
||||
import styled, { type AnyStyledComponent } from 'styled-components';
|
||||
import styled, { type AnyStyledComponent, } from 'styled-components';
|
||||
import { shallowEqual, useSelector } from 'react-redux';
|
||||
import type { RouteData } from '@0xsquid/sdk';
|
||||
|
||||
@@ -32,8 +32,6 @@ import { WithReceipt } from '@/components/WithReceipt';
|
||||
import { getSubaccountBuyingPower, getSubaccountEquity } from '@/state/accountSelectors';
|
||||
import { getTransferInputs } from '@/state/inputsSelectors';
|
||||
|
||||
import { MustBigNumber } from '@/lib/numbers';
|
||||
|
||||
import { SlippageEditor } from '../SlippageEditor';
|
||||
|
||||
type ElementProps = {
|
||||
@@ -133,7 +131,7 @@ export const DepositButtonAndReceipt = ({
|
||||
value: (
|
||||
<DiffOutput
|
||||
type={OutputType.Fiat}
|
||||
value={MustBigNumber(buyingPower).lt(0) ? undefined : buyingPower}
|
||||
value={buyingPower}
|
||||
newValue={newBuyingPower}
|
||||
sign={NumberSign.Positive}
|
||||
withDiff={Boolean(newBuyingPower) && buyingPower !== newBuyingPower}
|
||||
|
||||
@@ -36,7 +36,6 @@ import { truncateAddress } from '@/lib/wallet';
|
||||
|
||||
import { layoutMixins } from '@/styles/layoutMixins';
|
||||
import { headerMixins } from '@/styles/headerMixins';
|
||||
import { MustBigNumber } from '@/lib/numbers';
|
||||
|
||||
export const AccountMenu = () => {
|
||||
const stringGetter = useStringGetter();
|
||||
@@ -50,8 +49,6 @@ export const AccountMenu = () => {
|
||||
|
||||
const { evmAddress, walletType, dydxAddress, hdKey } = useAccounts();
|
||||
|
||||
const usdcBalance = freeCollateral?.current || 0;
|
||||
|
||||
const onRecoverKeys = () => {
|
||||
dispatch(openDialog({ type: DialogTypes.Onboarding }));
|
||||
};
|
||||
@@ -125,11 +122,7 @@ export const AccountMenu = () => {
|
||||
</Styled.label>
|
||||
<Styled.BalanceOutput type={OutputType.Asset} value={nativeTokenBalance} />
|
||||
</div>
|
||||
<AssetActions
|
||||
asset={DydxChainAsset.CHAINTOKEN}
|
||||
dispatch={dispatch}
|
||||
hasBalance={nativeTokenBalance.gt(0)}
|
||||
/>
|
||||
<AssetActions asset={DydxChainAsset.CHAINTOKEN} dispatch={dispatch} />
|
||||
</div>
|
||||
<div>
|
||||
<div>
|
||||
@@ -142,16 +135,11 @@ export const AccountMenu = () => {
|
||||
</Styled.label>
|
||||
<Styled.BalanceOutput
|
||||
type={OutputType.Asset}
|
||||
value={usdcBalance}
|
||||
value={freeCollateral?.current || 0}
|
||||
fractionDigits={2}
|
||||
/>
|
||||
</div>
|
||||
<AssetActions
|
||||
asset={DydxChainAsset.USDC}
|
||||
dispatch={dispatch}
|
||||
hasBalance={MustBigNumber(usdcBalance).gt(0)}
|
||||
withOnboarding
|
||||
/>
|
||||
<AssetActions asset={DydxChainAsset.USDC} dispatch={dispatch} withOnboarding />
|
||||
</div>
|
||||
</Styled.Balances>
|
||||
</Styled.AccountInfo>
|
||||
@@ -229,25 +217,22 @@ const AssetActions = memo(
|
||||
asset,
|
||||
dispatch,
|
||||
withOnboarding,
|
||||
hasBalance,
|
||||
}: {
|
||||
asset: DydxChainAsset;
|
||||
dispatch: Dispatch;
|
||||
withOnboarding?: boolean;
|
||||
hasBalance?: boolean;
|
||||
}) => (
|
||||
<Styled.InlineRow>
|
||||
{[
|
||||
withOnboarding &&
|
||||
hasBalance && {
|
||||
dialogType: DialogTypes.Withdraw,
|
||||
iconName: IconName.Withdraw,
|
||||
},
|
||||
withOnboarding && {
|
||||
dialogType: DialogTypes.Withdraw,
|
||||
iconName: IconName.Withdraw,
|
||||
},
|
||||
withOnboarding && {
|
||||
dialogType: DialogTypes.Deposit,
|
||||
iconName: IconName.Deposit,
|
||||
},
|
||||
hasBalance && {
|
||||
{
|
||||
dialogType: DialogTypes.Transfer,
|
||||
dialogProps: { selectedAsset: asset },
|
||||
iconName: IconName.Send,
|
||||
|
||||
Reference in New Issue
Block a user