@mictonode/widget 0.3.16 → 0.3.18
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/.github/FUNDING.yml +3 -3
- package/.github/workflows/npm-publish.yml +34 -34
- package/.prettierrc.json +9 -9
- package/.vscode/extensions.json +3 -3
- package/LICENSE +674 -674
- package/README.md +41 -41
- package/dist/{main-d0e5d1e4.js → main-bbea3e54.js} +155 -153
- package/dist/ping-widget.js +2 -2
- package/dist/ping-widget.umd.cjs +18 -18
- package/dist/{query.lcd-3d4d3495.js → query.lcd-88036522.js} +1 -1
- package/dist/{query.rpc.Query-b7807c29.js → query.rpc.Query-3a2b14f8.js} +1 -1
- package/dist/{tx.rpc.msg-59c3408a.js → tx.rpc.msg-39f0b824.js} +1 -1
- package/example/.vscode/extensions.json +3 -3
- package/example/README.md +7 -7
- package/example/index.html +12 -12
- package/example/package.json +19 -19
- package/example/pnpm-lock.yaml +465 -465
- package/example/public/cdn.html +19 -19
- package/example/src/App.vue +73 -73
- package/example/src/main.js +4 -4
- package/example/vite.config.js +7 -7
- package/index.html +12 -12
- package/lib/components/ConnectWallet/index.vue +262 -262
- package/lib/components/TokenConvert/index.vue +1033 -1033
- package/lib/components/TokenConvert/tokens.ts +36 -36
- package/lib/components/TxDialog/index.vue +422 -422
- package/lib/components/TxDialog/messages/Delegate.vue +174 -174
- package/lib/components/TxDialog/messages/Deposit.vue +96 -96
- package/lib/components/TxDialog/messages/Redelegate.vue +160 -160
- package/lib/components/TxDialog/messages/Send.vue +142 -142
- package/lib/components/TxDialog/messages/Transfer.vue +248 -248
- package/lib/components/TxDialog/messages/Unbond.vue +103 -103
- package/lib/components/TxDialog/messages/Vote.vue +62 -62
- package/lib/components/TxDialog/messages/Withdraw.vue +55 -55
- package/lib/components/TxDialog/messages/WithdrawCommission.vue +74 -74
- package/lib/components/TxDialog/wasm/ClearAdmin.vue +55 -55
- package/lib/components/TxDialog/wasm/ExecuteContract.vue +98 -98
- package/lib/components/TxDialog/wasm/InstantiateContract.vue +108 -108
- package/lib/components/TxDialog/wasm/MigrateContract.vue +76 -76
- package/lib/components/TxDialog/wasm/MigrateContract2.vue +76 -76
- package/lib/components/TxDialog/wasm/StoreCode.vue +100 -100
- package/lib/components/TxDialog/wasm/UpdateAdmin.vue +74 -74
- package/lib/main.css +591 -7
- package/lib/main.ts +24 -23
- package/lib/utils/TokenUnitConverter.ts +44 -44
- package/lib/utils/format.ts +16 -16
- package/lib/utils/http.ts +154 -154
- package/lib/utils/type.ts +56 -56
- package/lib/wallet/EthermintMessageAdapter.ts +135 -135
- package/lib/wallet/UniClient.ts +144 -144
- package/lib/wallet/Wallet.ts +142 -142
- package/lib/wallet/wallets/KeplerWallet.ts +141 -141
- package/lib/wallet/wallets/LeapWallet.ts +141 -141
- package/lib/wallet/wallets/LedgerWallet.ts +202 -202
- package/lib/wallet/wallets/MetamaskSnapWallet.ts +105 -105
- package/lib/wallet/wallets/MetamaskWallet.ts +173 -173
- package/lib/wallet/wallets/OKXWallet.ts +202 -202
- package/lib/wallet/wallets/UnisatWallet.ts +198 -198
- package/package.json +5 -6
- package/postcss.config.js +6 -6
- package/src/App.vue +225 -225
- package/src/main.ts +7 -4
- package/src/styles/design-system.css +184 -0
- package/src/vite-env.d.ts +1 -1
- package/tailwind.config.js +158 -34
- package/tsconfig.json +25 -25
- package/tsconfig.node.json +10 -10
- package/vite.config.ts +62 -62
- package/vue-shim.d.ts +6 -6
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import { Coin, CoinMetadata } from "./type";
|
|
2
|
-
import BigNumber from 'bignumber.js';
|
|
3
|
-
|
|
4
|
-
export class TokenUnitConverter {
|
|
5
|
-
metadata: Record<string, CoinMetadata>
|
|
6
|
-
constructor(metas?: Record<string, CoinMetadata> ) {
|
|
7
|
-
this.metadata = metas? metas: {}
|
|
8
|
-
}
|
|
9
|
-
addMetadata(denom: string, meta: CoinMetadata) {
|
|
10
|
-
this.metadata[denom] = meta
|
|
11
|
-
}
|
|
12
|
-
baseToDisplay(token: Coin, decimal = 6) {
|
|
13
|
-
const meta = this.metadata[token.denom]
|
|
14
|
-
if(!meta) return token
|
|
15
|
-
const unit = meta.denom_units.find(unit => unit.denom === meta.display)
|
|
16
|
-
if(!unit) return token
|
|
17
|
-
const amount = BigNumber(Number(token.amount)).div(BigNumber(10).pow(unit.exponent))
|
|
18
|
-
return {
|
|
19
|
-
amount: amount.toFixed(decimal),
|
|
20
|
-
denom: unit.denom.toUpperCase()
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
baseToUnit(token: Coin, unitName: string, decimal = 6) {
|
|
24
|
-
const meta = this.metadata[token.denom]
|
|
25
|
-
if(!meta) return token
|
|
26
|
-
const unit = meta.denom_units.find(unit => unit.denom === unitName)
|
|
27
|
-
if(!unit) return token
|
|
28
|
-
const amount = BigNumber(Number(token.amount)).div(BigNumber(10).pow(unit.exponent))
|
|
29
|
-
return {
|
|
30
|
-
amount: parseFloat(amount.toFixed(decimal)).toString(),
|
|
31
|
-
denom: unit.denom
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
displayToBase(baseDenom: string, display: Coin) {
|
|
35
|
-
const meta = this.metadata[baseDenom]
|
|
36
|
-
if(!meta) return display
|
|
37
|
-
const unit = meta.denom_units.find(unit => unit.denom === display.denom)
|
|
38
|
-
if(!unit) return display
|
|
39
|
-
const amount = BigNumber(Number(display.amount)).times(BigNumber(10).pow(unit.exponent))
|
|
40
|
-
return {
|
|
41
|
-
amount: amount.toFixed(),
|
|
42
|
-
denom: baseDenom
|
|
43
|
-
}
|
|
44
|
-
}
|
|
1
|
+
import { Coin, CoinMetadata } from "./type";
|
|
2
|
+
import BigNumber from 'bignumber.js';
|
|
3
|
+
|
|
4
|
+
export class TokenUnitConverter {
|
|
5
|
+
metadata: Record<string, CoinMetadata>
|
|
6
|
+
constructor(metas?: Record<string, CoinMetadata> ) {
|
|
7
|
+
this.metadata = metas? metas: {}
|
|
8
|
+
}
|
|
9
|
+
addMetadata(denom: string, meta: CoinMetadata) {
|
|
10
|
+
this.metadata[denom] = meta
|
|
11
|
+
}
|
|
12
|
+
baseToDisplay(token: Coin, decimal = 6) {
|
|
13
|
+
const meta = this.metadata[token.denom]
|
|
14
|
+
if(!meta) return token
|
|
15
|
+
const unit = meta.denom_units.find(unit => unit.denom === meta.display)
|
|
16
|
+
if(!unit) return token
|
|
17
|
+
const amount = BigNumber(Number(token.amount)).div(BigNumber(10).pow(unit.exponent))
|
|
18
|
+
return {
|
|
19
|
+
amount: amount.toFixed(decimal),
|
|
20
|
+
denom: unit.denom.toUpperCase()
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
baseToUnit(token: Coin, unitName: string, decimal = 6) {
|
|
24
|
+
const meta = this.metadata[token.denom]
|
|
25
|
+
if(!meta) return token
|
|
26
|
+
const unit = meta.denom_units.find(unit => unit.denom === unitName)
|
|
27
|
+
if(!unit) return token
|
|
28
|
+
const amount = BigNumber(Number(token.amount)).div(BigNumber(10).pow(unit.exponent))
|
|
29
|
+
return {
|
|
30
|
+
amount: parseFloat(amount.toFixed(decimal)).toString(),
|
|
31
|
+
denom: unit.denom
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
displayToBase(baseDenom: string, display: Coin) {
|
|
35
|
+
const meta = this.metadata[baseDenom]
|
|
36
|
+
if(!meta) return display
|
|
37
|
+
const unit = meta.denom_units.find(unit => unit.denom === display.denom)
|
|
38
|
+
if(!unit) return display
|
|
39
|
+
const amount = BigNumber(Number(display.amount)).times(BigNumber(10).pow(unit.exponent))
|
|
40
|
+
return {
|
|
41
|
+
amount: amount.toFixed(),
|
|
42
|
+
denom: baseDenom
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
45
|
}
|
package/lib/utils/format.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { fromBech32, toBech32, fromHex, toHex } from '@cosmjs/encoding'
|
|
2
|
-
|
|
3
|
-
export const ethToEthermint = (ethAddress: string, prefix: string) => {
|
|
4
|
-
const data = fromHex(ethAddress.replace("0x", ""))
|
|
5
|
-
return toBech32(prefix, data)
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const ethermintToEth = (ethermintAddress: string) => {
|
|
9
|
-
const { data } = fromBech32(ethermintAddress)
|
|
10
|
-
return `0x${toHex(data)}`
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function decimal2percent(v?: string) {
|
|
14
|
-
return v ? parseFloat((Number(v) * 100).toFixed(2)) : ''
|
|
15
|
-
}
|
|
16
|
-
|
|
1
|
+
import { fromBech32, toBech32, fromHex, toHex } from '@cosmjs/encoding'
|
|
2
|
+
|
|
3
|
+
export const ethToEthermint = (ethAddress: string, prefix: string) => {
|
|
4
|
+
const data = fromHex(ethAddress.replace("0x", ""))
|
|
5
|
+
return toBech32(prefix, data)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const ethermintToEth = (ethermintAddress: string) => {
|
|
9
|
+
const { data } = fromBech32(ethermintAddress)
|
|
10
|
+
return `0x${toHex(data)}`
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function decimal2percent(v?: string) {
|
|
14
|
+
return v ? parseFloat((Number(v) * 100).toFixed(2)) : ''
|
|
15
|
+
}
|
|
16
|
+
|
package/lib/utils/http.ts
CHANGED
|
@@ -1,155 +1,155 @@
|
|
|
1
|
-
import fetch from 'cross-fetch'
|
|
2
|
-
import { Coin, CoinMetadata, TxResponse } from './type'
|
|
3
|
-
|
|
4
|
-
export async function get(url: string) {
|
|
5
|
-
return (await fetch(url)).json()
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export async function post(url: string, data: any) {
|
|
9
|
-
const response = await fetch(url, {
|
|
10
|
-
method: 'POST', // *GET, POST, PUT, DELETE, etc.
|
|
11
|
-
// mode: 'cors', // no-cors, *cors, same-origin
|
|
12
|
-
// credentials: 'same-origin', // redirect: 'follow', // manual, *follow, error
|
|
13
|
-
// referrerPolicy: 'origin', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
|
|
14
|
-
headers: {
|
|
15
|
-
'Content-Type': 'text/plain',
|
|
16
|
-
Accept: '*/*',
|
|
17
|
-
// 'Accept-Encoding': 'gzip, deflate, br',
|
|
18
|
-
},
|
|
19
|
-
body: JSON.stringify(data), // body data type must match "Content-Type" header
|
|
20
|
-
})
|
|
21
|
-
// const response = axios.post((config ? config.api : this.config.api) + url, data)
|
|
22
|
-
return response.json() // parses JSON response into native JavaScript objects
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function findField(obj: any, name: string) {
|
|
26
|
-
|
|
27
|
-
if(!obj) return undefined
|
|
28
|
-
|
|
29
|
-
const list = Object.keys(obj).filter(x => x && !x.startsWith("@"))
|
|
30
|
-
if(list.includes(name)) {
|
|
31
|
-
return obj[name]
|
|
32
|
-
}
|
|
33
|
-
for(let i = 0; i < list.length; i++) {
|
|
34
|
-
const field = obj[list[i]]
|
|
35
|
-
if(typeof field === 'string') continue
|
|
36
|
-
if(Array.isArray(field)) continue
|
|
37
|
-
|
|
38
|
-
const sub = findField(field, name)
|
|
39
|
-
if(sub) return sub
|
|
40
|
-
}
|
|
41
|
-
return undefined
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// /cosmos/base/tendermint/v1beta1/blocks/latest
|
|
45
|
-
export async function getLatestBlock(endpoint: string) {
|
|
46
|
-
const url = `${endpoint}/cosmos/base/tendermint/v1beta1/blocks/latest`
|
|
47
|
-
return get(url)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export async function getAccount(endpoint: string, address: string) {
|
|
51
|
-
const url = `${endpoint}/cosmos/auth/v1beta1/accounts/${address}`
|
|
52
|
-
try{
|
|
53
|
-
const res = await get(url)
|
|
54
|
-
return {
|
|
55
|
-
account: {
|
|
56
|
-
account_number: findField(res, "account_number"),
|
|
57
|
-
sequence: findField(res, "sequence")
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}catch(err) {
|
|
61
|
-
throw new Error(err)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export async function getBalance(endpoint: string, address: string): Promise<{balances: Coin[]}> {
|
|
67
|
-
const url = `${endpoint}/cosmos/bank/v1beta1/balances/${address}`
|
|
68
|
-
return get(url)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export async function getBalanceMetadata(endpoint: string, denom: string): Promise<{metadata: CoinMetadata }> {
|
|
72
|
-
const url = `${endpoint}/cosmos/bank/v1beta1/denoms_metadata/${denom}`
|
|
73
|
-
return get(url)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export async function getIBCDenomMetadata(denom: string): Promise<CoinMetadata> {
|
|
77
|
-
const url = `https://metadata.ping.pub/metadata/${denom.replace("ibc/", "")}`
|
|
78
|
-
return get(url)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export async function getCoinMetadata(endpoint: string, denom: string) {
|
|
82
|
-
const url = `${endpoint}/cosmos/bank/v1beta1/denoms_metadata/${denom}`
|
|
83
|
-
return get(url)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export async function getDelegateRewards(endpoint: string, address: string) {
|
|
87
|
-
const url = `${endpoint}/cosmos/distribution/v1beta1/delegators/${address}/rewards`
|
|
88
|
-
return get(url)
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export async function getDelegations(endpoint: string, validator_addr: string, address: string) : Promise< {
|
|
92
|
-
delegation_response: {
|
|
93
|
-
balance: Coin,
|
|
94
|
-
delegation: {
|
|
95
|
-
delegator_address: string,
|
|
96
|
-
shares: string,
|
|
97
|
-
validator_address: string
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}> {
|
|
101
|
-
const url = `${endpoint}/cosmos/staking/v1beta1/validators/${validator_addr}/delegations/${address}`
|
|
102
|
-
return get(url)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export async function getActiveValidators(endpoint: string) {
|
|
106
|
-
const url = `${endpoint}/cosmos/staking/v1beta1/validators?pagination.limit=300&status=BOND_STATUS_BONDED`
|
|
107
|
-
return get(url)
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export async function getInactiveValidators(endpoint: string) {
|
|
111
|
-
const url = `${endpoint}/cosmos/staking/v1beta1/validators?pagination.limit=300&status=BOND_STATUS_UNBONDED`
|
|
112
|
-
return get(url)
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// /ibc/apps/transfer/v1/denom_traces/{hash}
|
|
116
|
-
export async function getDenomTraces(endpoint: string, hash: string) : Promise<{
|
|
117
|
-
denom_trace: {
|
|
118
|
-
path: string;
|
|
119
|
-
base_denom: string;
|
|
120
|
-
};
|
|
121
|
-
}> {
|
|
122
|
-
const url = `${endpoint}/ibc/apps/transfer/v1/denom_traces/${hash}`
|
|
123
|
-
return get(url)
|
|
124
|
-
}
|
|
125
|
-
// /cosmos/tx/v1beta1/txs/{hash}
|
|
126
|
-
export async function getTxByHash(endpoint: string, hash: string) : Promise<{
|
|
127
|
-
tx_response: TxResponse;
|
|
128
|
-
}> {
|
|
129
|
-
const url = `${endpoint}/cosmos/tx/v1beta1/txs/${hash}`
|
|
130
|
-
return get(url)
|
|
131
|
-
}
|
|
132
|
-
// /cosmos/staking/v1beta1/params
|
|
133
|
-
export async function getStakingParam(endpoint: string) : Promise<{
|
|
134
|
-
params: {
|
|
135
|
-
unbonding_time: string;
|
|
136
|
-
max_validators: number;
|
|
137
|
-
max_entries: number;
|
|
138
|
-
historical_entries: number;
|
|
139
|
-
bond_denom: string;
|
|
140
|
-
};
|
|
141
|
-
}> {
|
|
142
|
-
const url = `${endpoint}/cosmos/staking/v1beta1/params`
|
|
143
|
-
return get(url)
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export async function getOsmosisPools(endpoint: string) {
|
|
147
|
-
const url = `${endpoint}/osmosis/gamm/v1beta1/pools?pagination.limit=1000`
|
|
148
|
-
return get(url)
|
|
149
|
-
}
|
|
150
|
-
// https://lcd.osmosis.zone
|
|
151
|
-
// /osmosis/gamm/v1beta1/{pool_id}/estimate/swap_exact_amount_in
|
|
152
|
-
export async function estimateSwapAmountIn(endpoint: string, poolId: string, token: Coin) {
|
|
153
|
-
const url = `${endpoint}/osmosis/gamm/v1beta1/${poolId}/estimate/swap_exact_amount_in?token_in=${token.amount}${token.denom}`
|
|
154
|
-
return get(url)
|
|
1
|
+
import fetch from 'cross-fetch'
|
|
2
|
+
import { Coin, CoinMetadata, TxResponse } from './type'
|
|
3
|
+
|
|
4
|
+
export async function get(url: string) {
|
|
5
|
+
return (await fetch(url)).json()
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export async function post(url: string, data: any) {
|
|
9
|
+
const response = await fetch(url, {
|
|
10
|
+
method: 'POST', // *GET, POST, PUT, DELETE, etc.
|
|
11
|
+
// mode: 'cors', // no-cors, *cors, same-origin
|
|
12
|
+
// credentials: 'same-origin', // redirect: 'follow', // manual, *follow, error
|
|
13
|
+
// referrerPolicy: 'origin', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
|
|
14
|
+
headers: {
|
|
15
|
+
'Content-Type': 'text/plain',
|
|
16
|
+
Accept: '*/*',
|
|
17
|
+
// 'Accept-Encoding': 'gzip, deflate, br',
|
|
18
|
+
},
|
|
19
|
+
body: JSON.stringify(data), // body data type must match "Content-Type" header
|
|
20
|
+
})
|
|
21
|
+
// const response = axios.post((config ? config.api : this.config.api) + url, data)
|
|
22
|
+
return response.json() // parses JSON response into native JavaScript objects
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function findField(obj: any, name: string) {
|
|
26
|
+
|
|
27
|
+
if(!obj) return undefined
|
|
28
|
+
|
|
29
|
+
const list = Object.keys(obj).filter(x => x && !x.startsWith("@"))
|
|
30
|
+
if(list.includes(name)) {
|
|
31
|
+
return obj[name]
|
|
32
|
+
}
|
|
33
|
+
for(let i = 0; i < list.length; i++) {
|
|
34
|
+
const field = obj[list[i]]
|
|
35
|
+
if(typeof field === 'string') continue
|
|
36
|
+
if(Array.isArray(field)) continue
|
|
37
|
+
|
|
38
|
+
const sub = findField(field, name)
|
|
39
|
+
if(sub) return sub
|
|
40
|
+
}
|
|
41
|
+
return undefined
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// /cosmos/base/tendermint/v1beta1/blocks/latest
|
|
45
|
+
export async function getLatestBlock(endpoint: string) {
|
|
46
|
+
const url = `${endpoint}/cosmos/base/tendermint/v1beta1/blocks/latest`
|
|
47
|
+
return get(url)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export async function getAccount(endpoint: string, address: string) {
|
|
51
|
+
const url = `${endpoint}/cosmos/auth/v1beta1/accounts/${address}`
|
|
52
|
+
try{
|
|
53
|
+
const res = await get(url)
|
|
54
|
+
return {
|
|
55
|
+
account: {
|
|
56
|
+
account_number: findField(res, "account_number"),
|
|
57
|
+
sequence: findField(res, "sequence")
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}catch(err) {
|
|
61
|
+
throw new Error(err)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export async function getBalance(endpoint: string, address: string): Promise<{balances: Coin[]}> {
|
|
67
|
+
const url = `${endpoint}/cosmos/bank/v1beta1/balances/${address}`
|
|
68
|
+
return get(url)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export async function getBalanceMetadata(endpoint: string, denom: string): Promise<{metadata: CoinMetadata }> {
|
|
72
|
+
const url = `${endpoint}/cosmos/bank/v1beta1/denoms_metadata/${denom}`
|
|
73
|
+
return get(url)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export async function getIBCDenomMetadata(denom: string): Promise<CoinMetadata> {
|
|
77
|
+
const url = `https://metadata.ping.pub/metadata/${denom.replace("ibc/", "")}`
|
|
78
|
+
return get(url)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export async function getCoinMetadata(endpoint: string, denom: string) {
|
|
82
|
+
const url = `${endpoint}/cosmos/bank/v1beta1/denoms_metadata/${denom}`
|
|
83
|
+
return get(url)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export async function getDelegateRewards(endpoint: string, address: string) {
|
|
87
|
+
const url = `${endpoint}/cosmos/distribution/v1beta1/delegators/${address}/rewards`
|
|
88
|
+
return get(url)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export async function getDelegations(endpoint: string, validator_addr: string, address: string) : Promise< {
|
|
92
|
+
delegation_response: {
|
|
93
|
+
balance: Coin,
|
|
94
|
+
delegation: {
|
|
95
|
+
delegator_address: string,
|
|
96
|
+
shares: string,
|
|
97
|
+
validator_address: string
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}> {
|
|
101
|
+
const url = `${endpoint}/cosmos/staking/v1beta1/validators/${validator_addr}/delegations/${address}`
|
|
102
|
+
return get(url)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export async function getActiveValidators(endpoint: string) {
|
|
106
|
+
const url = `${endpoint}/cosmos/staking/v1beta1/validators?pagination.limit=300&status=BOND_STATUS_BONDED`
|
|
107
|
+
return get(url)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export async function getInactiveValidators(endpoint: string) {
|
|
111
|
+
const url = `${endpoint}/cosmos/staking/v1beta1/validators?pagination.limit=300&status=BOND_STATUS_UNBONDED`
|
|
112
|
+
return get(url)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// /ibc/apps/transfer/v1/denom_traces/{hash}
|
|
116
|
+
export async function getDenomTraces(endpoint: string, hash: string) : Promise<{
|
|
117
|
+
denom_trace: {
|
|
118
|
+
path: string;
|
|
119
|
+
base_denom: string;
|
|
120
|
+
};
|
|
121
|
+
}> {
|
|
122
|
+
const url = `${endpoint}/ibc/apps/transfer/v1/denom_traces/${hash}`
|
|
123
|
+
return get(url)
|
|
124
|
+
}
|
|
125
|
+
// /cosmos/tx/v1beta1/txs/{hash}
|
|
126
|
+
export async function getTxByHash(endpoint: string, hash: string) : Promise<{
|
|
127
|
+
tx_response: TxResponse;
|
|
128
|
+
}> {
|
|
129
|
+
const url = `${endpoint}/cosmos/tx/v1beta1/txs/${hash}`
|
|
130
|
+
return get(url)
|
|
131
|
+
}
|
|
132
|
+
// /cosmos/staking/v1beta1/params
|
|
133
|
+
export async function getStakingParam(endpoint: string) : Promise<{
|
|
134
|
+
params: {
|
|
135
|
+
unbonding_time: string;
|
|
136
|
+
max_validators: number;
|
|
137
|
+
max_entries: number;
|
|
138
|
+
historical_entries: number;
|
|
139
|
+
bond_denom: string;
|
|
140
|
+
};
|
|
141
|
+
}> {
|
|
142
|
+
const url = `${endpoint}/cosmos/staking/v1beta1/params`
|
|
143
|
+
return get(url)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export async function getOsmosisPools(endpoint: string) {
|
|
147
|
+
const url = `${endpoint}/osmosis/gamm/v1beta1/pools?pagination.limit=1000`
|
|
148
|
+
return get(url)
|
|
149
|
+
}
|
|
150
|
+
// https://lcd.osmosis.zone
|
|
151
|
+
// /osmosis/gamm/v1beta1/{pool_id}/estimate/swap_exact_amount_in
|
|
152
|
+
export async function estimateSwapAmountIn(endpoint: string, poolId: string, token: Coin) {
|
|
153
|
+
const url = `${endpoint}/osmosis/gamm/v1beta1/${poolId}/estimate/swap_exact_amount_in?token_in=${token.amount}${token.denom}`
|
|
154
|
+
return get(url)
|
|
155
155
|
}
|
package/lib/utils/type.ts
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import { EncodeObject } from '@cosmjs/proto-signing';
|
|
2
|
-
import { SignerData, StdFee } from '@cosmjs/stargate';
|
|
3
|
-
import type { App, Plugin } from 'vue';
|
|
4
|
-
export const withInstall = <T>(comp: T) => {
|
|
5
|
-
const c = comp as any;
|
|
6
|
-
c.install = function (app: App) {
|
|
7
|
-
app.component(c.displayName || c.name, comp as any);
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
return comp as T & Plugin;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export interface Coin {
|
|
15
|
-
amount: string,
|
|
16
|
-
denom: string,
|
|
17
|
-
}
|
|
18
|
-
export interface Configuration {
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface CoinMetadata {
|
|
23
|
-
description: string,
|
|
24
|
-
denom_units: {
|
|
25
|
-
denom: string,
|
|
26
|
-
exponent: number,
|
|
27
|
-
aliases: string[]
|
|
28
|
-
}[],
|
|
29
|
-
base: string,
|
|
30
|
-
display: string,
|
|
31
|
-
name: string,
|
|
32
|
-
symbol: string
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface TxResponse {
|
|
36
|
-
height: string,
|
|
37
|
-
txhash: string,
|
|
38
|
-
codespace: string,
|
|
39
|
-
code: 0,
|
|
40
|
-
data: string,
|
|
41
|
-
raw_log: string,
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface Transaction {
|
|
45
|
-
chainId: string;
|
|
46
|
-
signerAddress: string;
|
|
47
|
-
messages: readonly EncodeObject[];
|
|
48
|
-
fee: StdFee;
|
|
49
|
-
memo: string;
|
|
50
|
-
signerData: SignerData
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export enum BroadcastMode {
|
|
54
|
-
SYNC = 'BROADCAST_MODE_SYNC',
|
|
55
|
-
BLOCK = 'BROADCAST_MODE_BLOCK',
|
|
56
|
-
ASYNC = 'BROADCAST_MODE_ASYNC',
|
|
1
|
+
import { EncodeObject } from '@cosmjs/proto-signing';
|
|
2
|
+
import { SignerData, StdFee } from '@cosmjs/stargate';
|
|
3
|
+
import type { App, Plugin } from 'vue';
|
|
4
|
+
export const withInstall = <T>(comp: T) => {
|
|
5
|
+
const c = comp as any;
|
|
6
|
+
c.install = function (app: App) {
|
|
7
|
+
app.component(c.displayName || c.name, comp as any);
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
return comp as T & Plugin;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
export interface Coin {
|
|
15
|
+
amount: string,
|
|
16
|
+
denom: string,
|
|
17
|
+
}
|
|
18
|
+
export interface Configuration {
|
|
19
|
+
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface CoinMetadata {
|
|
23
|
+
description: string,
|
|
24
|
+
denom_units: {
|
|
25
|
+
denom: string,
|
|
26
|
+
exponent: number,
|
|
27
|
+
aliases: string[]
|
|
28
|
+
}[],
|
|
29
|
+
base: string,
|
|
30
|
+
display: string,
|
|
31
|
+
name: string,
|
|
32
|
+
symbol: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface TxResponse {
|
|
36
|
+
height: string,
|
|
37
|
+
txhash: string,
|
|
38
|
+
codespace: string,
|
|
39
|
+
code: 0,
|
|
40
|
+
data: string,
|
|
41
|
+
raw_log: string,
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface Transaction {
|
|
45
|
+
chainId: string;
|
|
46
|
+
signerAddress: string;
|
|
47
|
+
messages: readonly EncodeObject[];
|
|
48
|
+
fee: StdFee;
|
|
49
|
+
memo: string;
|
|
50
|
+
signerData: SignerData
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export enum BroadcastMode {
|
|
54
|
+
SYNC = 'BROADCAST_MODE_SYNC',
|
|
55
|
+
BLOCK = 'BROADCAST_MODE_BLOCK',
|
|
56
|
+
ASYNC = 'BROADCAST_MODE_ASYNC',
|
|
57
57
|
}
|