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

Send message to ingest amount as string #58

Merged
merged 6 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
11 changes: 5 additions & 6 deletions v4-client-js/__native__/__ios__/v4-native-client.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions v4-client-js/examples/transfer_example_send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async function test(): Promise<void> {
subaccount.address,
TEST_RECIPIENT_ADDRESS,
client.config.denoms.CHAINTOKEN_DENOM,
amount,
amount.toString(),
);

resolve([msg]);
Expand All @@ -55,7 +55,7 @@ async function test(): Promise<void> {
subaccount,
TEST_RECIPIENT_ADDRESS,
client.config.denoms.CHAINTOKEN_DENOM,
amountAfterFee,
amountAfterFee.toString(),
false,
Method.BroadcastTxCommit,
);
Expand Down
149 changes: 147 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.

3 changes: 2 additions & 1 deletion v4-client-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dydxprotocol/v4-client-js",
"version": "0.39.0",
"version": "0.39.1",
"description": "General client library for the new dYdX system (v4 decentralized)",
"main": "build/src/index.js",
"scripts": {
Expand Down Expand Up @@ -44,6 +44,7 @@
"bech32": "^1.1.4",
"bignumber.js": "^9.1.1",
"ethereum-cryptography": "^2.0.0",
"ethers": "^6.6.1",
"long": "^4.0.0",
"protobufjs": ">=6.11.4",
"ws": "^8.13.0"
Expand Down
41 changes: 33 additions & 8 deletions v4-client-js/src/clients/composite-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
} from '@cosmjs/stargate';
import { BroadcastTxAsyncResponse, BroadcastTxSyncResponse } from '@cosmjs/tendermint-rpc/build/tendermint37';
import { Order_ConditionType, Order_TimeInForce } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/order';
import { parseUnits } from 'ethers';
import Long from 'long';
import protobuf from 'protobufjs';

Expand Down Expand Up @@ -705,7 +706,13 @@ export class CompositeClient {
recipientSubaccountNumber: number,
amount: number,
): EncodeObject {
const quantums: Long = Long.fromNumber(amount * (10 ** 6));
const validatorClient = this._validatorClient;
if (validatorClient === undefined) {
throw new Error('validatorClient not set');
}
const quantums: Long = Long
rosepuppy marked this conversation as resolved.
Show resolved Hide resolved
.fromNumber(amount * (10 ** validatorClient.config.denoms.USDC_DECIMALS));

return this.validatorClient.post.composer.composeMsgTransfer(
subaccount.address,
subaccount.subaccountNumber,
Expand Down Expand Up @@ -756,7 +763,13 @@ export class CompositeClient {
subaccount: Subaccount,
amount: number,
): EncodeObject {
const quantums: Long = Long.fromNumber(amount * (10 ** 6));
const validatorClient = this._validatorClient;
if (validatorClient === undefined) {
throw new Error('validatorClient not set');
}
const quantums: Long = Long
.fromNumber(amount * (10 ** validatorClient.config.denoms.USDC_DECIMALS));

return this.validatorClient.post.composer.composeMsgDepositToSubaccount(
subaccount.address,
subaccount.subaccountNumber,
Expand Down Expand Up @@ -812,7 +825,13 @@ export class CompositeClient {
amount: number,
recipient?: string,
): EncodeObject {
const quantums: Long = Long.fromNumber(amount * (10 ** 6));
const validatorClient = this._validatorClient;
if (validatorClient === undefined) {
throw new Error('validatorClient not set');
}
const quantums: Long = Long
.fromNumber(amount * (10 ** validatorClient.config.denoms.USDC_DECIMALS));

return this.validatorClient.post.composer.composeMsgWithdrawFromSubaccount(
subaccount.address,
subaccount.subaccountNumber,
Expand All @@ -836,19 +855,25 @@ export class CompositeClient {
*/
sendTokenMessage(
subaccount: Subaccount,
amount: number,
amount: string,
recipient: string,
): EncodeObject {
const chainTokenDenom = this._validatorClient?.config.denoms.CHAINTOKEN_DENOM;
if (chainTokenDenom === undefined) {
const {
CHAINTOKEN_DENOM: chainTokenDenom,
CHAINTOKEN_DECIMALS: chainTokenDecimals,
} = this._validatorClient?.config.denoms || {};

if (chainTokenDenom === undefined || chainTokenDecimals === undefined) {
throw new Error('Chain token denom not set in validator config');
}
const quantums: Long = Long.fromNumber(amount * (10 ** 6));

const quantums = parseUnits(amount, chainTokenDecimals);

return this.validatorClient.post.composer.composeMsgSendToken(
subaccount.address,
recipient,
chainTokenDenom,
quantums,
quantums.toString(),
);
}

Expand Down
12 changes: 8 additions & 4 deletions v4-client-js/src/clients/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,9 @@ export class ValidatorConfig {
denoms: DenomConfig,
broadcastOptions?: BroadcastOptions,
) {
if ((restEndpoint?.endsWith('/'))) {
this.restEndpoint = restEndpoint.slice(0, -1);
}
this.restEndpoint = restEndpoint;
this.restEndpoint = restEndpoint?.endsWith('/') ? restEndpoint.slice(0, -1) : restEndpoint;
this.chainId = chainId;

this.denoms = denoms;
this.broadcastOptions = broadcastOptions;
}
Expand All @@ -186,6 +184,8 @@ export class Network {
CHAINTOKEN_DENOM: 'adv4tnt',
USDC_DENOM: 'ibc/8E27BA2D5493AF5636760E354E46004562C46AB7EC0CC4C1CA14E9E20E2545B5',
USDC_GAS_DENOM: 'uusdc',
USDC_DECIMALS: 6,
CHAINTOKEN_DECIMALS: 18,
});
return new Network('dev', indexerConfig, validatorConfig);
}
Expand All @@ -200,6 +200,8 @@ export class Network {
CHAINTOKEN_DENOM: 'adv4tnt',
USDC_DENOM: 'ibc/8E27BA2D5493AF5636760E354E46004562C46AB7EC0CC4C1CA14E9E20E2545B5',
USDC_GAS_DENOM: 'uusdc',
USDC_DECIMALS: 6,
CHAINTOKEN_DECIMALS: 18,
});
return new Network('staging', indexerConfig, validatorConfig);
}
Expand All @@ -214,6 +216,8 @@ export class Network {
CHAINTOKEN_DENOM: 'adv4tnt',
USDC_DENOM: 'ibc/8E27BA2D5493AF5636760E354E46004562C46AB7EC0CC4C1CA14E9E20E2545B5',
USDC_GAS_DENOM: 'uusdc',
USDC_DECIMALS: 6,
CHAINTOKEN_DECIMALS: 18,
});
return new Network('testnet', indexerConfig, validatorConfig);
}
Expand Down
4 changes: 2 additions & 2 deletions v4-client-js/src/clients/modules/composer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,11 @@ export class Composer {
address: string,
recipient: string,
coinDenom: string,
quantums: Long,
quantums: string,
): EncodeObject {
const coin: Coin = {
denom: coinDenom,
amount: quantums.toString(),
amount: quantums,
};

const msg: MsgSend = {
Expand Down
2 changes: 1 addition & 1 deletion v4-client-js/src/clients/modules/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ export class Post {
subaccount: Subaccount,
recipient: string,
coinDenom: string,
quantums: Long,
quantums: string,
zeroFee: boolean = true,
broadcastMode?: BroadcastMode,
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
Expand Down
Loading
Loading