@dydxprotocol/v4-client-js 1.9.1 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -3
- package/__native__/__ios__/v4-native-client.js +868 -27
- package/build/src/clients/constants.d.ts +1 -0
- package/build/src/clients/constants.js +5 -3
- package/build/src/clients/lib/registry.js +21 -18
- package/build/src/clients/modules/composer.d.ts +1 -0
- package/build/src/clients/modules/composer.js +12 -1
- package/build/src/clients/modules/get.d.ts +5 -1
- package/build/src/clients/modules/get.js +25 -1
- package/build/src/clients/modules/post.d.ts +3 -1
- package/build/src/clients/modules/post.js +17 -9
- package/build/src/clients/modules/proto-includes.d.ts +1 -0
- package/build/src/clients/modules/proto-includes.js +3 -2
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/clients/constants.ts +3 -0
- package/src/clients/lib/registry.ts +6 -0
- package/src/clients/modules/composer.ts +15 -0
- package/src/clients/modules/get.ts +51 -0
- package/src/clients/modules/post.ts +46 -10
- package/src/clients/modules/proto-includes.ts +1 -0
package/package.json
CHANGED
package/src/clients/constants.ts
CHANGED
|
@@ -97,6 +97,9 @@ export const TYPE_URL_MSG_WITHDRAW_FROM_SUBACCOUNT =
|
|
|
97
97
|
'/dydxprotocol.sending.MsgWithdrawFromSubaccount';
|
|
98
98
|
export const TYPE_URL_MSG_DEPOSIT_TO_SUBACCOUNT = '/dydxprotocol.sending.MsgDepositToSubaccount';
|
|
99
99
|
|
|
100
|
+
// x/affiliates
|
|
101
|
+
export const TYPE_URL_MSG_REGISTER_AFFILIATE = '/dydxprotocol.affiliates.MsgRegisterAffiliate';
|
|
102
|
+
|
|
100
103
|
// x/vault
|
|
101
104
|
export const TYPE_URL_MSG_DEPOSIT_TO_MEGAVAULT = '/dydxprotocol.vault.MsgDepositToMegavault';
|
|
102
105
|
export const TYPE_URL_MSG_WITHDRAW_FROM_MEGAVAULT = '/dydxprotocol.vault.MsgWithdrawFromMegavault';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { GeneratedType, Registry } from '@cosmjs/proto-signing';
|
|
2
2
|
import { defaultRegistryTypes } from '@cosmjs/stargate';
|
|
3
|
+
import { MsgRegisterAffiliate } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/affiliates/tx';
|
|
3
4
|
import {
|
|
4
5
|
MsgPlaceOrder,
|
|
5
6
|
MsgCancelOrder,
|
|
@@ -34,6 +35,7 @@ import {
|
|
|
34
35
|
TYPE_URL_BATCH_CANCEL,
|
|
35
36
|
TYPE_URL_MSG_DEPOSIT_TO_MEGAVAULT,
|
|
36
37
|
TYPE_URL_MSG_WITHDRAW_FROM_MEGAVAULT,
|
|
38
|
+
TYPE_URL_MSG_REGISTER_AFFILIATE,
|
|
37
39
|
} from '../constants';
|
|
38
40
|
|
|
39
41
|
export const registry: ReadonlyArray<[string, GeneratedType]> = [];
|
|
@@ -58,11 +60,15 @@ export function generateRegistry(): Registry {
|
|
|
58
60
|
// vaults
|
|
59
61
|
[TYPE_URL_MSG_DEPOSIT_TO_MEGAVAULT, MsgDepositToMegavault as GeneratedType],
|
|
60
62
|
[TYPE_URL_MSG_WITHDRAW_FROM_MEGAVAULT, MsgWithdrawFromMegavault as GeneratedType],
|
|
63
|
+
|
|
61
64
|
// sending
|
|
62
65
|
[TYPE_URL_MSG_CREATE_TRANSFER, MsgCreateTransfer as GeneratedType],
|
|
63
66
|
[TYPE_URL_MSG_WITHDRAW_FROM_SUBACCOUNT, MsgWithdrawFromSubaccount as GeneratedType],
|
|
64
67
|
[TYPE_URL_MSG_DEPOSIT_TO_SUBACCOUNT, MsgDepositToSubaccount as GeneratedType],
|
|
65
68
|
|
|
69
|
+
// affiliates
|
|
70
|
+
[TYPE_URL_MSG_REGISTER_AFFILIATE, MsgRegisterAffiliate as GeneratedType],
|
|
71
|
+
|
|
66
72
|
// default types
|
|
67
73
|
...defaultRegistryTypes,
|
|
68
74
|
]);
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
MsgDelegate,
|
|
8
8
|
MsgUndelegate,
|
|
9
9
|
} from '@dydxprotocol/v4-proto/src/codegen/cosmos/staking/v1beta1/tx';
|
|
10
|
+
import { MsgRegisterAffiliate } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/affiliates/tx';
|
|
10
11
|
import { ClobPair_Status } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/clob_pair';
|
|
11
12
|
import {
|
|
12
13
|
MsgBatchCancel,
|
|
@@ -47,6 +48,7 @@ import {
|
|
|
47
48
|
TYPE_URL_MSG_UNDELEGATE,
|
|
48
49
|
TYPE_URL_MSG_WITHDRAW_DELEGATOR_REWARD,
|
|
49
50
|
TYPE_URL_BATCH_CANCEL,
|
|
51
|
+
TYPE_URL_MSG_REGISTER_AFFILIATE,
|
|
50
52
|
TYPE_URL_MSG_DEPOSIT_TO_MEGAVAULT,
|
|
51
53
|
TYPE_URL_MSG_WITHDRAW_FROM_MEGAVAULT,
|
|
52
54
|
} from '../constants';
|
|
@@ -536,6 +538,19 @@ export class Composer {
|
|
|
536
538
|
};
|
|
537
539
|
}
|
|
538
540
|
|
|
541
|
+
// ------------ x/affiliates ------------
|
|
542
|
+
public composeMsgRegisterAffiliate(referee: string, affiliate: string): EncodeObject {
|
|
543
|
+
const msg: MsgRegisterAffiliate = {
|
|
544
|
+
referee,
|
|
545
|
+
affiliate,
|
|
546
|
+
};
|
|
547
|
+
|
|
548
|
+
return {
|
|
549
|
+
typeUrl: TYPE_URL_MSG_REGISTER_AFFILIATE,
|
|
550
|
+
value: msg,
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
|
|
539
554
|
// ------------ util ------------
|
|
540
555
|
public validateGoodTilBlockAndTime(
|
|
541
556
|
orderFlags: number,
|
|
@@ -17,6 +17,7 @@ import { bigIntToBytes } from '../../lib/helpers';
|
|
|
17
17
|
import { PAGE_REQUEST } from '../constants';
|
|
18
18
|
import { UnexpectedClientError } from '../lib/errors';
|
|
19
19
|
import {
|
|
20
|
+
AffiliateModule,
|
|
20
21
|
BridgeModule,
|
|
21
22
|
ClobModule,
|
|
22
23
|
DistributionModule,
|
|
@@ -559,6 +560,56 @@ export class Get {
|
|
|
559
560
|
return VaultModule.QueryMegavaultWithdrawalInfoResponse.decode(data);
|
|
560
561
|
}
|
|
561
562
|
|
|
563
|
+
async getAffiliateInfo(address: string): Promise<AffiliateModule.AffiliateInfoResponse> {
|
|
564
|
+
const requestData = Uint8Array.from(
|
|
565
|
+
AffiliateModule.AffiliateInfoRequest.encode({
|
|
566
|
+
address,
|
|
567
|
+
}).finish(),
|
|
568
|
+
);
|
|
569
|
+
|
|
570
|
+
const data = await this.sendQuery('/dydxprotocol.affiliates.Query/AffiliateInfo', requestData);
|
|
571
|
+
|
|
572
|
+
return AffiliateModule.AffiliateInfoResponse.decode(data);
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
async getReferredBy(address: string): Promise<AffiliateModule.ReferredByResponse> {
|
|
576
|
+
const requestData = Uint8Array.from(
|
|
577
|
+
AffiliateModule.ReferredByRequest.encode({
|
|
578
|
+
address,
|
|
579
|
+
}).finish(),
|
|
580
|
+
);
|
|
581
|
+
|
|
582
|
+
const data = await this.sendQuery('/dydxprotocol.affiliates.Query/ReferredBy', requestData);
|
|
583
|
+
|
|
584
|
+
return AffiliateModule.ReferredByResponse.decode(data);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
async getAllAffiliateTiers(): Promise<AffiliateModule.AllAffiliateTiersResponse> {
|
|
588
|
+
const requestData = Uint8Array.from(
|
|
589
|
+
AffiliateModule.AllAffiliateTiersRequest.encode({}).finish(),
|
|
590
|
+
);
|
|
591
|
+
|
|
592
|
+
const data = await this.sendQuery(
|
|
593
|
+
'/dydxprotocol.affiliates.Query/AllAffiliateTiers',
|
|
594
|
+
requestData,
|
|
595
|
+
);
|
|
596
|
+
|
|
597
|
+
return AffiliateModule.AllAffiliateTiersResponse.decode(data);
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
async getAffiliateWhitelist(): Promise<AffiliateModule.AffiliateWhitelistResponse> {
|
|
601
|
+
const requestData = Uint8Array.from(
|
|
602
|
+
AffiliateModule.AffiliateWhitelistRequest.encode({}).finish(),
|
|
603
|
+
);
|
|
604
|
+
|
|
605
|
+
const data = await this.sendQuery(
|
|
606
|
+
'/dydxprotocol.affiliates.Query/AffiliateWhitelist',
|
|
607
|
+
requestData,
|
|
608
|
+
);
|
|
609
|
+
|
|
610
|
+
return AffiliateModule.AffiliateWhitelistResponse.decode(data);
|
|
611
|
+
}
|
|
612
|
+
|
|
562
613
|
private async sendQuery(requestUrl: string, requestData: Uint8Array): Promise<Uint8Array> {
|
|
563
614
|
// eslint-disable-next-line max-len
|
|
564
615
|
const resp: QueryAbciResponse = await this.stargateQueryClient.queryAbci(
|
|
@@ -58,7 +58,13 @@ export class Post {
|
|
|
58
58
|
public useTimestampNonce: boolean = false;
|
|
59
59
|
private accountNumberCache: Map<string, Account> = new Map();
|
|
60
60
|
|
|
61
|
-
constructor(
|
|
61
|
+
constructor(
|
|
62
|
+
get: Get,
|
|
63
|
+
chainId: string,
|
|
64
|
+
denoms: DenomConfig,
|
|
65
|
+
defaultClientMemo?: string,
|
|
66
|
+
useTimestampNonce?: boolean,
|
|
67
|
+
) {
|
|
62
68
|
this.get = get;
|
|
63
69
|
this.chainId = chainId;
|
|
64
70
|
this.registry = generateRegistry();
|
|
@@ -129,13 +135,7 @@ export class Post {
|
|
|
129
135
|
sequence = msgsAndAccount[1].sequence;
|
|
130
136
|
}
|
|
131
137
|
|
|
132
|
-
return this.simulateTransaction(
|
|
133
|
-
wallet.pubKey!,
|
|
134
|
-
sequence,
|
|
135
|
-
msgs,
|
|
136
|
-
gasPrice,
|
|
137
|
-
memo,
|
|
138
|
-
);
|
|
138
|
+
return this.simulateTransaction(wallet.pubKey!, sequence, msgs, gasPrice, memo);
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
/**
|
|
@@ -177,6 +177,7 @@ export class Post {
|
|
|
177
177
|
memo?: string,
|
|
178
178
|
broadcastMode?: BroadcastMode,
|
|
179
179
|
account?: () => Promise<Account>,
|
|
180
|
+
gasAdjustment: number = GAS_MULTIPLIER,
|
|
180
181
|
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
|
|
181
182
|
const msgsPromise = messaging();
|
|
182
183
|
const accountPromise = account ? await account() : this.account(wallet.address!);
|
|
@@ -191,6 +192,7 @@ export class Post {
|
|
|
191
192
|
gasPrice,
|
|
192
193
|
memo ?? this.defaultClientMemo,
|
|
193
194
|
broadcastMode ?? this.defaultBroadcastMode(msgs),
|
|
195
|
+
gasAdjustment,
|
|
194
196
|
);
|
|
195
197
|
}
|
|
196
198
|
|
|
@@ -235,6 +237,7 @@ export class Post {
|
|
|
235
237
|
zeroFee: boolean,
|
|
236
238
|
gasPrice: GasPrice = this.getGasPrice(),
|
|
237
239
|
memo?: string,
|
|
240
|
+
gasAdjustment: number = GAS_MULTIPLIER,
|
|
238
241
|
): Promise<Uint8Array> {
|
|
239
242
|
// protocol expects timestamp nonce in UTC milliseconds, which is the unit returned by Date.now()
|
|
240
243
|
const sequence = this.useTimestampNonce ? Date.now() : account.sequence;
|
|
@@ -244,7 +247,14 @@ export class Post {
|
|
|
244
247
|
amount: [],
|
|
245
248
|
gas: '1000000',
|
|
246
249
|
}
|
|
247
|
-
: await this.simulateTransaction(
|
|
250
|
+
: await this.simulateTransaction(
|
|
251
|
+
wallet.pubKey!,
|
|
252
|
+
sequence,
|
|
253
|
+
messages,
|
|
254
|
+
gasPrice,
|
|
255
|
+
memo,
|
|
256
|
+
gasAdjustment,
|
|
257
|
+
);
|
|
248
258
|
|
|
249
259
|
const txOptions: TransactionOptions = {
|
|
250
260
|
sequence,
|
|
@@ -286,6 +296,7 @@ export class Post {
|
|
|
286
296
|
gasPrice: GasPrice = this.getGasPrice(),
|
|
287
297
|
memo?: string,
|
|
288
298
|
broadcastMode?: BroadcastMode,
|
|
299
|
+
gasAdjustment: number = GAS_MULTIPLIER,
|
|
289
300
|
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
|
|
290
301
|
const signedTransaction = await this.signTransaction(
|
|
291
302
|
wallet,
|
|
@@ -294,6 +305,7 @@ export class Post {
|
|
|
294
305
|
zeroFee,
|
|
295
306
|
gasPrice,
|
|
296
307
|
memo,
|
|
308
|
+
gasAdjustment,
|
|
297
309
|
);
|
|
298
310
|
return this.sendSignedTransaction(signedTransaction, broadcastMode);
|
|
299
311
|
}
|
|
@@ -326,6 +338,7 @@ export class Post {
|
|
|
326
338
|
messages: readonly EncodeObject[],
|
|
327
339
|
gasPrice: GasPrice = this.getGasPrice(),
|
|
328
340
|
memo?: string,
|
|
341
|
+
gasAdjustment: number = GAS_MULTIPLIER,
|
|
329
342
|
): Promise<StdFee> {
|
|
330
343
|
// Get simulated response.
|
|
331
344
|
const encodedMessages: Any[] = messages.map((message: EncodeObject) =>
|
|
@@ -347,7 +360,7 @@ export class Post {
|
|
|
347
360
|
const gasEstimate: number = Uint53.fromString(
|
|
348
361
|
simulationResponse.gasInfo.gasUsed.toString(),
|
|
349
362
|
).toNumber();
|
|
350
|
-
const fee = calculateFee(Math.floor(gasEstimate *
|
|
363
|
+
const fee = calculateFee(Math.floor(gasEstimate * gasAdjustment), gasPrice);
|
|
351
364
|
|
|
352
365
|
// TODO(TRCL-2550): Temporary workaround before IBC denom is supported in '@cosmjs/stargate'.
|
|
353
366
|
// The '@cosmjs/stargate' does not support denom with '/', so currently GAS_PRICE is
|
|
@@ -881,4 +894,27 @@ export class Post {
|
|
|
881
894
|
): EncodeObject {
|
|
882
895
|
return this.composer.composeMsgWithdrawFromMegavault(...args);
|
|
883
896
|
}
|
|
897
|
+
|
|
898
|
+
async registerAffiliate(
|
|
899
|
+
subaccount: SubaccountInfo,
|
|
900
|
+
affiliate: string,
|
|
901
|
+
broadcastMode?: BroadcastMode,
|
|
902
|
+
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
|
|
903
|
+
const msg = this.registerAffiliateMsg(subaccount.address, affiliate);
|
|
904
|
+
const gasAdjustment = 1.8;
|
|
905
|
+
return this.send(
|
|
906
|
+
subaccount.wallet,
|
|
907
|
+
() => Promise.resolve([msg]),
|
|
908
|
+
false,
|
|
909
|
+
undefined,
|
|
910
|
+
undefined,
|
|
911
|
+
broadcastMode,
|
|
912
|
+
undefined,
|
|
913
|
+
gasAdjustment,
|
|
914
|
+
);
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
registerAffiliateMsg(...args: Parameters<Composer['composeMsgRegisterAffiliate']>): EncodeObject {
|
|
918
|
+
return this.composer.composeMsgRegisterAffiliate(...args);
|
|
919
|
+
}
|
|
884
920
|
}
|
|
@@ -11,6 +11,7 @@ export * as RewardsModule from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/
|
|
|
11
11
|
export * as StakingModule from '@dydxprotocol/v4-proto/src/codegen/cosmos/staking/v1beta1/query';
|
|
12
12
|
export * as BridgeModule from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/bridge/query';
|
|
13
13
|
export * as DistributionModule from '@dydxprotocol/v4-proto/src/codegen/cosmos/distribution/v1beta1/query';
|
|
14
|
+
export * as AffiliateModule from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/affiliates/query';
|
|
14
15
|
export * as VaultModule from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/query';
|
|
15
16
|
|
|
16
17
|
export * from '@dydxprotocol/v4-proto/src/codegen/cosmos/base/abci/v1beta1/abci';
|