Compare commits

..
Author SHA1 Message Date
Bill He 2ca1c94e55 grammar 2023-11-06 10:43:49 -08:00
Bill He 6abb2dd7c0 remove examples 2023-11-06 10:36:00 -08:00
Bill He f7a362db34 update 2023-11-06 10:33:02 -08:00
Bill He 5cb0624c0c Add Env var descriptions to readme 2023-11-06 10:30:47 -08:00
8 changed files with 69 additions and 138 deletions
+1 -4
View File
@@ -1,9 +1,6 @@
Copyright (C) 2023 dYdX Trading Inc. 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. 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 “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.
The GNU Affero General Public License The GNU Affero General Public License
+2 -7
View File
@@ -1,9 +1,4 @@
{ {
"apps": {
"iOS": {
"scheme": "dydxv4"
}
},
"deployments": { "deployments": {
"MAINNET": { "MAINNET": {
"environments": [ "environments": [
@@ -208,8 +203,8 @@
"endpoints": { "endpoints": {
"indexers": [ "indexers": [
{ {
"api": "https://indexer.v4dev4.dydx.exchange", "api": "http://indexer.v4dev4.dydx.exchange",
"socket": "wss://indexer.v4dev4.dydx.exchange" "socket": "ws://indexer.v4dev4.dydx.exchange"
} }
], ],
"validators": [ "validators": [
+54 -91
View File
@@ -48,7 +48,7 @@ export const useSubaccount = () => useContext(SubaccountContext);
export const useSubaccountContext = ({ localDydxWallet }: { localDydxWallet?: LocalWallet }) => { export const useSubaccountContext = ({ localDydxWallet }: { localDydxWallet?: LocalWallet }) => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const { usdcDenom, usdcDecimals } = useTokenConfigs(); const { usdcDenom } = useTokenConfigs();
const { compositeClient, faucetClient } = useDydxClient(); const { compositeClient, faucetClient } = useDydxClient();
const { getFaucetFunds } = useMemo( const { getFaucetFunds } = useMemo(
@@ -79,34 +79,16 @@ export const useSubaccountContext = ({ localDydxWallet }: { localDydxWallet?: Lo
subaccountClient: SubaccountClient; subaccountClient: SubaccountClient;
assetId?: number; assetId?: number;
amount: number; amount: number;
}) => { }) => await compositeClient?.depositToSubaccount(subaccountClient, amount.toString()),
try {
return await compositeClient?.depositToSubaccount(
subaccountClient,
amount.toFixed(usdcDecimals)
);
} catch (error) {
log('useSubaccount/depositToSubaccount', error);
throw error;
}
},
withdrawFromSubaccount: async ({ withdrawFromSubaccount: async ({
subaccountClient, subaccountClient,
amount, amount,
}: { }: {
subaccountClient: SubaccountClient; subaccountClient: SubaccountClient;
amount: number; amount: number;
}) => { }) => await compositeClient?.withdrawFromSubaccount(subaccountClient, amount.toString()),
try {
return await compositeClient?.withdrawFromSubaccount(
subaccountClient,
amount.toFixed(usdcDecimals)
);
} catch (error) {
log('useSubaccount/withdrawFromSubaccount', error);
throw error;
}
},
transferFromSubaccountToAddress: async ({ transferFromSubaccountToAddress: async ({
subaccountClient, subaccountClient,
assetId = 0, assetId = 0,
@@ -117,33 +99,27 @@ export const useSubaccountContext = ({ localDydxWallet }: { localDydxWallet?: Lo
assetId?: number; assetId?: number;
amount: number; amount: number;
recipient: string; recipient: string;
}) => { }) =>
try { await compositeClient?.validatorClient.post.send(
return await compositeClient?.validatorClient.post.send( subaccountClient?.wallet,
subaccountClient?.wallet, () =>
() => new Promise((resolve) => {
new Promise((resolve) => { const msg =
const msg = compositeClient?.validatorClient.post.composer.composeMsgWithdrawFromSubaccount(
compositeClient?.validatorClient.post.composer.composeMsgWithdrawFromSubaccount( subaccountClient.address,
subaccountClient.address, subaccountClient.subaccountNumber,
subaccountClient.subaccountNumber, assetId,
assetId, Long.fromNumber(amount * QUANTUM_MULTIPLIER),
Long.fromNumber(amount * QUANTUM_MULTIPLIER), recipient
recipient );
);
resolve([msg]); resolve([msg]);
}), }),
false, false,
undefined, undefined,
undefined, undefined,
Method.BroadcastTxCommit Method.BroadcastTxCommit
); ),
} catch (error) {
log('useSubaccount/transferFromSubaccountToAddress', error);
throw error;
}
},
transferNativeToken: async ({ transferNativeToken: async ({
subaccountClient, subaccountClient,
@@ -153,30 +129,24 @@ export const useSubaccountContext = ({ localDydxWallet }: { localDydxWallet?: Lo
subaccountClient: SubaccountClient; subaccountClient: SubaccountClient;
amount: number; amount: number;
recipient: string; recipient: string;
}) => { }) =>
try { await compositeClient?.validatorClient.post.send(
return await compositeClient?.validatorClient.post.send( subaccountClient.wallet,
subaccountClient.wallet, () =>
() => new Promise((resolve) => {
new Promise((resolve) => { const msg = compositeClient?.sendTokenMessage(
const msg = compositeClient?.sendTokenMessage( subaccountClient.wallet,
subaccountClient.wallet, amount.toString(),
amount.toString(), recipient,
recipient );
);
resolve([msg]); resolve([msg]);
}), }),
false, false,
compositeClient?.validatorClient?.post.defaultDydxGasPrice, compositeClient?.validatorClient?.post.defaultDydxGasPrice,
undefined, undefined,
Method.BroadcastTxCommit Method.BroadcastTxCommit
); ),
} catch (error) {
log('useSubaccount/transferNativeToken', error);
throw error;
}
},
sendSquidWithdrawFromSubaccount: async ({ sendSquidWithdrawFromSubaccount: async ({
subaccountClient, subaccountClient,
@@ -188,27 +158,20 @@ export const useSubaccountContext = ({ localDydxWallet }: { localDydxWallet?: Lo
payload: string; payload: string;
}) => { }) => {
if (!compositeClient) throw new Error('client not initialized'); if (!compositeClient) throw new Error('client not initialized');
try {
const transaction = JSON.parse(payload);
const msg = compositeClient.withdrawFromSubaccountMessage( const transaction = JSON.parse(payload);
subaccountClient,
amount.toFixed(usdcDecimals)
);
const ibcMsg: EncodeObject = {
typeUrl: transaction.msgTypeUrl,
value: transaction.msg,
};
return await compositeClient.send( const msg = compositeClient.withdrawFromSubaccountMessage(subaccountClient, amount.toString());
subaccountClient.wallet, const ibcMsg: EncodeObject = {
() => Promise.resolve([msg, ibcMsg]), typeUrl: transaction.msgTypeUrl,
false value: transaction.msg,
); };
} catch (error) {
log('useSubaccount/sendSquidWithdrawFromSubaccount', error); return await compositeClient.send(
throw error; subaccountClient.wallet,
} () => Promise.resolve([msg, ibcMsg]),
false
);
}, },
}), }),
[compositeClient] [compositeClient]
-4
View File
@@ -19,10 +19,8 @@ export const useTokenConfigs = (): {
}, },
}; };
usdcDenom: string; usdcDenom: string;
usdcDecimals: number;
usdcLabel: string; usdcLabel: string;
chainTokenDenom: string; chainTokenDenom: string;
chainTokenDecimals: number;
chainTokenLabel: string; chainTokenLabel: string;
} => { } => {
const { selectedNetwork } = useSelectedNetwork(); const { selectedNetwork } = useSelectedNetwork();
@@ -31,10 +29,8 @@ export const useTokenConfigs = (): {
return { return {
tokensConfigs, tokensConfigs,
usdcDenom: tokensConfigs[DydxChainAsset.USDC].denom, usdcDenom: tokensConfigs[DydxChainAsset.USDC].denom,
usdcDecimals: tokensConfigs[DydxChainAsset.USDC].decimals,
usdcLabel: tokensConfigs[DydxChainAsset.USDC].name, usdcLabel: tokensConfigs[DydxChainAsset.USDC].name,
chainTokenDenom: tokensConfigs[DydxChainAsset.CHAINTOKEN].denom, chainTokenDenom: tokensConfigs[DydxChainAsset.CHAINTOKEN].denom,
chainTokenDecimals: tokensConfigs[DydxChainAsset.CHAINTOKEN].decimals,
chainTokenLabel: tokensConfigs[DydxChainAsset.CHAINTOKEN].name, chainTokenLabel: tokensConfigs[DydxChainAsset.CHAINTOKEN].name,
}; };
}; };
@@ -131,7 +131,7 @@ export const AccountDetailsAndHistory = () => {
key: 'BuyingPower', key: 'BuyingPower',
labelKey: STRING_KEYS.BUYING_POWER, labelKey: STRING_KEYS.BUYING_POWER,
type: OutputType.Fiat, type: OutputType.Fiat,
value: MustBigNumber(buyingPower?.current).lt(0) ? undefined : buyingPower?.current, // show '-' when buying power is negative value: buyingPower?.current,
}, },
].filter(isTruthy); ].filter(isTruthy);
@@ -151,10 +151,7 @@ export const AccountInfoConnectedState = () => {
), ),
label: stringGetter({ key: STRING_KEYS.BUYING_POWER }), label: stringGetter({ key: STRING_KEYS.BUYING_POWER }),
type: OutputType.Fiat, type: OutputType.Fiat,
value: value: buyingPower,
MustBigNumber(buyingPower?.current).lt(0) && buyingPower?.postOrder === null
? undefined
: buyingPower,
}, },
].map( ].map(
({ ({
@@ -1,5 +1,5 @@
import { type Dispatch, type SetStateAction, useState, type ReactNode } from 'react'; 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 { shallowEqual, useSelector } from 'react-redux';
import type { RouteData } from '@0xsquid/sdk'; import type { RouteData } from '@0xsquid/sdk';
@@ -32,8 +32,6 @@ import { WithReceipt } from '@/components/WithReceipt';
import { getSubaccountBuyingPower, getSubaccountEquity } from '@/state/accountSelectors'; import { getSubaccountBuyingPower, getSubaccountEquity } from '@/state/accountSelectors';
import { getTransferInputs } from '@/state/inputsSelectors'; import { getTransferInputs } from '@/state/inputsSelectors';
import { MustBigNumber } from '@/lib/numbers';
import { SlippageEditor } from '../SlippageEditor'; import { SlippageEditor } from '../SlippageEditor';
type ElementProps = { type ElementProps = {
@@ -133,7 +131,7 @@ export const DepositButtonAndReceipt = ({
value: ( value: (
<DiffOutput <DiffOutput
type={OutputType.Fiat} type={OutputType.Fiat}
value={MustBigNumber(buyingPower).lt(0) ? undefined : buyingPower} value={buyingPower}
newValue={newBuyingPower} newValue={newBuyingPower}
sign={NumberSign.Positive} sign={NumberSign.Positive}
withDiff={Boolean(newBuyingPower) && buyingPower !== newBuyingPower} withDiff={Boolean(newBuyingPower) && buyingPower !== newBuyingPower}
+8 -23
View File
@@ -36,7 +36,6 @@ import { truncateAddress } from '@/lib/wallet';
import { layoutMixins } from '@/styles/layoutMixins'; import { layoutMixins } from '@/styles/layoutMixins';
import { headerMixins } from '@/styles/headerMixins'; import { headerMixins } from '@/styles/headerMixins';
import { MustBigNumber } from '@/lib/numbers';
export const AccountMenu = () => { export const AccountMenu = () => {
const stringGetter = useStringGetter(); const stringGetter = useStringGetter();
@@ -50,8 +49,6 @@ export const AccountMenu = () => {
const { evmAddress, walletType, dydxAddress, hdKey } = useAccounts(); const { evmAddress, walletType, dydxAddress, hdKey } = useAccounts();
const usdcBalance = freeCollateral?.current || 0;
const onRecoverKeys = () => { const onRecoverKeys = () => {
dispatch(openDialog({ type: DialogTypes.Onboarding })); dispatch(openDialog({ type: DialogTypes.Onboarding }));
}; };
@@ -125,11 +122,7 @@ export const AccountMenu = () => {
</Styled.label> </Styled.label>
<Styled.BalanceOutput type={OutputType.Asset} value={nativeTokenBalance} /> <Styled.BalanceOutput type={OutputType.Asset} value={nativeTokenBalance} />
</div> </div>
<AssetActions <AssetActions asset={DydxChainAsset.CHAINTOKEN} dispatch={dispatch} />
asset={DydxChainAsset.CHAINTOKEN}
dispatch={dispatch}
hasBalance={nativeTokenBalance.gt(0)}
/>
</div> </div>
<div> <div>
<div> <div>
@@ -142,16 +135,11 @@ export const AccountMenu = () => {
</Styled.label> </Styled.label>
<Styled.BalanceOutput <Styled.BalanceOutput
type={OutputType.Asset} type={OutputType.Asset}
value={usdcBalance} value={freeCollateral?.current || 0}
fractionDigits={2} fractionDigits={2}
/> />
</div> </div>
<AssetActions <AssetActions asset={DydxChainAsset.USDC} dispatch={dispatch} withOnboarding />
asset={DydxChainAsset.USDC}
dispatch={dispatch}
hasBalance={MustBigNumber(usdcBalance).gt(0)}
withOnboarding
/>
</div> </div>
</Styled.Balances> </Styled.Balances>
</Styled.AccountInfo> </Styled.AccountInfo>
@@ -229,25 +217,22 @@ const AssetActions = memo(
asset, asset,
dispatch, dispatch,
withOnboarding, withOnboarding,
hasBalance,
}: { }: {
asset: DydxChainAsset; asset: DydxChainAsset;
dispatch: Dispatch; dispatch: Dispatch;
withOnboarding?: boolean; withOnboarding?: boolean;
hasBalance?: boolean;
}) => ( }) => (
<Styled.InlineRow> <Styled.InlineRow>
{[ {[
withOnboarding && withOnboarding && {
hasBalance && { dialogType: DialogTypes.Withdraw,
dialogType: DialogTypes.Withdraw, iconName: IconName.Withdraw,
iconName: IconName.Withdraw, },
},
withOnboarding && { withOnboarding && {
dialogType: DialogTypes.Deposit, dialogType: DialogTypes.Deposit,
iconName: IconName.Deposit, iconName: IconName.Deposit,
}, },
hasBalance && { {
dialogType: DialogTypes.Transfer, dialogType: DialogTypes.Transfer,
dialogProps: { selectedAsset: asset }, dialogProps: { selectedAsset: asset },
iconName: IconName.Send, iconName: IconName.Send,