example-js-sdk 0.0.6 → 0.0.8
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/README.md +134 -52
- package/lib/OrbixSDK.d.ts +145 -0
- package/lib/{CarbonSDK.js → OrbixSDK.js} +52 -52
- package/lib/clients/ETHClient.d.ts +10 -10
- package/lib/clients/ETHClient.js +4 -4
- package/lib/clients/{CarbonQueryClient.d.ts → OrbixQueryClient.d.ts} +4 -4
- package/lib/clients/{CarbonQueryClient.js → OrbixQueryClient.js} +2 -2
- package/lib/clients/TokenClient.d.ts +26 -26
- package/lib/clients/TokenClient.js +5 -5
- package/lib/clients/index.d.ts +1 -1
- package/lib/clients/index.js +3 -3
- package/lib/codec/index.d.ts +1 -1
- package/lib/codec/index.js +253 -253
- package/lib/constant/eip712.d.ts +1 -1
- package/lib/constant/eip712.js +2 -2
- package/lib/constant/generic.d.ts +1 -1
- package/lib/constant/generic.js +2 -2
- package/lib/constant/ibc.d.ts +0 -1
- package/lib/constant/ibc.js +0 -32
- package/lib/constant/network.d.ts +2 -2
- package/lib/constant/network.js +3 -3
- package/lib/constant/node.js +2 -74
- package/lib/constant/web3Config.d.ts +5 -5
- package/lib/constant/web3Config.js +18 -22
- package/lib/index.d.ts +3 -3
- package/lib/index.js +7 -7
- package/lib/insights/balance.d.ts +2 -2
- package/lib/modules/admin.d.ts +23 -23
- package/lib/modules/admin.js +43 -43
- package/lib/modules/alliance.d.ts +6 -6
- package/lib/modules/alliance.js +5 -5
- package/lib/modules/bank.d.ts +2 -2
- package/lib/modules/bank.js +1 -1
- package/lib/modules/base.d.ts +4 -4
- package/lib/modules/bridge.d.ts +3 -3
- package/lib/modules/bridge.js +5 -5
- package/lib/modules/broker.d.ts +3 -3
- package/lib/modules/broker.js +2 -2
- package/lib/modules/coin.d.ts +8 -8
- package/lib/modules/coin.js +7 -7
- package/lib/modules/evm.d.ts +2 -2
- package/lib/modules/evm.js +1 -1
- package/lib/modules/evmmerge.d.ts +2 -2
- package/lib/modules/evmmerge.js +3 -3
- package/lib/modules/gov.d.ts +4 -4
- package/lib/modules/gov.js +3 -3
- package/lib/modules/grant.d.ts +4 -4
- package/lib/modules/grant.js +6 -6
- package/lib/modules/ibc.d.ts +3 -3
- package/lib/modules/ibc.js +2 -2
- package/lib/modules/leverage.d.ts +3 -3
- package/lib/modules/leverage.js +2 -2
- package/lib/modules/market.d.ts +15 -15
- package/lib/modules/market.js +7 -7
- package/lib/modules/order.d.ts +8 -8
- package/lib/modules/order.js +7 -7
- package/lib/modules/perpspool.d.ts +14 -14
- package/lib/modules/perpspool.js +23 -23
- package/lib/modules/position.d.ts +3 -3
- package/lib/modules/position.js +2 -2
- package/lib/modules/staking.d.ts +6 -6
- package/lib/modules/subaccount.d.ts +4 -4
- package/lib/modules/subaccount.js +3 -3
- package/lib/provider/amino/types/admin.js +12 -12
- package/lib/provider/amino/types/bank.js +2 -2
- package/lib/provider/amino/types/bridge.js +3 -3
- package/lib/provider/amino/types/broker.js +2 -2
- package/lib/provider/amino/types/coin.js +5 -5
- package/lib/provider/amino/types/evm.js +2 -2
- package/lib/provider/amino/types/evmmerge.js +2 -2
- package/lib/provider/amino/types/feemarket.js +2 -2
- package/lib/provider/amino/types/gov.js +17 -17
- package/lib/provider/amino/types/grant.js +6 -6
- package/lib/provider/amino/types/group.js +4 -4
- package/lib/provider/amino/types/ibc.js +2 -2
- package/lib/provider/amino/types/leverage.js +2 -2
- package/lib/provider/amino/types/market.js +7 -7
- package/lib/provider/amino/types/order.js +5 -5
- package/lib/provider/amino/types/perpspool.js +11 -11
- package/lib/provider/amino/types/position.js +2 -2
- package/lib/provider/amino/types/staking.js +5 -5
- package/lib/provider/amino/types/subaccount.js +4 -4
- package/lib/provider/keplr/KeplrAccount.d.ts +3 -3
- package/lib/provider/keplr/KeplrAccount.js +8 -8
- package/lib/provider/leap/LeapAccount.d.ts +3 -3
- package/lib/provider/leap/LeapAccount.js +7 -7
- package/lib/provider/metamask/MetaMask.d.ts +8 -8
- package/lib/provider/metamask/MetaMask.js +17 -17
- package/lib/provider/rainbowKit/RainbowKitAccount.d.ts +7 -7
- package/lib/provider/rainbowKit/RainbowKitAccount.js +12 -12
- package/lib/provider/sdk/SDKProvider.d.ts +4 -4
- package/lib/util/alliance.js +1 -1
- package/lib/util/blockchain.d.ts +5 -5
- package/lib/util/blockchain.js +11 -11
- package/lib/util/eip712.d.ts +2 -2
- package/lib/util/eip712.js +1 -1
- package/lib/util/ethermint.d.ts +4 -4
- package/lib/util/ethermint.js +1 -1
- package/lib/util/external.d.ts +2 -2
- package/lib/util/gov.js +16 -16
- package/lib/util/index.d.ts +1 -1
- package/lib/util/index.js +2 -2
- package/lib/util/legacyEIP712.js +1 -1
- package/lib/util/network.d.ts +1 -1
- package/lib/util/network.js +7 -7
- package/lib/util/provider.js +1 -1
- package/lib/util/tx.d.ts +3 -3
- package/lib/util/tx.js +9 -9
- package/lib/wallet/{CarbonSigner.d.ts → OrbixSigner.d.ts} +19 -19
- package/lib/wallet/{CarbonSigner.js → OrbixSigner.js} +19 -19
- package/lib/wallet/{CarbonSigningClient.d.ts → OrbixSigningClient.d.ts} +3 -3
- package/lib/wallet/{CarbonSigningClient.js → OrbixSigningClient.js} +9 -9
- package/lib/wallet/{CarbonWallet.d.ts → OrbixWallet.d.ts} +38 -38
- package/lib/wallet/{CarbonWallet.js → OrbixWallet.js} +39 -39
- package/lib/wallet/index.d.ts +2 -2
- package/lib/wallet/index.js +2 -2
- package/package.json +1 -1
- package/lib/CarbonSDK.d.ts +0 -145
- /package/lib/codec/{carbon-models.d.ts → orbix-models.d.ts} +0 -0
- /package/lib/codec/{carbon-models.js → orbix-models.js} +0 -0
package/README.md
CHANGED
|
@@ -1,38 +1,13 @@
|
|
|
1
|
-
###
|
|
1
|
+
### Mememax Orbix TypeScript SDK ###
|
|
2
2
|
|
|
3
3
|
# Get Started
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
# go to the root of your carbon-js-sdk directory
|
|
9
|
-
cd /path/to/carbon-js-sdk
|
|
10
|
-
|
|
11
|
-
# install ts-node, typescript
|
|
12
|
-
npm i -g ts-node typescript
|
|
13
|
-
|
|
14
|
-
# install local dependencies
|
|
15
|
-
yarn
|
|
16
|
-
|
|
17
|
-
# build the SDK
|
|
18
|
-
yarn build
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## To Run Example script
|
|
22
|
-
```bash
|
|
23
|
-
# run connect SDK example
|
|
24
|
-
ts-node examples/connect_sdk
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
## Initializing CarbonSDK
|
|
5
|
+
## Initializing SDK
|
|
28
6
|
|
|
29
7
|
```typescript
|
|
30
8
|
|
|
31
9
|
const sdk = await CarbonSDK.instance({
|
|
32
10
|
network: CarbonSDK.Network.LocalHost,
|
|
33
|
-
|
|
34
|
-
// optionally provide a set of network configuration overrides
|
|
35
|
-
// to overwrite default parameters for a selected network.
|
|
36
11
|
config: {
|
|
37
12
|
tmRpcUrl: TRPC_ENDPOINT,
|
|
38
13
|
},
|
|
@@ -45,45 +20,152 @@ ts-node examples/connect_sdk
|
|
|
45
20
|
const sdk2 = await sdk.connectWithPrivateKey(privateKey);
|
|
46
21
|
|
|
47
22
|
// connect SDK with custom signer (ideal for ledger/ext wallet implementation)
|
|
48
|
-
|
|
49
|
-
const sdk3 = await sdk.connectWithSigner(signer, bech32Address);
|
|
23
|
+
const sdk3 = await sdk.connectWithSigner(signer, publicKeyBase64);
|
|
50
24
|
|
|
51
25
|
```
|
|
52
26
|
|
|
53
|
-
|
|
27
|
+
## Usage Overview
|
|
54
28
|
|
|
55
|
-
|
|
56
|
-
Runs the scripts [update-proto.sh](./scripts/update-proto.sh) followed by [generate-registry.sh](./scripts/generate-registry.sh)
|
|
29
|
+
The SDK provides a structured way to interact with the Orbix blockchain.
|
|
57
30
|
|
|
58
|
-
|
|
31
|
+
### Architecture
|
|
59
32
|
|
|
60
|
-
```
|
|
61
|
-
|
|
33
|
+
```
|
|
34
|
+
Your Application (e.g. Node.js/React)
|
|
35
|
+
↓ initialize & connect
|
|
36
|
+
SDK (SDK.instance)
|
|
37
|
+
↓ call module methods
|
|
38
|
+
sdk.order / sdk.leverage / sdk.ibc / sdk.bridge ...
|
|
39
|
+
↓ broadcast transaction
|
|
40
|
+
Orbix Chain
|
|
62
41
|
```
|
|
63
42
|
|
|
64
|
-
|
|
43
|
+
### Common SDK Methods
|
|
44
|
+
|
|
45
|
+
| Module | Method | Description |
|
|
46
|
+
|--------|--------|-------------|
|
|
47
|
+
| `order` | `sdk.order.create(params)` | Create a single order |
|
|
48
|
+
| `order` | `sdk.order.createOrders(params[])` | Create multiple orders or set leverage in batch |
|
|
49
|
+
| `order` | `sdk.order.edit(params)` | Edit an existing order |
|
|
50
|
+
| `order` | `sdk.order.cancel(params)` | Cancel an order |
|
|
51
|
+
| `order` | `sdk.order.cancelAll(params)` | Cancel all orders for a market |
|
|
52
|
+
| `leverage` | `sdk.leverage.set(params)` | Set leverage multiplier |
|
|
53
|
+
| `ibc` | `sdk.ibc.sendIbcTransferV2(params)` | Cross-chain IBC transfer |
|
|
54
|
+
| `bridge` | `sdk.bridge.withdraw(params)` | Cross-chain bridge withdrawal |
|
|
55
|
+
| `admin` | `sdk.admin.createToken(params)` | Create a new token (Admin only) |
|
|
56
|
+
| `admin` | `sdk.admin.createMarket(params)` | Create a new market (Admin only) |
|
|
57
|
+
| `admin` | `sdk.admin.setTradingFlag(params)` | Enable/disable trading for a blockchain |
|
|
58
|
+
| `evm` | `sdk.evm.sendEvmTx(params)` | Send EVM transaction (Contract calls) |
|
|
59
|
+
|
|
60
|
+
### Examples
|
|
61
|
+
|
|
62
|
+
#### Create a Limit Order
|
|
63
|
+
```typescript
|
|
64
|
+
import BigNumber from "bignumber.js";
|
|
65
|
+
|
|
66
|
+
await sdk.order.create({
|
|
67
|
+
marketId: 'btc_z29',
|
|
68
|
+
side: CarbonSDK.OrderSide.Buy,
|
|
69
|
+
orderType: CarbonSDK.OrderType.Limit,
|
|
70
|
+
price: new BigNumber(50000),
|
|
71
|
+
quantity: new BigNumber(0.1),
|
|
72
|
+
timeInForce: CarbonSDK.TimeInForce.Gtc,
|
|
73
|
+
})
|
|
74
|
+
```
|
|
65
75
|
|
|
66
|
-
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
76
|
+
#### Create Order + Set Leverage (Batch)
|
|
77
|
+
```typescript
|
|
78
|
+
await sdk.order.createOrders([
|
|
79
|
+
{
|
|
80
|
+
marketId: 'btc_z29',
|
|
81
|
+
leverage: new BigNumber(10),
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
marketId: 'btc_z29',
|
|
85
|
+
side: CarbonSDK.OrderSide.Buy,
|
|
86
|
+
orderType: CarbonSDK.OrderType.Limit,
|
|
87
|
+
price: new BigNumber(50000),
|
|
88
|
+
quantity: new BigNumber(0.1),
|
|
89
|
+
}
|
|
90
|
+
])
|
|
71
91
|
```
|
|
72
92
|
|
|
73
|
-
|
|
74
|
-
```
|
|
75
|
-
|
|
93
|
+
#### IBC Transfer
|
|
94
|
+
```typescript
|
|
95
|
+
await sdk.ibc.sendIbcTransferV2({
|
|
96
|
+
sourceChannel: 'channel-0',
|
|
97
|
+
receiver: 'meme1...',
|
|
98
|
+
token: { denom: 'meme', amount: '1000000' },
|
|
99
|
+
timeoutTimestamp: (Date.now() + 60000).toString(),
|
|
100
|
+
})
|
|
76
101
|
```
|
|
77
102
|
|
|
78
|
-
|
|
103
|
+
#### Admin: Create a New Token
|
|
104
|
+
```typescript
|
|
105
|
+
await sdk.admin.createToken({
|
|
106
|
+
name: "New Token",
|
|
107
|
+
symbol: "NEW",
|
|
108
|
+
decimals: 18,
|
|
109
|
+
chainId: 1,
|
|
110
|
+
bridgeId: 1,
|
|
111
|
+
bridgeAddress: "0x...",
|
|
112
|
+
tokenAddress: "0x...",
|
|
113
|
+
})
|
|
114
|
+
```
|
|
79
115
|
|
|
80
|
-
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
|
|
116
|
+
#### Admin: Create a New Market
|
|
117
|
+
```typescript
|
|
118
|
+
await sdk.admin.createMarket({
|
|
119
|
+
marketType: "futures",
|
|
120
|
+
base: "btc",
|
|
121
|
+
quote: "usd",
|
|
122
|
+
currentBasePriceUsd: new BigNumber(50000),
|
|
123
|
+
currentQuotePriceUsd: new BigNumber(1),
|
|
124
|
+
indexOracleId: "btc_oracle",
|
|
125
|
+
})
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
#### Admin: Set Trading Flag
|
|
129
|
+
```typescript
|
|
130
|
+
await sdk.admin.setTradingFlag({
|
|
131
|
+
isEnabled: true,
|
|
132
|
+
blockchain: "orbix",
|
|
133
|
+
})
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
#### EVM: Send Transaction (Contract Call)
|
|
137
|
+
```typescript
|
|
138
|
+
import { ethers } from "ethers";
|
|
139
|
+
|
|
140
|
+
await sdk.evm.sendEvmTx({
|
|
141
|
+
to: "0x...", // contract address
|
|
142
|
+
value: ethers.utils.parseEther("0.1"),
|
|
143
|
+
data: "0x...", // encoded contract call data
|
|
144
|
+
})
|
|
84
145
|
```
|
|
85
146
|
|
|
86
|
-
|
|
147
|
+
### Return Values
|
|
148
|
+
|
|
149
|
+
Mutation methods generally return a `Promise` resolving to an object containing the transaction hash:
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
{
|
|
153
|
+
txHash: string;
|
|
154
|
+
orderId?: string;
|
|
155
|
+
orderIds?: string[];
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Module Support Summary
|
|
160
|
+
|
|
161
|
+
The SDK covers a wide range of blockchain functionalities:
|
|
162
|
+
|
|
163
|
+
- **Order**: Create, edit, cancel (single/batch)
|
|
164
|
+
- **Leverage**: Set leverage for markets
|
|
165
|
+
- **Position**: Adjust margin, query positions
|
|
166
|
+
- **Bank**: On-chain token transfers
|
|
167
|
+
- **SubAccount**: Management of sub-accounts
|
|
168
|
+
- **Staking & Alliance**: Delegation, rewards, and validator interaction
|
|
169
|
+
- **IBC & Bridge**: Cross-chain transfers and withdrawals
|
|
170
|
+
- **EVM**: Sending transactions to the EVM module
|
|
87
171
|
|
|
88
|
-
# Contributing to Carbon SDK
|
|
89
|
-
{wip}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { Network, NetworkConfig, Network as _Network } from "./constant";
|
|
2
|
+
import { Tendermint37Client } from "@cosmjs/tendermint-rpc";
|
|
3
|
+
import * as clients from "./clients";
|
|
4
|
+
import { OrbixQueryClient, HydrogenClient, InsightsQueryClient, TokenClient } from "./clients";
|
|
5
|
+
import GasFee from "./clients/GasFee";
|
|
6
|
+
import GrpcQueryClient from "./clients/GrpcQueryClient";
|
|
7
|
+
import { AdminModule, AllianceModule, BankModule, BridgeModule, BrokerModule, CoinModule, EvmMergeModule, EvmModule, FeeModule, GovModule, IBCModule, LeverageModule, MarketModule, OracleModule, OrderModule, PerpspoolModule, PositionModule, SubAccountModule } from "./modules";
|
|
8
|
+
import { GrantModule } from "./modules/grant";
|
|
9
|
+
import { StakingModule } from "./modules/staking";
|
|
10
|
+
import { CosmosLedger, Keplr, LeapExtended } from "./provider";
|
|
11
|
+
import { MetaMask } from "./provider/metamask/MetaMask";
|
|
12
|
+
import RainbowKitAccount from "./provider/rainbowKit/RainbowKitAccount";
|
|
13
|
+
import { OrbixSigner, OrbixWallet, OrbixWalletGenericOpts, EvmWalletOpts, RainbowKitWalletOpts } from "./wallet";
|
|
14
|
+
export { OrbixTx } from "./util";
|
|
15
|
+
export { OrbixSigner, OrbixSignerTypes, OrbixWallet, OrbixWalletGenericOpts, OrbixWalletInitOpts } from "./wallet";
|
|
16
|
+
export * as Orbix from "./codec/orbix-models";
|
|
17
|
+
export interface OrbixSDKOpts {
|
|
18
|
+
network: Network;
|
|
19
|
+
tmClient: Tendermint37Client;
|
|
20
|
+
wallet?: OrbixWallet;
|
|
21
|
+
chainId?: string;
|
|
22
|
+
evmChainId?: string;
|
|
23
|
+
token?: TokenClient;
|
|
24
|
+
query?: OrbixQueryClient;
|
|
25
|
+
hydrogen?: HydrogenClient;
|
|
26
|
+
insights?: InsightsQueryClient;
|
|
27
|
+
config?: Partial<NetworkConfig>;
|
|
28
|
+
grpcQueryClient?: GrpcQueryClient;
|
|
29
|
+
useTmAbciQuery?: boolean;
|
|
30
|
+
defaultTimeoutBlocks?: number;
|
|
31
|
+
gasFee?: GasFee;
|
|
32
|
+
}
|
|
33
|
+
export interface OrbixSDKInitOpts {
|
|
34
|
+
network: Network;
|
|
35
|
+
tmClient?: Tendermint37Client;
|
|
36
|
+
config?: Partial<NetworkConfig>;
|
|
37
|
+
wallet?: OrbixWallet;
|
|
38
|
+
skipInit?: boolean;
|
|
39
|
+
defaultTimeoutBlocks?: number;
|
|
40
|
+
/**
|
|
41
|
+
* temporary flag to disable GRPC Query client service when required
|
|
42
|
+
* TODO: Deprecate when grpc query client is implemented across all networks
|
|
43
|
+
*/
|
|
44
|
+
useTmAbciQuery?: boolean;
|
|
45
|
+
}
|
|
46
|
+
export interface OverrideConfig {
|
|
47
|
+
chainId: string;
|
|
48
|
+
evmChainId: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Orbix SDK
|
|
52
|
+
*
|
|
53
|
+
*
|
|
54
|
+
*/
|
|
55
|
+
declare class OrbixSDK {
|
|
56
|
+
static DEFAULT_NETWORK: Network;
|
|
57
|
+
static DenomPrefix: {
|
|
58
|
+
LPToken: string;
|
|
59
|
+
CDPToken: string;
|
|
60
|
+
PerpPoolToken: string;
|
|
61
|
+
UserVaultToken: string;
|
|
62
|
+
};
|
|
63
|
+
initialized: boolean;
|
|
64
|
+
readonly query: OrbixQueryClient;
|
|
65
|
+
readonly useTmAbciQuery: boolean;
|
|
66
|
+
insights: InsightsQueryClient;
|
|
67
|
+
hydrogen: HydrogenClient;
|
|
68
|
+
wallet?: OrbixWallet;
|
|
69
|
+
gasFee?: GasFee;
|
|
70
|
+
network: Network;
|
|
71
|
+
configOverride: Partial<NetworkConfig>;
|
|
72
|
+
networkConfig: NetworkConfig;
|
|
73
|
+
tmClient: Tendermint37Client;
|
|
74
|
+
token: TokenClient;
|
|
75
|
+
admin: AdminModule;
|
|
76
|
+
alliance: AllianceModule;
|
|
77
|
+
order: OrderModule;
|
|
78
|
+
perpspool: PerpspoolModule;
|
|
79
|
+
grant: GrantModule;
|
|
80
|
+
subaccount: SubAccountModule;
|
|
81
|
+
leverage: LeverageModule;
|
|
82
|
+
market: MarketModule;
|
|
83
|
+
broker: BrokerModule;
|
|
84
|
+
position: PositionModule;
|
|
85
|
+
coin: CoinModule;
|
|
86
|
+
oracle: OracleModule;
|
|
87
|
+
gov: GovModule;
|
|
88
|
+
staking: StakingModule;
|
|
89
|
+
bank: BankModule;
|
|
90
|
+
fee: FeeModule;
|
|
91
|
+
ibc: IBCModule;
|
|
92
|
+
evm: EvmModule;
|
|
93
|
+
evmmerge: EvmMergeModule;
|
|
94
|
+
bridge: BridgeModule;
|
|
95
|
+
chainId: string;
|
|
96
|
+
evmChainId: string;
|
|
97
|
+
constructor(opts: OrbixSDKOpts);
|
|
98
|
+
static instance(opts?: OrbixSDKInitOpts): Promise<OrbixSDK>;
|
|
99
|
+
static instanceWithWallet(wallet: OrbixWallet, sdkOpts?: OrbixSDKInitOpts): Promise<ConnectedOrbixSDK>;
|
|
100
|
+
static instanceWithPrivateKey(privateKey: string | Buffer, sdkOpts?: OrbixSDKInitOpts, walletOpts?: OrbixWalletGenericOpts): Promise<ConnectedOrbixSDK>;
|
|
101
|
+
static instanceWithMnemonic(mnemonic: string, sdkOpts?: OrbixSDKInitOpts, walletOpts?: OrbixWalletGenericOpts): Promise<ConnectedOrbixSDK>;
|
|
102
|
+
static instanceWithSigner(signer: OrbixSigner, publicKeyBase64: string, sdkOpts?: OrbixSDKInitOpts, walletOpts?: OrbixWalletGenericOpts): Promise<ConnectedOrbixSDK>;
|
|
103
|
+
static instanceWithLedger(ledger: CosmosLedger, sdkOpts?: OrbixSDKInitOpts, walletOpts?: OrbixWalletGenericOpts): Promise<ConnectedOrbixSDK>;
|
|
104
|
+
static instanceWithKeplr(keplr: Keplr, sdkOpts?: OrbixSDKInitOpts, walletOpts?: OrbixWalletGenericOpts): Promise<ConnectedOrbixSDK>;
|
|
105
|
+
static instanceWithLeap(leap: LeapExtended, sdkOpts?: OrbixSDKInitOpts, walletOpts?: OrbixWalletGenericOpts): Promise<ConnectedOrbixSDK>;
|
|
106
|
+
static instanceWithMetamask(metamask: MetaMask, sdkOpts?: OrbixSDKInitOpts, walletOpts?: OrbixWalletGenericOpts): Promise<ConnectedOrbixSDK>;
|
|
107
|
+
static instanceWithRainbowKit(rainbowKit: RainbowKitAccount, sdkOpts: OrbixSDKInitOpts | undefined, rainbowKitWalletOpts: RainbowKitWalletOpts, walletOpts?: OrbixWalletGenericOpts): Promise<ConnectedOrbixSDK>;
|
|
108
|
+
static instanceViewOnly(bech32Address: string, sdkOpts?: OrbixSDKInitOpts, walletOpts?: OrbixWalletGenericOpts): Promise<ConnectedOrbixSDK>;
|
|
109
|
+
initialize(): Promise<OrbixSDK>;
|
|
110
|
+
getGasFee(): Promise<GasFee>;
|
|
111
|
+
clone(): OrbixSDK;
|
|
112
|
+
generateOpts(): OrbixSDKOpts;
|
|
113
|
+
connect(wallet: OrbixWallet, opts?: OrbixWalletGenericOpts): Promise<ConnectedOrbixSDK>;
|
|
114
|
+
disconnect(): OrbixSDK;
|
|
115
|
+
connectWithPrivateKey(privateKey: string | Buffer, opts?: OrbixWalletGenericOpts): Promise<ConnectedOrbixSDK>;
|
|
116
|
+
connectWithMnemonic(mnemonic: string, opts?: OrbixWalletGenericOpts): Promise<ConnectedOrbixSDK>;
|
|
117
|
+
connectWithSigner(signer: OrbixSigner, publicKeyBase64: string, opts?: OrbixWalletGenericOpts): Promise<ConnectedOrbixSDK>;
|
|
118
|
+
connectWithLedger(ledger: CosmosLedger, opts?: OrbixWalletGenericOpts): Promise<ConnectedOrbixSDK>;
|
|
119
|
+
connectWithKeplr(keplr: Keplr, opts?: OrbixWalletGenericOpts): Promise<ConnectedOrbixSDK>;
|
|
120
|
+
connectWithLeap(leap: LeapExtended, opts?: OrbixWalletGenericOpts): Promise<ConnectedOrbixSDK>;
|
|
121
|
+
connectWithMetamask(metamask: MetaMask, opts?: OrbixWalletGenericOpts, evmWalletOpts?: EvmWalletOpts): Promise<ConnectedOrbixSDK>;
|
|
122
|
+
connectWithRainbowKit(rainbowKit: RainbowKitAccount, rainbowKitWalletOpts: RainbowKitWalletOpts, opts?: OrbixWalletGenericOpts): Promise<ConnectedOrbixSDK>;
|
|
123
|
+
connectViewOnly(bech32Address: string, opts?: OrbixWalletGenericOpts): Promise<ConnectedOrbixSDK>;
|
|
124
|
+
connectWithQr(granteeMnemonic: string, granterAddress: string, expiry: Date, opts?: OrbixWalletGenericOpts): Promise<ConnectedOrbixSDK>;
|
|
125
|
+
getConfig(): NetworkConfig;
|
|
126
|
+
getTokenClient(): TokenClient;
|
|
127
|
+
getConnectedWallet(): OrbixWallet;
|
|
128
|
+
log(...args: any[]): void;
|
|
129
|
+
private checkWallet;
|
|
130
|
+
static parseNetwork: (network: string, defaultNetwork?: Network | null) => Network | null;
|
|
131
|
+
}
|
|
132
|
+
export declare class ConnectedOrbixSDK extends OrbixSDK {
|
|
133
|
+
wallet: OrbixWallet;
|
|
134
|
+
constructor(wallet: OrbixWallet, opts: OrbixSDKOpts);
|
|
135
|
+
clone(): ConnectedOrbixSDK;
|
|
136
|
+
}
|
|
137
|
+
declare namespace OrbixSDK {
|
|
138
|
+
export import Network = _Network;
|
|
139
|
+
export import OrbixQueryClient = clients.OrbixQueryClient;
|
|
140
|
+
export import ETHClient = clients.ETHClient;
|
|
141
|
+
export import HydrogenClient = clients.HydrogenClient;
|
|
142
|
+
export import InsightsQueryClient = clients.InsightsQueryClient;
|
|
143
|
+
export import TokenClient = clients.TokenClient;
|
|
144
|
+
}
|
|
145
|
+
export default OrbixSDK;
|
|
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.
|
|
39
|
+
exports.ConnectedOrbixSDK = exports.Orbix = exports.OrbixWallet = exports.OrbixSignerTypes = exports.OrbixTx = void 0;
|
|
40
40
|
const constant_1 = require("./constant");
|
|
41
41
|
const util_1 = require("./util");
|
|
42
42
|
const tendermint_rpc_1 = require("@cosmjs/tendermint-rpc");
|
|
@@ -55,20 +55,20 @@ const number_1 = require("./util/number");
|
|
|
55
55
|
const wallet_1 = require("./wallet");
|
|
56
56
|
const auth_1 = require("./util/auth");
|
|
57
57
|
var util_2 = require("./util");
|
|
58
|
-
Object.defineProperty(exports, "
|
|
58
|
+
Object.defineProperty(exports, "OrbixTx", { enumerable: true, get: function () { return util_2.OrbixTx; } });
|
|
59
59
|
var wallet_2 = require("./wallet");
|
|
60
|
-
Object.defineProperty(exports, "
|
|
61
|
-
Object.defineProperty(exports, "
|
|
62
|
-
exports.
|
|
60
|
+
Object.defineProperty(exports, "OrbixSignerTypes", { enumerable: true, get: function () { return wallet_2.OrbixSignerTypes; } });
|
|
61
|
+
Object.defineProperty(exports, "OrbixWallet", { enumerable: true, get: function () { return wallet_2.OrbixWallet; } });
|
|
62
|
+
exports.Orbix = __importStar(require("./codec/orbix-models"));
|
|
63
63
|
const DEFAULT_SDK_INIT_OPTS = {
|
|
64
64
|
network: constant_1.DEFAULT_NETWORK,
|
|
65
65
|
};
|
|
66
66
|
/**
|
|
67
|
-
*
|
|
67
|
+
* Orbix SDK
|
|
68
68
|
*
|
|
69
69
|
*
|
|
70
70
|
*/
|
|
71
|
-
class
|
|
71
|
+
class OrbixSDK {
|
|
72
72
|
constructor(opts) {
|
|
73
73
|
this.initialized = false;
|
|
74
74
|
this.network = opts.network ?? constant_1.DEFAULT_NETWORK;
|
|
@@ -78,9 +78,9 @@ class CarbonSDK {
|
|
|
78
78
|
this.gasFee = opts.gasFee;
|
|
79
79
|
this.tmClient = opts.tmClient;
|
|
80
80
|
this.wallet = opts.wallet;
|
|
81
|
-
this.chainId = opts.chainId ?? constant_1.
|
|
82
|
-
this.evmChainId = opts.evmChainId ?? constant_1.
|
|
83
|
-
let
|
|
81
|
+
this.chainId = opts.chainId ?? constant_1.OrbixChainIDs[this.network] ?? constant_1.OrbixChainIDs[constant_1.Network.MainNet];
|
|
82
|
+
this.evmChainId = opts.evmChainId ?? constant_1.OrbixEvmChainIDs[this.network] ?? constant_1.OrbixEvmChainIDs[constant_1.Network.MainNet];
|
|
83
|
+
let orbixQueryClient;
|
|
84
84
|
if (!opts.query) {
|
|
85
85
|
let grpcClient;
|
|
86
86
|
if (opts.useTmAbciQuery !== true && this.networkConfig.grpcUrl) {
|
|
@@ -91,12 +91,12 @@ class CarbonSDK {
|
|
|
91
91
|
transport,
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
|
-
|
|
94
|
+
orbixQueryClient = new clients_1.OrbixQueryClient({
|
|
95
95
|
tmClient: this.tmClient,
|
|
96
96
|
grpcClient,
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
|
-
this.query = (opts.query ??
|
|
99
|
+
this.query = (opts.query ?? orbixQueryClient);
|
|
100
100
|
this.insights = opts.insights ?? new clients_1.InsightsQueryClient(this.networkConfig);
|
|
101
101
|
this.token = opts.token ?? clients_1.TokenClient.instance(this.query, this);
|
|
102
102
|
this.hydrogen = opts.hydrogen ?? new clients_1.HydrogenClient(this.networkConfig, this.token);
|
|
@@ -137,7 +137,7 @@ class CarbonSDK {
|
|
|
137
137
|
console.error(error);
|
|
138
138
|
normalInit = false;
|
|
139
139
|
}
|
|
140
|
-
const sdk = new
|
|
140
|
+
const sdk = new OrbixSDK({
|
|
141
141
|
network,
|
|
142
142
|
config: configOverride,
|
|
143
143
|
tmClient,
|
|
@@ -157,43 +157,43 @@ class CarbonSDK {
|
|
|
157
157
|
return sdk;
|
|
158
158
|
}
|
|
159
159
|
static async instanceWithWallet(wallet, sdkOpts = DEFAULT_SDK_INIT_OPTS) {
|
|
160
|
-
const sdk = await
|
|
160
|
+
const sdk = await OrbixSDK.instance(sdkOpts);
|
|
161
161
|
return sdk.connect(wallet);
|
|
162
162
|
}
|
|
163
163
|
static async instanceWithPrivateKey(privateKey, sdkOpts = DEFAULT_SDK_INIT_OPTS, walletOpts) {
|
|
164
|
-
const sdk = await
|
|
164
|
+
const sdk = await OrbixSDK.instance(sdkOpts);
|
|
165
165
|
return sdk.connectWithPrivateKey(privateKey, walletOpts);
|
|
166
166
|
}
|
|
167
167
|
static async instanceWithMnemonic(mnemonic, sdkOpts = DEFAULT_SDK_INIT_OPTS, walletOpts) {
|
|
168
|
-
const sdk = await
|
|
168
|
+
const sdk = await OrbixSDK.instance(sdkOpts);
|
|
169
169
|
return sdk.connectWithMnemonic(mnemonic, walletOpts);
|
|
170
170
|
}
|
|
171
171
|
static async instanceWithSigner(signer, publicKeyBase64, sdkOpts = DEFAULT_SDK_INIT_OPTS, walletOpts) {
|
|
172
|
-
const sdk = await
|
|
172
|
+
const sdk = await OrbixSDK.instance(sdkOpts);
|
|
173
173
|
return sdk.connectWithSigner(signer, publicKeyBase64, walletOpts);
|
|
174
174
|
}
|
|
175
175
|
static async instanceWithLedger(ledger, sdkOpts = DEFAULT_SDK_INIT_OPTS, walletOpts) {
|
|
176
|
-
const sdk = await
|
|
176
|
+
const sdk = await OrbixSDK.instance(sdkOpts);
|
|
177
177
|
return sdk.connectWithLedger(ledger, walletOpts);
|
|
178
178
|
}
|
|
179
179
|
static async instanceWithKeplr(keplr, sdkOpts = DEFAULT_SDK_INIT_OPTS, walletOpts) {
|
|
180
|
-
const sdk = await
|
|
180
|
+
const sdk = await OrbixSDK.instance(sdkOpts);
|
|
181
181
|
return sdk.connectWithKeplr(keplr, walletOpts);
|
|
182
182
|
}
|
|
183
183
|
static async instanceWithLeap(leap, sdkOpts = DEFAULT_SDK_INIT_OPTS, walletOpts) {
|
|
184
|
-
const sdk = await
|
|
184
|
+
const sdk = await OrbixSDK.instance(sdkOpts);
|
|
185
185
|
return sdk.connectWithLeap(leap, walletOpts);
|
|
186
186
|
}
|
|
187
187
|
static async instanceWithMetamask(metamask, sdkOpts = DEFAULT_SDK_INIT_OPTS, walletOpts) {
|
|
188
|
-
const sdk = await
|
|
188
|
+
const sdk = await OrbixSDK.instance(sdkOpts);
|
|
189
189
|
return sdk.connectWithMetamask(metamask, walletOpts);
|
|
190
190
|
}
|
|
191
191
|
static async instanceWithRainbowKit(rainbowKit, sdkOpts = DEFAULT_SDK_INIT_OPTS, rainbowKitWalletOpts, walletOpts) {
|
|
192
|
-
const sdk = await
|
|
192
|
+
const sdk = await OrbixSDK.instance(sdkOpts);
|
|
193
193
|
return sdk.connectWithRainbowKit(rainbowKit, rainbowKitWalletOpts, walletOpts);
|
|
194
194
|
}
|
|
195
195
|
static async instanceViewOnly(bech32Address, sdkOpts = DEFAULT_SDK_INIT_OPTS, walletOpts) {
|
|
196
|
-
const sdk = await
|
|
196
|
+
const sdk = await OrbixSDK.instance(sdkOpts);
|
|
197
197
|
return sdk.connectViewOnly(bech32Address, walletOpts);
|
|
198
198
|
}
|
|
199
199
|
async initialize() {
|
|
@@ -229,7 +229,7 @@ class CarbonSDK {
|
|
|
229
229
|
return new GasFee_1.default(txGasCosts, txGasPrices);
|
|
230
230
|
}
|
|
231
231
|
clone() {
|
|
232
|
-
return new
|
|
232
|
+
return new OrbixSDK(this.generateOpts());
|
|
233
233
|
}
|
|
234
234
|
generateOpts() {
|
|
235
235
|
return {
|
|
@@ -271,15 +271,15 @@ class CarbonSDK {
|
|
|
271
271
|
return this;
|
|
272
272
|
}
|
|
273
273
|
disconnect() {
|
|
274
|
-
if (this.wallet?.isSigner(wallet_1.
|
|
274
|
+
if (this.wallet?.isSigner(wallet_1.OrbixSignerTypes.Ledger)) {
|
|
275
275
|
this.wallet.signer.ledger.disconnect();
|
|
276
276
|
}
|
|
277
277
|
const opts = this.generateOpts();
|
|
278
278
|
delete opts.wallet;
|
|
279
|
-
return new
|
|
279
|
+
return new OrbixSDK(opts);
|
|
280
280
|
}
|
|
281
281
|
async connectWithPrivateKey(privateKey, opts) {
|
|
282
|
-
const wallet = new wallet_1.
|
|
282
|
+
const wallet = new wallet_1.OrbixWallet({
|
|
283
283
|
...opts,
|
|
284
284
|
mode: "privateKey",
|
|
285
285
|
privateKey,
|
|
@@ -289,7 +289,7 @@ class CarbonSDK {
|
|
|
289
289
|
return this.connect(wallet, opts);
|
|
290
290
|
}
|
|
291
291
|
async connectWithMnemonic(mnemonic, opts) {
|
|
292
|
-
const wallet = new wallet_1.
|
|
292
|
+
const wallet = new wallet_1.OrbixWallet({
|
|
293
293
|
...opts,
|
|
294
294
|
mode: "mnemonic",
|
|
295
295
|
mnemonic,
|
|
@@ -299,7 +299,7 @@ class CarbonSDK {
|
|
|
299
299
|
return this.connect(wallet, opts);
|
|
300
300
|
}
|
|
301
301
|
async connectWithSigner(signer, publicKeyBase64, opts) {
|
|
302
|
-
const wallet = new wallet_1.
|
|
302
|
+
const wallet = new wallet_1.OrbixWallet({
|
|
303
303
|
...opts,
|
|
304
304
|
mode: "customSigner",
|
|
305
305
|
signer,
|
|
@@ -312,8 +312,8 @@ class CarbonSDK {
|
|
|
312
312
|
async connectWithLedger(ledger, opts) {
|
|
313
313
|
const publicKeyBuffer = await ledger.getPubKey();
|
|
314
314
|
const publicKeyBase64 = publicKeyBuffer.toString("base64");
|
|
315
|
-
const signer = new wallet_1.
|
|
316
|
-
const wallet = new wallet_1.
|
|
315
|
+
const signer = new wallet_1.OrbixLedgerSigner(ledger);
|
|
316
|
+
const wallet = new wallet_1.OrbixWallet({
|
|
317
317
|
...opts,
|
|
318
318
|
mode: "customSigner",
|
|
319
319
|
signer,
|
|
@@ -333,7 +333,7 @@ class CarbonSDK {
|
|
|
333
333
|
? provider_1.KeplrAccount.createKeplrSignerAmino(keplr, chainInfo, keplrKey)
|
|
334
334
|
: provider_1.KeplrAccount.createKeplrSigner(keplr, chainInfo, keplrKey);
|
|
335
335
|
const publicKeyBase64 = Buffer.from(keplrKey.pubKey).toString("base64");
|
|
336
|
-
const wallet = new wallet_1.
|
|
336
|
+
const wallet = new wallet_1.OrbixWallet({
|
|
337
337
|
...opts,
|
|
338
338
|
mode: "customSigner",
|
|
339
339
|
signer,
|
|
@@ -352,7 +352,7 @@ class CarbonSDK {
|
|
|
352
352
|
await leap.enable(chainId);
|
|
353
353
|
const signer = leapKey.isNanoLedger ? provider_1.LeapAccount.createLeapSignerAmino(leap, chainId) : provider_1.LeapAccount.createLeapSigner(leap, chainId);
|
|
354
354
|
const publicKeyBase64 = Buffer.from(leapKey.pubKey).toString("base64");
|
|
355
|
-
const wallet = new wallet_1.
|
|
355
|
+
const wallet = new wallet_1.OrbixWallet({
|
|
356
356
|
...opts,
|
|
357
357
|
mode: "customSigner",
|
|
358
358
|
signer,
|
|
@@ -381,7 +381,7 @@ class CarbonSDK {
|
|
|
381
381
|
signature = result.signature;
|
|
382
382
|
}
|
|
383
383
|
const signer = MetaMask_1.MetaMask.createMetamaskSigner(metamask, evmChainId, pubKey, addressOptions);
|
|
384
|
-
const wallet = new wallet_1.
|
|
384
|
+
const wallet = new wallet_1.OrbixWallet({
|
|
385
385
|
...opts,
|
|
386
386
|
mode: "customSigner",
|
|
387
387
|
signer,
|
|
@@ -419,7 +419,7 @@ class CarbonSDK {
|
|
|
419
419
|
signature = result.signature;
|
|
420
420
|
}
|
|
421
421
|
const signer = RainbowKitAccount_1.default.createRainbowKitSigner(rainbowKit, evmChainId, pubKey, addressOptions);
|
|
422
|
-
const wallet = new wallet_1.
|
|
422
|
+
const wallet = new wallet_1.OrbixWallet({
|
|
423
423
|
...opts,
|
|
424
424
|
mode: "customSigner",
|
|
425
425
|
signer,
|
|
@@ -441,7 +441,7 @@ class CarbonSDK {
|
|
|
441
441
|
return this.connect(wallet, opts);
|
|
442
442
|
}
|
|
443
443
|
async connectViewOnly(bech32Address, opts) {
|
|
444
|
-
const wallet = new wallet_1.
|
|
444
|
+
const wallet = new wallet_1.OrbixWallet({
|
|
445
445
|
...opts,
|
|
446
446
|
mode: "viewOnly",
|
|
447
447
|
bech32Address,
|
|
@@ -451,7 +451,7 @@ class CarbonSDK {
|
|
|
451
451
|
return this.connect(wallet, opts);
|
|
452
452
|
}
|
|
453
453
|
async connectWithQr(granteeMnemonic, granterAddress, expiry, opts) {
|
|
454
|
-
const wallet = new wallet_1.
|
|
454
|
+
const wallet = new wallet_1.OrbixWallet({
|
|
455
455
|
...opts,
|
|
456
456
|
mode: "qr",
|
|
457
457
|
mnemonic: granteeMnemonic,
|
|
@@ -482,25 +482,25 @@ class CarbonSDK {
|
|
|
482
482
|
return this.wallet;
|
|
483
483
|
}
|
|
484
484
|
}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
class
|
|
485
|
+
OrbixSDK.DEFAULT_NETWORK = constant_1.DEFAULT_NETWORK;
|
|
486
|
+
OrbixSDK.DenomPrefix = constant_1.DenomPrefix;
|
|
487
|
+
OrbixSDK.parseNetwork = util_1.NetworkUtils.parseNetwork;
|
|
488
|
+
class ConnectedOrbixSDK extends OrbixSDK {
|
|
489
489
|
constructor(wallet, opts) {
|
|
490
490
|
super(opts);
|
|
491
491
|
this.wallet = wallet;
|
|
492
492
|
}
|
|
493
493
|
clone() {
|
|
494
|
-
return new
|
|
494
|
+
return new ConnectedOrbixSDK(this.wallet, this.generateOpts());
|
|
495
495
|
}
|
|
496
496
|
}
|
|
497
|
-
exports.
|
|
498
|
-
(function (
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
})(
|
|
506
|
-
exports.default =
|
|
497
|
+
exports.ConnectedOrbixSDK = ConnectedOrbixSDK;
|
|
498
|
+
(function (OrbixSDK) {
|
|
499
|
+
OrbixSDK.Network = constant_1.Network;
|
|
500
|
+
OrbixSDK.OrbixQueryClient = clients.OrbixQueryClient;
|
|
501
|
+
OrbixSDK.ETHClient = clients.ETHClient;
|
|
502
|
+
OrbixSDK.HydrogenClient = clients.HydrogenClient;
|
|
503
|
+
OrbixSDK.InsightsQueryClient = clients.InsightsQueryClient;
|
|
504
|
+
OrbixSDK.TokenClient = clients.TokenClient;
|
|
505
|
+
})(OrbixSDK || (OrbixSDK = {}));
|
|
506
|
+
exports.default = OrbixSDK;
|