Compare commits

...
2 Commits
Author SHA1 Message Date
jaredvu 7b036d880b Handle EquityTier query 2023-08-22 15:39:13 -07:00
jaredvu 0406d05200 equity tier fetch 2023-08-22 13:35:35 -07:00
4 changed files with 65 additions and 33 deletions
+1 -1
View File
@@ -35,7 +35,7 @@
"@cosmjs/encoding": "^0.31.0", "@cosmjs/encoding": "^0.31.0",
"@cosmjs/proto-signing": "^0.31.0", "@cosmjs/proto-signing": "^0.31.0",
"@cosmjs/stargate": "^0.31.0", "@cosmjs/stargate": "^0.31.0",
"@dydxprotocol/abacus": "^0.2.28", "@dydxprotocol/abacus": "file:/Users/jaredvu/Documents/abacus/build/packages/dydxprotocol-abacus-0.2.28.tgz",
"@cosmjs/tendermint-rpc": "^0.31.0", "@cosmjs/tendermint-rpc": "^0.31.0",
"@dydxprotocol/v4-client": "^0.29.0", "@dydxprotocol/v4-client": "^0.29.0",
"@ethersproject/providers": "^5.7.2", "@ethersproject/providers": "^5.7.2",
+11 -9
View File
@@ -27,8 +27,8 @@ dependencies:
specifier: ^0.31.0 specifier: ^0.31.0
version: 0.31.0 version: 0.31.0
'@dydxprotocol/abacus': '@dydxprotocol/abacus':
specifier: ^0.2.28 specifier: file:/Users/jaredvu/Documents/abacus/build/packages/dydxprotocol-abacus-0.2.28.tgz
version: 0.2.28 version: file:../abacus/build/packages/dydxprotocol-abacus-0.2.28.tgz
'@dydxprotocol/v4-client': '@dydxprotocol/v4-client':
specifier: ^0.29.0 specifier: ^0.29.0
version: 0.29.0 version: 0.29.0
@@ -1143,10 +1143,6 @@ packages:
resolution: {integrity: sha512-RpfLEtTlyIxeNPGKcokS+p3BZII/Q3bYxryFRglh5H3A3T8q9fsLYm72VYAMEOOIBLEa8o93kFLiBDUWKrwXZA==} resolution: {integrity: sha512-RpfLEtTlyIxeNPGKcokS+p3BZII/Q3bYxryFRglh5H3A3T8q9fsLYm72VYAMEOOIBLEa8o93kFLiBDUWKrwXZA==}
dev: true dev: true
/@dydxprotocol/abacus@0.2.28:
resolution: {integrity: sha512-mGmhwQM8aiV/cD+d3lvW76ysoPN7uVsDyAiVcRdzGqgj+gbM0IIJDYXG14xHruOTi+gK1Aga5MUz2pdvmPDhYA==}
dev: false
/@dydxprotocol/dydxjs@0.3.0: /@dydxprotocol/dydxjs@0.3.0:
resolution: {integrity: sha512-ygNeBs0f3H7sJk1qLUjfNwaXgc5TmjD+qZf7BFDbi7+boHJI9xuOWrGpjfBo7OTUZxS6O5jZG323CgU5XqMSPw==} resolution: {integrity: sha512-ygNeBs0f3H7sJk1qLUjfNwaXgc5TmjD+qZf7BFDbi7+boHJI9xuOWrGpjfBo7OTUZxS6O5jZG323CgU5XqMSPw==}
dependencies: dependencies:
@@ -8277,7 +8273,7 @@ packages:
resolution: {integrity: sha512-WIdaQ8uW1vIbYvNnAVunkC6yxTrneJC7VQ5UUQ0kuw8b0C0A39KTIpoQHCfc8tV7o9vF4niwRhdXEdfAgQEsQQ==} resolution: {integrity: sha512-WIdaQ8uW1vIbYvNnAVunkC6yxTrneJC7VQ5UUQ0kuw8b0C0A39KTIpoQHCfc8tV7o9vF4niwRhdXEdfAgQEsQQ==}
dependencies: dependencies:
cosmos-directory-types: 0.0.6 cosmos-directory-types: 0.0.6
node-fetch-native: 1.2.0 node-fetch-native: 1.3.3
dev: false dev: false
/cosmos-directory-types@0.0.6: /cosmos-directory-types@0.0.6:
@@ -12462,8 +12458,8 @@ packages:
resolution: {integrity: sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==} resolution: {integrity: sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==}
engines: {node: '>=10.5.0'} engines: {node: '>=10.5.0'}
/node-fetch-native@1.2.0: /node-fetch-native@1.3.3:
resolution: {integrity: sha512-5IAMBTl9p6PaAjYCnMv5FmqIF6GcZnawAVnzaCG0rX2aYZJ4CxEkZNtVPuTRug7fL7wyM5BQYTlAzcyMPi6oTQ==} resolution: {integrity: sha512-dw7R7GkbPkgC2jfEtJjvF2t3eJ/2+Pj1crKjbowhgnkMsuehYx6LUvfDG4FmWX20KYddJCZbQG8kZE9LNrf5GQ==}
dev: false dev: false
/node-fetch@2.6.12: /node-fetch@2.6.12:
@@ -15840,6 +15836,12 @@ packages:
resolution: {integrity: sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==} resolution: {integrity: sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==}
dev: true dev: true
file:../abacus/build/packages/dydxprotocol-abacus-0.2.28.tgz:
resolution: {integrity: sha512-tBZRaSBATUsI+Z5x9/iwg0I2hEINTI2UGlIw5oGNFm1MRgZqjHAr3mRzsmYg6jaCqjOgXWIGGAY9QjrwQU99qw==, tarball: file:../abacus/build/packages/dydxprotocol-abacus-0.2.28.tgz}
name: '@dydxprotocol/abacus'
version: 0.2.28
dev: false
github.com/release-it/conventional-changelog/a4acfeac76369937a6566d698a5ae9180eceb413(release-it@15.11.0): 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} resolution: {tarball: https://codeload.github.com/release-it/conventional-changelog/tar.gz/a4acfeac76369937a6566d698a5ae9180eceb413}
id: github.com/release-it/conventional-changelog/a4acfeac76369937a6566d698a5ae9180eceb413 id: github.com/release-it/conventional-changelog/a4acfeac76369937a6566d698a5ae9180eceb413
+39 -23
View File
@@ -17,6 +17,7 @@ import {
} from '@/constants/abacus'; } from '@/constants/abacus';
import { log } from '../telemetry'; import { log } from '../telemetry';
import { bytesToBigInt } from '../numbers';
class DydxChainQueries implements AbacusDydxChainQueriesProtocol { class DydxChainQueries implements AbacusDydxChainQueriesProtocol {
private compositeClient: CompositeClient | undefined; private compositeClient: CompositeClient | undefined;
@@ -33,30 +34,34 @@ class DydxChainQueries implements AbacusDydxChainQueriesProtocol {
faucetUrl: Nullable<string> | undefined, faucetUrl: Nullable<string> | undefined,
callback: (p0: Nullable<string>) => void callback: (p0: Nullable<string>) => void
): Promise<void> { ): Promise<void> {
this.compositeClient = await CompositeClient.connect( try {
new Network( this.compositeClient = await CompositeClient.connect(
chainId, new Network(
new IndexerConfig(indexerUrl, indexerSocketUrl), chainId,
new ValidatorConfig(validatorUrl, chainId, { new IndexerConfig(indexerUrl, indexerSocketUrl),
broadcastPollIntervalMs: 3_000, new ValidatorConfig(validatorUrl, chainId, {
broadcastTimeoutMs: 60_000, broadcastPollIntervalMs: 3_000,
}) broadcastTimeoutMs: 60_000,
) })
); )
);
} catch (error) {
log('AbacusDydxChainQueries/connectNetwork', error);
} finally {
// Dispatch custom event to notify other parts of the app that the network has been connected
const customEvent = new CustomEvent('abacus:connectNetwork', {
detail: {
indexerUrl,
indexerSocketUrl,
validatorUrl,
chainId,
faucetUrl,
},
});
// Dispatch custom event to notify other parts of the app that the network has been connected globalThis.dispatchEvent(customEvent);
const customEvent = new CustomEvent('abacus:connectNetwork', { callback(JSON.stringify({ success: true }));
detail: { }
indexerUrl,
indexerSocketUrl,
validatorUrl,
chainId,
faucetUrl,
},
});
globalThis.dispatchEvent(customEvent);
callback(JSON.stringify({ success: true }));
} }
parseToPrimitives<T>(x: T): T { parseToPrimitives<T>(x: T): T {
@@ -68,6 +73,10 @@ class DydxChainQueries implements AbacusDydxChainQueriesProtocol {
return x.map((item) => this.parseToPrimitives(item)) as T; return x.map((item) => this.parseToPrimitives(item)) as T;
} }
if (x instanceof Uint8Array) {
return bytesToBigInt(x).toString() as T;
}
if (Long.isLong(x)) { if (Long.isLong(x)) {
return x.toString() as T; return x.toString() as T;
} }
@@ -106,6 +115,13 @@ class DydxChainQueries implements AbacusDydxChainQueriesProtocol {
); );
callback(JSON.stringify({ url: optimalNode })); callback(JSON.stringify({ url: optimalNode }));
break; break;
case QueryType.EquityTiers:
const equityTiers =
await this.compositeClient?.validatorClient.get.getEquityTierLimitConfiguration();
const parsedEquityTiers = this.parseToPrimitives(equityTiers);
console.log(parsedEquityTiers);
callback(JSON.stringify(parsedEquityTiers));
break;
case QueryType.FeeTiers: case QueryType.FeeTiers:
const feeTiers = await this.compositeClient?.validatorClient.get.getFeeTiers(); const feeTiers = await this.compositeClient?.validatorClient.get.getFeeTiers();
const parsedFeeTiers = this.parseToPrimitives(feeTiers); const parsedFeeTiers = this.parseToPrimitives(feeTiers);
+14
View File
@@ -65,3 +65,17 @@ export const getSeparator = ({
Intl.NumberFormat(locale) Intl.NumberFormat(locale)
.formatToParts(1000.1) .formatToParts(1000.1)
.find?.((part) => part.type === separatorType)?.value; .find?.((part) => part.type === separatorType)?.value;
/**
* Converts a byte array (representing an arbitrary-size signed integer) into a bigint.
* @param u Array of bytes represented as a Uint8Array.
*/
export function bytesToBigInt(u: Uint8Array): bigint {
if (u.length <= 1) {
return BigInt(0);
}
const negated: boolean = (u[0] & 1) === 1;
const hex: string = Buffer.from(u.slice(1)).toString('hex');
const abs: bigint = BigInt(`0x${hex}`);
return negated ? -abs : abs;
}