From 628041e53739ab283a686d4c45592c8f57fe6c4b Mon Sep 17 00:00:00 2001 From: jaredvu Date: Mon, 28 Aug 2023 08:13:29 -0700 Subject: [PATCH] add abacusFileSystem protocol --- package.json | 2 +- pnpm-lock.yaml | 20 +++++++++++--------- src/constants/abacus.ts | 9 +++++++++ src/constants/networks.tsx | 2 +- src/lib/abacus/filesystem.ts | 19 +++++++++++++++++++ src/lib/abacus/index.ts | 5 ++++- src/lib/abacus/stateNotification.ts | 11 +++++++++++ 7 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 src/lib/abacus/filesystem.ts diff --git a/package.json b/package.json index 88420c0..02f58af 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "@cosmjs/encoding": "^0.31.0", "@cosmjs/proto-signing": "^0.31.0", "@cosmjs/stargate": "^0.31.0", - "@dydxprotocol/abacus": "^0.2.28", + "@dydxprotocol/abacus": "^0.3.7", "@cosmjs/tendermint-rpc": "^0.31.0", "@dydxprotocol/v4-client": "^0.29.0", "@ethersproject/providers": "^5.7.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 83de3b2..07732cd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -27,8 +27,8 @@ dependencies: specifier: ^0.31.0 version: 0.31.0 '@dydxprotocol/abacus': - specifier: ^0.2.28 - version: 0.2.28 + specifier: file:/Users/jaredvu/Documents/v4-abacus/build/packages/dydxprotocol-abacus-0.3.7.tgz + version: file:../v4-abacus/build/packages/dydxprotocol-abacus-0.3.7.tgz '@dydxprotocol/v4-client': specifier: ^0.29.0 version: 0.29.0 @@ -1143,10 +1143,6 @@ packages: resolution: {integrity: sha512-RpfLEtTlyIxeNPGKcokS+p3BZII/Q3bYxryFRglh5H3A3T8q9fsLYm72VYAMEOOIBLEa8o93kFLiBDUWKrwXZA==} dev: true - /@dydxprotocol/abacus@0.2.28: - resolution: {integrity: sha512-mGmhwQM8aiV/cD+d3lvW76ysoPN7uVsDyAiVcRdzGqgj+gbM0IIJDYXG14xHruOTi+gK1Aga5MUz2pdvmPDhYA==} - dev: false - /@dydxprotocol/dydxjs@0.3.0: resolution: {integrity: sha512-ygNeBs0f3H7sJk1qLUjfNwaXgc5TmjD+qZf7BFDbi7+boHJI9xuOWrGpjfBo7OTUZxS6O5jZG323CgU5XqMSPw==} dependencies: @@ -8277,7 +8273,7 @@ packages: resolution: {integrity: sha512-WIdaQ8uW1vIbYvNnAVunkC6yxTrneJC7VQ5UUQ0kuw8b0C0A39KTIpoQHCfc8tV7o9vF4niwRhdXEdfAgQEsQQ==} dependencies: cosmos-directory-types: 0.0.6 - node-fetch-native: 1.2.0 + node-fetch-native: 1.4.0 dev: false /cosmos-directory-types@0.0.6: @@ -12462,8 +12458,8 @@ packages: resolution: {integrity: sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==} engines: {node: '>=10.5.0'} - /node-fetch-native@1.2.0: - resolution: {integrity: sha512-5IAMBTl9p6PaAjYCnMv5FmqIF6GcZnawAVnzaCG0rX2aYZJ4CxEkZNtVPuTRug7fL7wyM5BQYTlAzcyMPi6oTQ==} + /node-fetch-native@1.4.0: + resolution: {integrity: sha512-F5kfEj95kX8tkDhUCYdV8dg3/8Olx/94zB8+ZNthFs6Bz31UpUi8Xh40TN3thLwXgrwXry1pEg9lJ++tLWTcqA==} dev: false /node-fetch@2.6.12: @@ -15840,6 +15836,12 @@ packages: resolution: {integrity: sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==} dev: true + file:../v4-abacus/build/packages/dydxprotocol-abacus-0.3.7.tgz: + resolution: {integrity: sha512-omUiVHcT/tHWeXKgZTk1WW8LDVHI+2yxXNM6+B756liRY/t1JwUkRzwplp09U2+mNo/FenejHFtWZ0qd+W79iw==, tarball: file:../v4-abacus/build/packages/dydxprotocol-abacus-0.3.7.tgz} + name: '@dydxprotocol/abacus' + version: 0.3.7 + dev: false + github.com/release-it/conventional-changelog/a4acfeac76369937a6566d698a5ae9180eceb413(release-it@15.11.0): resolution: {tarball: https://codeload.github.com/release-it/conventional-changelog/tar.gz/a4acfeac76369937a6566d698a5ae9180eceb413} id: github.com/release-it/conventional-changelog/a4acfeac76369937a6566d698a5ae9180eceb413 diff --git a/src/constants/abacus.ts b/src/constants/abacus.ts index 80d9747..39134af 100644 --- a/src/constants/abacus.ts +++ b/src/constants/abacus.ts @@ -36,6 +36,12 @@ export type AbacusThreadingProtocol = Omit< Abacus.exchange.dydx.abacus.protocols.ThreadingProtocol, '__doNotUseOrImplementIt' >; +export type AbacusFileSystemProtocol = Omit< + Abacus.exchange.dydx.abacus.protocols.FileSystemProtocol, + '__doNotUseOrImplementIt' +>; + +export type FileLocation = Abacus.exchange.dydx.abacus.protocols.FileLocation; export type ThreadingType = Abacus.exchange.dydx.abacus.protocols.ThreadingType; export const CoroutineTimer = Abacus.exchange.dydx.abacus.utils.CoroutineTimer; @@ -175,6 +181,9 @@ export const RiskLevel = Abacus.exchange.dydx.abacus.utils.RiskLevel; const riskLevels = [...RiskLevel.values()] as const; export type RiskLevels = (typeof riskLevels)[number]; +// ------ Notifications ------ // +export type AbacusNotification = Abacus.exchange.dydx.abacus.output.Notification; + // ------ Enum Conversions ------ // type IfEquals = (() => T extends X ? 1 : 2) extends () => T extends Y ? 1 : 2 ? A diff --git a/src/constants/networks.tsx b/src/constants/networks.tsx index f0a079f..87cae59 100644 --- a/src/constants/networks.tsx +++ b/src/constants/networks.tsx @@ -1,7 +1,7 @@ export enum DydxV4Network { V4Mainnet = 'dydxprotocol-mainnet', V4Staging = 'dydxprotocol-staging', - V4Testnet2 = 'dydxprotocol-testnet-2', + V4Testnet2 = 'dydxprotocol-testnet', V4Local = 'dydxprotocol-dev', } diff --git a/src/lib/abacus/filesystem.ts b/src/lib/abacus/filesystem.ts new file mode 100644 index 0000000..7c1e127 --- /dev/null +++ b/src/lib/abacus/filesystem.ts @@ -0,0 +1,19 @@ +import type { AbacusFileSystemProtocol, FileLocation, Nullable } from '@/constants/abacus'; + +class AbacusFileSystem implements AbacusFileSystemProtocol { + readTextFile(location: FileLocation, path: string): Nullable { + console.log({ location, path }); + if (path === 'config/staging/environments.json') { + console.log('ENVIRONMENT_CONFIGS', globalThis.ENVIRONMENT_CONFIGS); + return JSON.stringify(globalThis.ENVIRONMENT_CONFIGS); + } + + return null; + } + + writeTextFile(path: string, text: string): boolean { + return true; + } +} + +export default AbacusFileSystem; diff --git a/src/lib/abacus/index.ts b/src/lib/abacus/index.ts index 1d43a86..4b7a528 100644 --- a/src/lib/abacus/index.ts +++ b/src/lib/abacus/index.ts @@ -34,6 +34,7 @@ import AbacusStateNotifier from './stateNotification'; import AbacusLocalizer from './localizer'; import AbacusFormatter from './formatter'; import AbacusThreading from './threading'; +import AbacusFileSystem from './filesystem'; import { LocaleSeparators } from '../numbers'; class AbacusStateManager { @@ -60,7 +61,7 @@ class AbacusStateManager { null, new AbacusThreading(), new CoroutineTimer(), - null + new AbacusFileSystem() ); const uiImplementations = new UIImplementations( @@ -70,6 +71,8 @@ class AbacusStateManager { ); this.stateManager = new AsyncAbacusStateManager( + import.meta.env.SHARED_RESOURCES_URI, + 'config/staging/environments.json', ioImplementations, uiImplementations, // @ts-ignore diff --git a/src/lib/abacus/stateNotification.ts b/src/lib/abacus/stateNotification.ts index ef08749..51fd67b 100644 --- a/src/lib/abacus/stateNotification.ts +++ b/src/lib/abacus/stateNotification.ts @@ -1,5 +1,8 @@ +import { kollections } from '@dydxprotocol/abacus'; + import type { AbacusApiState, + AbacusNotification, AbacusStateNotificationProtocol, Asset, Nullable, @@ -35,6 +38,14 @@ class AbacusStateNotifier implements AbacusStateNotificationProtocol { this.store = undefined; } + environmentsChanged(): void { + console.log('environments changed'); + } + + notificationsChanged(notifications: kollections.List): void { + console.log(notifications.toArray()); + } + stateChanged( updatedState: Nullable, incomingChanges: Nullable