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

Update connectNetwork param and testnet id #60

Merged
merged 4 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
109 changes: 74 additions & 35 deletions v4-client-js/__native__/__ios__/v4-native-client.js

Large diffs are not rendered by default.

19 changes: 12 additions & 7 deletions v4-client-js/examples/native_examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,18 @@ async function test(): Promise<void> {
tx = await withdrawToIBC(0, '13', encoded);
console.log(tx);

const connected = await connectNetwork(
'dydxprotocol-testnet',
'https://validator.v4staging.dydx.exchange',
'https://indexer.v4staging.dydx.exchange',
'wss://indexer.v4staging.dydx.exchange/v4/ws',
'https://faucet.v4staging.dydx.exchange',
);
const connected = await connectNetwork(JSON.stringify({
indexerUrl: 'https://indexer.v4staging.dydx.exchange',
websocketUrl: 'wss://indexer.v4staging.dydx.exchange/v4/ws',
validatorUrl: 'https://validator.v4staging.dydx.exchange',
chainId: 'dydxprotocol-testnet',
faucetUrl: 'https://faucet.v4staging.dydx.exchange',
USDC_DENOM: 'ibc/8E27BA2D5493AF5636760E354E46004562C46AB7EC0CC4C1CA14E9E20E2545B5',
USDC_DECIMALS: 6,
USDC_GAS_DENOM: 'uusdc',
CHAINTOKEN_DENOM: 'adv4tnt',
CHAINTOKEN_DECIMALS: 18,
}));
console.log(connected);

} catch (error) {
Expand Down
4 changes: 2 additions & 2 deletions v4-client-js/package-lock.json

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

10 changes: 5 additions & 5 deletions v4-client-js/src/clients/composite-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,8 @@ export class CompositeClient {
clientId: number,
orderFlags: OrderFlags,
marketId: string,
goodTilBlock: number,
goodTilTimeInSeconds: number,
goodTilBlock?: number,
goodTilTimeInSeconds?: number,
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {

const marketsResponse = await this.indexerClient.markets.getPerpetualMarkets(marketId);
Expand All @@ -625,7 +625,7 @@ export class CompositeClient {

let goodTilBlockTime;
if (isStatefulOrder(orderFlags)) {
if (goodTilTimeInSeconds === 0) {
if (goodTilTimeInSeconds === undefined || goodTilTimeInSeconds === 0) {
throw new Error('goodTilTimeInSeconds must be set for LONG_TERM or CONDITIONAL order');
}
if (goodTilBlock !== 0) {
Expand All @@ -636,10 +636,10 @@ export class CompositeClient {
}
goodTilBlockTime = this.calculateGoodTilBlockTime(goodTilTimeInSeconds);
} else {
if (goodTilBlock === 0) {
if (goodTilBlock === undefined || goodTilBlock === 0) {
throw new Error('goodTilBlock must be non-zero for SHORT_TERM orders');
}
if (goodTilTimeInSeconds !== 0) {
if (goodTilTimeInSeconds !== undefined && goodTilTimeInSeconds !== 0) {
throw new Error('goodTilTimeInSeconds should be zero since SHORT_TERM orders use goodTilBlock instead of goodTilTimeInSeconds.');
}
}
Expand Down
2 changes: 1 addition & 1 deletion v4-client-js/src/clients/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export * from '../lib/constants';
// Chain ID
export const DEV_CHAIN_ID = 'dydxprotocol-testnet';
export const STAGING_CHAIN_ID = 'dydxprotocol-testnet';
export const TESTNET_CHAIN_ID = 'dydx-testnet-3';
export const TESTNET_CHAIN_ID = 'dydx-testnet-4';

// ------------ API URLs ------------
export enum IndexerApiHost {
Expand Down
4 changes: 2 additions & 2 deletions v4-client-js/src/clients/modules/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ export class Post {
public readonly get: Get;
public readonly denoms: DenomConfig;

private readonly defaultGasPrice: GasPrice;
private readonly defaultDydxGasPrice: GasPrice;
public readonly defaultGasPrice: GasPrice;
public readonly defaultDydxGasPrice: GasPrice;

private accountNumberCache: Map<string, Account> = new Map();

Expand Down
54 changes: 36 additions & 18 deletions v4-client-js/src/clients/native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,45 @@ export async function connectClient(
}

export async function connectNetwork(
chainId: string,
validatorUrl: string,
indexerUrl: string,
indexerSocketUrl: string,
faucetUrl?: string,
usdcDenom?: string,
usdcDecimals?: string,
usdcGasDenom?: string,
chainTokenDenom?: string,
chainTokenDecimals?: string,
chainTokenGasDenom?: string,
paramsJSON: string,
): Promise<string> {
try {
const indexerConfig = new IndexerConfig(indexerUrl, indexerSocketUrl);
const params = JSON.parse(paramsJSON);
const {
indexerUrl,
websocketUrl,
validatorUrl,
chainId,
faucetUrl,
USDC_DENOM,
USDC_DECIMALS,
USDC_GAS_DENOM,
CHAINTOKEN_DENOM,
CHAINTOKEN_DECIMALS,
CHAINTOKEN_GAS_DENOM,
} = params;

if (indexerUrl === undefined ||
websocketUrl === undefined ||
validatorUrl === undefined ||
chainId === undefined) {
throw new UserError('Missing required network params');
}
if (USDC_DENOM === undefined ||
USDC_DECIMALS === undefined ||
CHAINTOKEN_DENOM === undefined ||
CHAINTOKEN_DECIMALS === undefined) {
throw new UserError('Missing required token params');
}

const indexerConfig = new IndexerConfig(indexerUrl, websocketUrl);
const validatorConfig = new ValidatorConfig(validatorUrl, chainId, {
USDC_DENOM: usdcDenom ?? 'ibc/8E27BA2D5493AF5636760E354E46004562C46AB7EC0CC4C1CA14E9E20E2545B5',
USDC_DECIMALS: parseInt(usdcDecimals ?? '6', 10),
USDC_GAS_DENOM: usdcGasDenom ?? 'uusdc',
CHAINTOKEN_DENOM: chainTokenDenom ?? 'adv4tnt',
CHAINTOKEN_DECIMALS: parseInt(chainTokenDecimals ?? '18', 10),
CHAINTOKEN_GAS_DENOM: chainTokenGasDenom,
USDC_DENOM,
USDC_DECIMALS,
USDC_GAS_DENOM,
CHAINTOKEN_DENOM,
CHAINTOKEN_DECIMALS,
CHAINTOKEN_GAS_DENOM,
});
const config = new Network('native', indexerConfig, validatorConfig);
globalThis.client = await CompositeClient.connect(config);
Expand Down