Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: noUncheckedIndexedAccess #1180

Merged
merged 8 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"@cosmjs/tendermint-rpc": "^0.32.1",
"@datadog/browser-logs": "^5.23.3",
"@dydxprotocol/v4-abacus": "1.13.2",
"@dydxprotocol/v4-client-js": "1.11.1",
"@dydxprotocol/v4-client-js": "1.12.1",
"@dydxprotocol/v4-localization": "^1.1.222",
"@dydxprotocol/v4-proto": "^7.0.0-dev.0",
"@emotion/is-prop-valid": "^1.3.0",
Expand Down
9 changes: 5 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 11 additions & 10 deletions scripts/markets/add-markets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ import {
IndexerConfig,
LocalWallet as LocalWalletType,
Network,
ValidatorConfig
ValidatorConfig,
} from '@dydxprotocol/v4-client-js';
import { readFileSync } from 'fs';
import Long from 'long';

import {
createAndSendMarketMapProposal,
PerpetualMarketType,
Proposal,
createAndSendMarketMapProposal,
retry,
sleep,
voteOnProposals
voteOnProposals,
} from './help';

const LocalWalletModule = await import(
Expand Down Expand Up @@ -177,15 +178,15 @@ async function addMarkets(
);

// Add markets to market map first.
console.log("Submitting market map proposal...");
console.log('Submitting market map proposal...');
await createAndSendMarketMapProposal(
filteredProposals.slice(0, numMarkets),
config.validatorEndpoint,
config.chainId,
binary,
binary
);
await sleep(sleepMsBtwTxs);
console.log("Submitted market map proposal");
console.log('Submitted market map proposal');

// Get latest gov proposal ID.
const allProposalsResp = await client.validatorClient.get.getAllGovProposals();
Expand Down Expand Up @@ -215,16 +216,16 @@ async function addMarkets(
if (numProposalsSent >= numProposalsToSend) {
break;
}
const proposal = proposalsToSend[j];
const proposal = proposalsToSend[j]!;
const marketId: number = numExistingMarkets + numProposalsSent + 1;

// Send proposal.
const exchangeConfigString = `{"exchanges":${JSON.stringify(
proposal.params.exchangeConfigJson
proposal!.params.exchangeConfigJson
)}}`;
await retry(() =>
client.submitGovAddNewMarketProposal(
wallets[j],
wallets[j]!,
{
id: marketId,
ticker: proposal.params.ticker,
Expand Down Expand Up @@ -272,7 +273,7 @@ async function main(): Promise<void> {
// Get which env and how many markets to add.
const args = process.argv.slice(2);
const env = args[0] as Env;
const numMarkets = parseInt(args[1], 10);
const numMarkets = args[1] != null ? parseInt(args[1], 10) : 0;
const binary = args[2];

// Validate inputs.
Expand Down
59 changes: 31 additions & 28 deletions scripts/markets/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { spawn } from 'child_process';
import * as fs from 'fs';
import Long from 'long';


const VOTE_FEE: StdFee = {
amount: [
{
Expand Down Expand Up @@ -192,7 +191,7 @@ export async function createAndSendMarketMapProposal(
proposals: Proposal[],
validatorEndpoint: string,
chainId: string,
binary: string,
binary: string
) {
const markets: Market[] = proposals.map((proposal) => {
const { ticker, priceExponent, minExchanges, exchangeConfigJson } = proposal.params;
Expand All @@ -205,23 +204,23 @@ export async function createAndSendMarketMapProposal(

if (config.adjustByMarket) {
const [Base, Quote] = config.adjustByMarket.split('-');
normalize_by_pair = { Base, Quote };
normalize_by_pair = { Base: Base!, Quote: Quote! };
tyleroooo marked this conversation as resolved.
Show resolved Hide resolved
}

return {
name: config.exchangeName,
normalize_by_pair,
off_chain_ticker: config.ticker,
invert: config.invert || false,
invert: !!config.invert,
metadata_JSON: config.metadata_JSON ?? '',
};
});

return {
ticker: {
currency_pair: {
Base: modifiedTicker.split('/')[0],
Quote: modifiedTicker.split('/')[1],
Base: modifiedTicker.split('/')[0]!,
Quote: modifiedTicker.split('/')[1]!,
},
decimals: Math.abs(priceExponent).toString(),
enabled: false,
Expand All @@ -233,17 +232,17 @@ export async function createAndSendMarketMapProposal(
});

const proposal = {
"title": "Add markets to market map",
"summary":"Add markets to market map",
"messages": [
title: 'Add markets to market map',
summary: 'Add markets to market map',
messages: [
{
"@type": "/slinky.marketmap.v1.MsgUpsertMarkets",
"authority": "dydx10d07y265gmmuvt4z0w9aw880jnsr700jnmapky",
"markets": markets,
'@type': '/slinky.marketmap.v1.MsgUpsertMarkets',
authority: 'dydx10d07y265gmmuvt4z0w9aw880jnsr700jnmapky',
markets: markets,
},
],
"deposit":"5000000000000000000adv4tnt",
"expedited": true,
deposit: '5000000000000000000adv4tnt',
expedited: true,
};

const proposalFile = 'marketMapProposal.json';
Expand All @@ -256,30 +255,34 @@ export async function createAndSendMarketMapProposal(
binary,
['keys', 'add', 'alice', '--recover'],
'merge panther lobster crazy road hollow amused security before critic about cliff exhibit cause coyote talent happy where lion river tobacco option coconut small'
)
);
}

await execCLI(
binary,
[
'--node', validatorEndpoint,
'tx', 'gov', 'submit-proposal', 'marketMapProposal.json',
'--from', 'alice',
'--fees', '2000000000000000000adv4tnt',
'--chain-id', chainId,
'--gas', 'auto'
'--node',
validatorEndpoint,
'tx',
'gov',
'submit-proposal',
'marketMapProposal.json',
'--from',
'alice',
'--fees',
'2000000000000000000adv4tnt',
'--chain-id',
chainId,
'--gas',
'auto',
],
'y',
)
'y'
);

fs.unlinkSync(proposalFile);
}

export function execCLI(
command: string,
args?: string[],
input?: string,
): Promise<string> {
export function execCLI(command: string, args?: string[], input?: string): Promise<string> {
return new Promise((resolve, reject) => {
const process = spawn(command, args);

Expand Down
10 changes: 5 additions & 5 deletions scripts/markets/validate-other-market-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ async function validateAgainstLocalnet(proposals: Proposal[]): Promise<void> {
network.validatorConfig.chainId,
'v4-chain/protocol/build/dydxprotocold'
);
console.log("Submitted market map proposal");
console.log('Submitted market map proposal');
await sleep(5000);
for (const wallet of wallets) {
retry(() => voteOnProposals([1], client, wallet));
Expand All @@ -352,7 +352,7 @@ async function validateAgainstLocalnet(proposals: Proposal[]): Promise<void> {
const proposalIds: number[] = [];
for (let j = 0; j < proposalsToSend.length; j++) {
// Use wallets[j] to send out proposalsToSend[j]
const proposal = proposalsToSend[j];
const proposal = proposalsToSend[j]!;
const marketId: number = numExistingMarkets + proposalId;

// Send proposal.
Expand All @@ -361,7 +361,7 @@ async function validateAgainstLocalnet(proposals: Proposal[]): Promise<void> {
)}}`;
const tx = await retry(() =>
client.submitGovAddNewMarketProposal(
wallets[j],
wallets[j]!,
// @ts-ignore: marketType is not a valid parameter for addNewMarketProposal
{
id: marketId,
Expand Down Expand Up @@ -734,7 +734,7 @@ function getProposalsToValidate(newProposals: Record<string, Proposal>): Set<str
continue;
}

const oldParams = removeIdFromParams(oldProposals[name].params);
const oldParams = removeIdFromParams(oldProposals[name]!.params);
const newParams = removeIdFromParams(newProposal.params);
if (JSON.stringify(oldParams) !== JSON.stringify(newParams)) {
marketsToValidate.add(name);
Expand Down Expand Up @@ -780,7 +780,7 @@ async function main(): Promise<void> {
if (proposalsToValidate.size === 0) {
return;
}
await validateAgainstLocalnet(Array.from(proposalsToValidate).map((name) => newProposals[name]));
await validateAgainstLocalnet(Array.from(proposalsToValidate).map((name) => newProposals[name]!));

console.log(`\nValidated ${proposalsToValidate.size} proposals. See log for specific names.`);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/DropdownSelectMenu.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const exampleItems = [
export const DropdownSelectMenuStory: Story<
Pick<Parameters<typeof DropdownSelectMenu>[0], 'items' | 'align' | 'sideOffset' | 'disabled'>
> = (args) => {
const [item, setItem] = useState(exampleItems[0].value);
const [item, setItem] = useState(exampleItems[0]!.value);
return (
<StoryWrapper>
<DropdownSelectMenu value={item} onValueChange={(value) => setItem(value)} {...args} />
Expand Down
2 changes: 1 addition & 1 deletion src/components/RadioButtonCards.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const RadioButtonCardsStory: Story<RadioButtonCardStoryProps> = ({
withSlotTop,
withSlotBottom,
}: RadioButtonCardStoryProps) => {
const [item, setItem] = useState(exampleItems[0].value);
const [item, setItem] = useState(exampleItems[0]!.value);
return (
<StoryWrapper>
<StyledRadioButtonCards
Expand Down
2 changes: 1 addition & 1 deletion src/components/RadioGroup.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const exampleItems = [
];

export const RadioGroupStory: Story<Pick<Parameters<typeof RadioGroup>[0], 'items'>> = (args) => {
const [item, setItem] = useState(exampleItems[0].value);
const [item, setItem] = useState(exampleItems[0]!.value);
return (
<StoryWrapper>
<RadioGroup value={item} onValueChange={(value) => setItem(value)} {...args} />
Expand Down
4 changes: 2 additions & 2 deletions src/components/SelectMenu.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const exampleItems: { value: string; label: string }[] = [
];

export const SelectMenuStory: Story<Parameters<typeof SelectMenu>[0]> = () => {
const [value, setValue] = useState(exampleItems[0].value);
const [value2, setValue2] = useState(exampleItems[2].value);
const [value, setValue] = useState(exampleItems[0]!.value);
const [value2, setValue2] = useState(exampleItems[2]!.value);

return (
<StoryWrapper>
Expand Down
7 changes: 6 additions & 1 deletion src/components/WalletIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ export const WalletIcon = ({ wallet, size = '1em' }: { wallet: WalletInfo; size?
return <$Image src={wallet.icon} alt={wallet.name} size={size} />;
}

return <Icon iconComponent={wallets[wallet.name].icon as ElementType} size={size} />;
return (
<Icon
iconComponent={wallets[wallet.name as keyof typeof wallets].icon as ElementType}
size={size}
/>
);
};

const $Image = styled.img<{ size: string }>`
Expand Down
25 changes: 17 additions & 8 deletions src/components/visx/TimeSeriesChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,19 @@ export const TimeSeriesChart = <Datum extends {}>({
const chartRef = useRef<HTMLDivElement>(null);

// Chart data
const { xAccessor, yAccessor } = series[0];
const { xAccessor, yAccessor } = series[0]!;

const earliestDatum = data?.[0];
const latestDatum = data?.[data.length - 1];
const atLeastOnePoint = data.length > 0;
const earliestDatum = data[0];
const latestDatum = data[data.length - 1];

// Chart state
const getClampedZoomDomain = useCallback(
(unclamped: number) => {
return clamp(
Math.max(1e-320, Math.min(Number.MAX_SAFE_INTEGER, unclamped)),
minZoomDomain,
xAccessor(latestDatum) - xAccessor(earliestDatum)
atLeastOnePoint ? xAccessor(latestDatum!) - xAccessor(earliestDatum!) : 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need to be added to dep array?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's missing a bunch of stuff downstream of data but depends on data so it should be fine I think.

);
},
[earliestDatum, latestDatum, minZoomDomain, xAccessor]
Expand Down Expand Up @@ -211,10 +212,18 @@ export const TimeSeriesChart = <Datum extends {}>({

const zoom = zoomDomain / minZoomDomain;

const domainBase = [
clamp(xAccessor(latestDatum) - zoomDomain, xAccessor(earliestDatum), xAccessor(latestDatum)),
xAccessor(latestDatum),
] as [number, number];
const domainBase = (
atLeastOnePoint
? [
clamp(
xAccessor(latestDatum!) - zoomDomain,
xAccessor(earliestDatum!),
xAccessor(latestDatum!)
),
xAccessor(latestDatum!),
]
: [0, 0]
) as [number, number];
const domain = [
domainBase[0] - (domainBase[1] - domainBase[0]) * domainBasePadding[0],
domainBase[1] + (domainBase[1] - domainBase[0]) * domainBasePadding[1],
Expand Down
4 changes: 2 additions & 2 deletions src/constants/__test__/cctp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,12 @@ describe('isTokenCctp', () => {
recommendedSymbol: 'test-recommendedSymbol',
});
it('returns true for cctp token', () => {
const denom = cctpTokens[0].tokenAddress;
const denom = cctpTokens[0]!.tokenAddress;
const asset = getTestAssetWithDenom(denom);
expect(isTokenCctp(asset)).toBe(true);
});
it('returns true for cctp token case insensitive', () => {
const denom = cctpTokens[0].tokenAddress.toLowerCase();
const denom = cctpTokens[0]!.tokenAddress.toLowerCase();
const asset = getTestAssetWithDenom(denom);
expect(isTokenCctp(asset)).toBe(true);
});
Expand Down
Loading
Loading