@mictonode/widget 0.3.9

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.
Files changed (70) hide show
  1. package/.github/FUNDING.yml +3 -0
  2. package/.github/workflows/npm-publish.yml +34 -0
  3. package/.prettierrc.json +9 -0
  4. package/.vscode/extensions.json +3 -0
  5. package/README.md +41 -0
  6. package/dist/main-172a6585.js +404361 -0
  7. package/dist/ping-widget.js +13 -0
  8. package/dist/ping-widget.umd.cjs +96 -0
  9. package/dist/query.lcd-2adf1c0c.js +129 -0
  10. package/dist/query.rpc.Query-b53908e7.js +2316 -0
  11. package/dist/tx.rpc.msg-d234ff40.js +37 -0
  12. package/dist/tx.rpc.msg-f7a80a78.js +21 -0
  13. package/example/.vscode/extensions.json +3 -0
  14. package/example/README.md +7 -0
  15. package/example/index.html +12 -0
  16. package/example/package.json +19 -0
  17. package/example/pnpm-lock.yaml +465 -0
  18. package/example/public/cdn.html +19 -0
  19. package/example/src/App.vue +73 -0
  20. package/example/src/main.js +4 -0
  21. package/example/vite.config.js +7 -0
  22. package/index.html +12 -0
  23. package/lib/components/ConnectWallet/index.vue +267 -0
  24. package/lib/components/TokenConvert/index.vue +1033 -0
  25. package/lib/components/TokenConvert/tokens.ts +37 -0
  26. package/lib/components/TxDialog/index.vue +432 -0
  27. package/lib/components/TxDialog/messages/Delegate.vue +194 -0
  28. package/lib/components/TxDialog/messages/Deposit.vue +97 -0
  29. package/lib/components/TxDialog/messages/MsgDelegate.ts +0 -0
  30. package/lib/components/TxDialog/messages/Redelegate.vue +189 -0
  31. package/lib/components/TxDialog/messages/Send.vue +142 -0
  32. package/lib/components/TxDialog/messages/Transfer.vue +248 -0
  33. package/lib/components/TxDialog/messages/Unbond.vue +137 -0
  34. package/lib/components/TxDialog/messages/Vote.vue +63 -0
  35. package/lib/components/TxDialog/messages/Withdraw.vue +56 -0
  36. package/lib/components/TxDialog/messages/WithdrawCommission.vue +75 -0
  37. package/lib/components/TxDialog/wasm/ClearAdmin.vue +56 -0
  38. package/lib/components/TxDialog/wasm/ExecuteContract.vue +99 -0
  39. package/lib/components/TxDialog/wasm/InstantiateContract.vue +109 -0
  40. package/lib/components/TxDialog/wasm/MigrateContract.vue +77 -0
  41. package/lib/components/TxDialog/wasm/MigrateContract2.vue +77 -0
  42. package/lib/components/TxDialog/wasm/StoreCode.vue +101 -0
  43. package/lib/components/TxDialog/wasm/UpdateAdmin.vue +75 -0
  44. package/lib/main.css +7 -0
  45. package/lib/main.ts +23 -0
  46. package/lib/utils/TokenUnitConverter.ts +45 -0
  47. package/lib/utils/format.ts +16 -0
  48. package/lib/utils/http.ts +223 -0
  49. package/lib/utils/type.ts +77 -0
  50. package/lib/wallet/EthermintMessageAdapter.ts +136 -0
  51. package/lib/wallet/UniClient.ts +152 -0
  52. package/lib/wallet/Wallet.ts +138 -0
  53. package/lib/wallet/wallets/InitiaWallet.ts +189 -0
  54. package/lib/wallet/wallets/KeplerWallet.ts +158 -0
  55. package/lib/wallet/wallets/LeapWallet.ts +142 -0
  56. package/lib/wallet/wallets/LedgerWallet.ts +203 -0
  57. package/lib/wallet/wallets/MetamaskSnapWallet.ts +105 -0
  58. package/lib/wallet/wallets/MetamaskWallet.ts +173 -0
  59. package/lib/wallet/wallets/OKXWallet.ts +202 -0
  60. package/lib/wallet/wallets/UnisatWallet.ts +198 -0
  61. package/package.json +102 -0
  62. package/postcss.config.js +6 -0
  63. package/src/App.vue +241 -0
  64. package/src/main.ts +4 -0
  65. package/src/vite-env.d.ts +1 -0
  66. package/tailwind.config.js +34 -0
  67. package/tsconfig.json +25 -0
  68. package/tsconfig.node.json +10 -0
  69. package/vite.config.ts +62 -0
  70. package/vue-shim.d.ts +6 -0
@@ -0,0 +1,77 @@
1
+ <script lang="ts" setup>
2
+ import { computed, ref } from 'vue';
3
+ import { toBase64 } from '@cosmjs/encoding'
4
+
5
+ const props = defineProps({
6
+ endpoint: { type: String, required: true },
7
+ sender: { type: String, required: true },
8
+ params: String,
9
+ });
10
+
11
+ const params = computed(() => JSON.parse(props.params || "{}"))
12
+
13
+ const codeId = ref("")
14
+ const msg = ref("")
15
+
16
+ const msgs = computed(() => {
17
+ return [{
18
+ typeUrl: '/cosmwasm.wasm.v1.MsgMigrateContract',
19
+ value: {
20
+ /** Sender is the that actor that signed the messages */
21
+ sender: props.sender,
22
+ /** contract address that can execute migrations */
23
+ contract: params.value.contract,
24
+ /** CodeID is the reference to the stored WASM code */
25
+ codeId: codeId.value,
26
+ /** Msg json encoded message to be passed to the contract on instantiation */
27
+ msg: toBase64(new TextEncoder().encode(msg.value)),
28
+ },
29
+ }]
30
+ })
31
+
32
+ const isValid = computed(() => {
33
+ let ok = true
34
+ let error = ""
35
+ if( Number(codeId.value) < 1) {
36
+ ok = false
37
+ error = "Code Id is not selected"
38
+ }
39
+ return { ok, error }
40
+ })
41
+
42
+ function initial() {
43
+ }
44
+
45
+ defineExpose({msgs, isValid, initial})
46
+
47
+ </script>
48
+ <template>
49
+ <div>
50
+ <div class="form-control">
51
+ <label class="label">
52
+ <span class="label-text">Sender</span>
53
+ </label>
54
+ <input :value="sender" type="text" class="text-gray-600 dark:text-white input border !border-gray-300 dark:!border-gray-600" />
55
+ </div>
56
+ <div class="form-control">
57
+ <label class="label">
58
+ <span class="label-text">Contract Address</span>
59
+ </label>
60
+ <input type="text" readonly class="text-gray-600 dark:text-white input border !border-gray-300 dark:!border-gray-600" :value="params.contract" />
61
+ </div>
62
+
63
+ <div class="form-control">
64
+ <label class="label">
65
+ <span class="label-text">Code Id</span>
66
+ </label>
67
+ <input v-model="codeId" type="text" class="text-gray-600 dark:text-white input border !border-gray-300 dark:!border-gray-600" />
68
+ </div>
69
+
70
+ <div class="form-control">
71
+ <label class="label">
72
+ <span class="label-text">Messages</span>
73
+ </label>
74
+ <textarea v-model="msg" placeholder="{config: {}}" class="text-gray-600 dark:text-white textarea border !border-gray-300 dark:!border-gray-600"></textarea>
75
+ </div>
76
+ </div>
77
+ </template>
@@ -0,0 +1,101 @@
1
+ <script lang="ts" setup>
2
+ import { PropType, computed, ref } from 'vue';
3
+ import * as fflate from 'fflate';
4
+
5
+ const props = defineProps({
6
+ endpoint: { type: String, required: true },
7
+ sender: { type: String, required: true },
8
+ params: String,
9
+ });
10
+
11
+ const bytecode = ref(new Uint8Array())
12
+ const addresses = ref("")
13
+ const permission = ref('3')
14
+ const zip = ref('gzip')
15
+
16
+ function loadWasm(event) {
17
+ const file = event.target.files[0]
18
+ if(file) {
19
+ var reader = new FileReader();
20
+ reader.addEventListener('load', (e)=>{
21
+ if(e.target) {
22
+ if(zip.value === 'gzip') {
23
+ bytecode.value = fflate.compressSync(new Uint8Array(e.target.result as ArrayBuffer))
24
+ }
25
+ bytecode.value = new Uint8Array(e.target.result as ArrayBuffer)
26
+ }
27
+ });
28
+ reader.readAsArrayBuffer(file);
29
+ }
30
+ }
31
+
32
+ const msgs = computed(() => {
33
+ return [{
34
+ typeUrl: '/cosmwasm.wasm.v1.MsgStoreCode',
35
+ value: {
36
+ sender: props.sender,
37
+ wasmByteCode: bytecode.value,
38
+ instantiatePermission: {
39
+ permission: permission.value,
40
+ addresses: addresses.value.split(","),
41
+ },
42
+ },
43
+ }]
44
+ })
45
+ const isValid = computed(() => {
46
+ let ok = true
47
+ let error = ""
48
+ if( bytecode.value.length < 1) {
49
+ ok = false
50
+ error = "No contract is selected"
51
+ }
52
+ return { ok, error }
53
+ })
54
+
55
+ function initial() {
56
+
57
+ }
58
+
59
+ defineExpose({msgs, isValid, initial})
60
+ </script>
61
+ <template>
62
+ <div>
63
+ <div class="form-control">
64
+ <label class="label">
65
+ <span class="label-text">Sender</span>
66
+ </label>
67
+ <input :value="sender" type="text" class="text-gray-600 dark:text-white input border !border-gray-300 dark:!border-gray-600" />
68
+ </div>
69
+ <div class="form-control">
70
+ <label class="label">
71
+ <span class="label-text">Permission</span>
72
+ </label>
73
+ <div class="flex">
74
+ <input v-model="permission" type="radio" id="nobody" value="1" class="radio radio-error mx-2" /><label for="nobody">Nobody</label>
75
+ <input v-model="permission" type="radio" id="everyone" value="3" class="radio radio-success mx-2" /><label for="everyone">Everybody</label>
76
+ <input v-model="permission" type="radio" id="anyofaddress" value="4" class="radio radio-success mx-2" /><label for="anyofaddress">Any Of addresses</label>
77
+ </div>
78
+ </div>
79
+ <div v-if="permission === '4'" class="form-control">
80
+ <label class="label">
81
+ <span class="label-text">Addresses</span>
82
+ </label>
83
+ <input v-model="addresses" type="text" placeholder="use ',' for addresses" class="input border border-gray-300 dark:border-gray-600" />
84
+ </div>
85
+ <div class="form-control">
86
+ <label class="label">
87
+ <span class="label-text">Compressing</span>
88
+ </label>
89
+ <div class="flex">
90
+ <input v-model="zip" type="radio" id="raw" value="raw" class="radio mx-2" /><label for="raw">Raw</label>
91
+ <input v-model="zip" type="radio" id="gzip" value="gzip" class="radio mx-2" /><label for="gzip">Gzip</label>
92
+ </div>
93
+ </div>
94
+ <div class="form-control">
95
+ <label class="label">
96
+ <span class="label-text">Contract</span>
97
+ </label>
98
+ <input type="file" class="file-input" @change="loadWasm"/>
99
+ </div>
100
+ </div>
101
+ </template>
@@ -0,0 +1,75 @@
1
+ <script lang="ts" setup>
2
+ import { computed, ref } from 'vue';
3
+ import { toBase64 } from '@cosmjs/encoding'
4
+
5
+ const props = defineProps({
6
+ endpoint: { type: String, required: true },
7
+ sender: { type: String, required: true },
8
+ params: String,
9
+ });
10
+
11
+ const params = computed(() => JSON.parse(props.params || "{}"))
12
+
13
+ const newAdmin = ref("")
14
+ const msg = ref("")
15
+
16
+ const msgs = computed(() => {
17
+ return [{
18
+ typeUrl: '/cosmwasm.wasm.v1.MsgUpdateAdmin',
19
+ value: {
20
+ /** Sender is the that actor that signed the messages */
21
+ sender: props.sender,
22
+ /** contract address that can execute migrations */
23
+ contract: params.value.contract,
24
+ /** CodeID is the reference to the stored WASM code */
25
+ newAdmin: newAdmin.value,
26
+ /** Msg json encoded message to be passed to the contract on instantiation */
27
+ msg: toBase64(new TextEncoder().encode(msg.value)),
28
+ },
29
+ }]
30
+ })
31
+
32
+ const isValid = computed(() => {
33
+ let ok = true
34
+ let error = ""
35
+ if( !params.value.contract) {
36
+ ok = false
37
+ error = "Contract is not selected!"
38
+ }
39
+ if( !newAdmin.value) {
40
+ ok = false
41
+ error = "Admin should not be empty!"
42
+ }
43
+ return { ok, error }
44
+ })
45
+
46
+ function initial() {
47
+ }
48
+
49
+ defineExpose({msgs, isValid, initial})
50
+
51
+ </script>
52
+ <template>
53
+ <div>
54
+ <div class="form-control">
55
+ <label class="label">
56
+ <span class="label-text">Sender</span>
57
+ </label>
58
+ <input :value="sender" type="text" class="text-gray-600 dark:text-white input border !border-gray-300 dark:!border-gray-600" />
59
+ </div>
60
+ <div class="form-control">
61
+ <label class="label">
62
+ <span class="label-text">Contract Address</span>
63
+ </label>
64
+ <input type="text" readonly class="text-gray-600 dark:text-white input border !border-gray-300 dark:!border-gray-600" :value="params.contract" />
65
+ </div>
66
+
67
+ <div class="form-control">
68
+ <label class="label">
69
+ <span class="label-text">New Admin</span>
70
+ </label>
71
+ <input v-model="newAdmin" type="text" class="text-gray-600 dark:text-white input border !border-gray-300 dark:!border-gray-600" />
72
+ </div>
73
+
74
+ </div>
75
+ </template>
package/lib/main.css ADDED
@@ -0,0 +1,7 @@
1
+ @tailwind base;
2
+ @tailwind components;
3
+ @tailwind utilities;
4
+
5
+ .input:focus {
6
+ outline: none;
7
+ }
package/lib/main.ts ADDED
@@ -0,0 +1,23 @@
1
+ import './main.css';
2
+ import { createApp, h } from 'vue';
3
+ // @ts-ignore
4
+ import wrapper from 'vue3-webcomponent-wrapper';
5
+
6
+ import TxDialog from './components/TxDialog/index.vue';
7
+ import ConnectWallet from './components/ConnectWallet/index.vue';
8
+ import TokenConvert from './components/TokenConvert/index.vue';
9
+
10
+ function registry(name: string, module: any) {
11
+ if (!window.customElements.get(name)) {
12
+ const component = wrapper(module, createApp, h);
13
+ window.customElements.define(name, component);
14
+ }
15
+ }
16
+
17
+ registry('ping-tx-dialog', TxDialog)
18
+ registry('ping-connect-wallet', ConnectWallet)
19
+ registry('ping-token-convert', TokenConvert)
20
+
21
+ export default {
22
+ version: '0.0.5',
23
+ };
@@ -0,0 +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
+ }
45
+ }
@@ -0,0 +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
+
@@ -0,0 +1,223 @@
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
+ //let returnvalue = getLatestBlock(`$endpoint`);
26
+
27
+ function isInitiaChain(endpoint: string): boolean {
28
+ return endpoint.indexOf("init") !== -1;
29
+ }
30
+
31
+ function findField(obj: any, name: string) {
32
+
33
+ if(!obj) return undefined
34
+
35
+ const list = Object.keys(obj).filter(x => x && !x.startsWith("@"))
36
+ if(list.includes(name)) {
37
+ return obj[name]
38
+ }
39
+ for(let i = 0; i < list.length; i++) {
40
+ const field = obj[list[i]]
41
+ if(typeof field === 'string') continue
42
+ if(Array.isArray(field)) continue
43
+
44
+ const sub = findField(field, name)
45
+ if(sub) return sub
46
+ }
47
+ return undefined
48
+ }
49
+
50
+ export async function getEndpoint(endpoint: string){
51
+ const url = `${endpoint}`
52
+ return get(url)
53
+ }
54
+
55
+ export async function getLatestBlock(endpoint: string){
56
+ const url = `${endpoint}/cosmos/base/tendermint/v1beta1/blocks/latest`
57
+ return get(url)
58
+ }
59
+
60
+ export async function getAccount(endpoint: string, address: string) {
61
+ const url = `${endpoint}/cosmos/auth/v1beta1/accounts/${address}`
62
+ try{
63
+ const res = await get(url)
64
+ return {
65
+ account: {
66
+ account_number: findField(res, "account_number"),
67
+ sequence: findField(res, "sequence")
68
+ }
69
+ }
70
+ }catch(err) {
71
+ throw new Error(err)
72
+ }
73
+
74
+ }
75
+
76
+ export async function getBalance(endpoint: string, address: string): Promise<{balances: Coin[]}> {
77
+ const url = `${endpoint}/cosmos/bank/v1beta1/balances/${address}`
78
+ return get(url)
79
+ }
80
+
81
+ export async function getBalanceMetadata(endpoint: string, denom: string): Promise<{metadata: CoinMetadata }> {
82
+ const url = `${endpoint}/cosmos/bank/v1beta1/denoms_metadata/${denom}`
83
+ return get(url)
84
+ }
85
+
86
+ export async function getIBCDenomMetadata(denom: string): Promise<CoinMetadata> {
87
+ const url = `https://metadata.ping.pub/metadata/${denom.replace("ibc/", "")}`
88
+ return get(url)
89
+ }
90
+
91
+ export async function getCoinMetadata(endpoint: string, denom: string) {
92
+ const url = `${endpoint}/cosmos/bank/v1beta1/denoms_metadata/${denom}`
93
+ return get(url)
94
+ }
95
+ export async function getInitiaMetadata(endpoint: string, denom: string) {
96
+ const url = `${endpoint}/initia/move/v1/metadata?denom=${denom}`
97
+ return get(url)
98
+ }
99
+
100
+ export async function getDelegateRewards(endpoint: string, address: string) {
101
+ const url = `${endpoint}/cosmos/distribution/v1beta1/delegators/${address}/rewards`
102
+ return get(url)
103
+ }
104
+
105
+ export async function getDelegations(endpoint: string, validator_addr: string, address: string): Promise<{
106
+ delegation_response: {
107
+ balance: Coin | Coin[],
108
+ delegation: {
109
+ delegator_address: string,
110
+ shares: string,
111
+ validator_address: string
112
+ }
113
+ }
114
+ }> {
115
+ const baseUrl = isInitiaChain(endpoint)
116
+ ? `${endpoint}/initia/mstaking/v1/validators`
117
+ : `${endpoint}/cosmos/staking/v1beta1/validators`;
118
+
119
+ const url = `${baseUrl}/${validator_addr}/delegations/${address}`;
120
+ const response = await get(url);
121
+
122
+ // Adjust balance type based on initia condition
123
+ if (isInitiaChain(endpoint)) {
124
+ response.delegation_response.balance = Array.isArray(response.delegation_response.balance)
125
+ ? response.delegation_response.balance
126
+ : [response.delegation_response.balance];
127
+ }
128
+
129
+ return response;
130
+ }
131
+
132
+
133
+ export async function getActiveValidators(endpoint: string) {
134
+ const baseUrl = isInitiaChain(endpoint)
135
+ ? `${endpoint}/initia/mstaking/v1/validators`
136
+ : `${endpoint}/cosmos/staking/v1beta1/validators`;
137
+
138
+ const url = `${baseUrl}?pagination.limit=300&status=BOND_STATUS_BONDED`;
139
+ return get(url);
140
+ }
141
+
142
+
143
+ export async function getInactiveValidators(endpoint: string) {
144
+ const baseUrl = isInitiaChain(endpoint)
145
+ ? `${endpoint}/initia/mstaking/v1/validators`
146
+ : `${endpoint}/cosmos/staking/v1beta1/validators`;
147
+
148
+ const url = `${baseUrl}?pagination.limit=300&status=BOND_STATUS_UNBONDED`;
149
+ return get(url);
150
+ }
151
+
152
+ // /ibc/apps/transfer/v1/denom_traces/{hash}
153
+ export async function getDenomTraces(endpoint: string, hash: string) : Promise<{
154
+ denom_trace: {
155
+ path: string;
156
+ base_denom: string;
157
+ };
158
+ }> {
159
+ const url = `${endpoint}/ibc/apps/transfer/v1beta1/denom_traces/${hash}`
160
+ return get(url)
161
+ }
162
+ // /cosmos/tx/v1beta1/txs/{hash}
163
+ export async function getTxByHash(endpoint: string, hash: string) : Promise<{
164
+ tx_response: TxResponse;
165
+ }> {
166
+ const url = `${endpoint}/cosmos/tx/v1beta1/txs/${hash}`
167
+ return get(url)
168
+ }
169
+ // /cosmos/staking/v1beta1/params
170
+
171
+ // /initia/mstaking/v1/params
172
+
173
+ export async function getStakingParam(endpoint: string): Promise<{
174
+ params: {
175
+ unbonding_time: string;
176
+ max_validators: number;
177
+ max_entries: number;
178
+ historical_entries: number;
179
+ bond_denom?: string;
180
+ bond_denoms?: string[];
181
+ min_voting_power: string;
182
+ min_commission_rate: string;
183
+ }
184
+ }> {
185
+ const initia = isInitiaChain(endpoint);
186
+ const url = initia
187
+ ? `${endpoint}/initia/mstaking/v1/params`
188
+ : `${endpoint}/cosmos/staking/v1beta1/params`;
189
+ const response = await get(url);
190
+
191
+ if (initia) {
192
+ const bondDenomsArray = Array.isArray(response.params.bond_denom)
193
+ ? response.params.bond_denom
194
+ : [response.params.bond_denom];
195
+
196
+ // Ensure "uinit" is in the bond_denoms array
197
+ if (!bondDenomsArray.includes("uinit")) {
198
+ bondDenomsArray.unshift("uinit");
199
+ }
200
+
201
+ response.params.bond_denoms = bondDenomsArray;
202
+ response.params.bond_denom = bondDenomsArray[0];
203
+ } else {
204
+ // Ensure bond_denom is a string
205
+ if (Array.isArray(response.params.bond_denom)) {
206
+ response.params.bond_denom = response.params.bond_denom[0];
207
+ }
208
+ }
209
+
210
+ return response;
211
+ }
212
+
213
+
214
+ export async function getOsmosisPools(endpoint: string) {
215
+ const url = `${endpoint}/osmosis/gamm/v1beta1/pools?pagination.limit=1000`
216
+ return get(url)
217
+ }
218
+ // https://lcd.osmosis.zone
219
+ // /osmosis/gamm/v1beta1/{pool_id}/estimate/swap_exact_amount_in
220
+ export async function estimateSwapAmountIn(endpoint: string, poolId: string, token: Coin) {
221
+ const url = `${endpoint}/osmosis/gamm/v1beta1/${poolId}/estimate/swap_exact_amount_in?token_in=${token.amount}${token.denom}`
222
+ return get(url)
223
+ }
@@ -0,0 +1,77 @@
1
+ //import { EncodeObject } from '@cosmjs/proto-signing';
2
+ import { SignerData, StdFee } from '@cosmjs/stargate';
3
+ import { EncodeObject } from '@initia/utils';
4
+ import type { App, Plugin } from 'vue';
5
+ export const withInstall = <T>(comp: T) => {
6
+ const c = comp as any;
7
+ c.install = function (app: App) {
8
+ app.component(c.displayName || c.name, comp as any);
9
+ };
10
+
11
+ return comp as T & Plugin;
12
+ };
13
+
14
+
15
+ export interface Coin {
16
+ amount: string,
17
+ denom: string,
18
+ }
19
+ export interface Configuration {
20
+
21
+ }
22
+
23
+ export interface CoinMetadata {
24
+ description: string,
25
+ denom_units: {
26
+ denom: string,
27
+ exponent: number,
28
+ aliases: string[]
29
+ }[],
30
+ base: string,
31
+ display: string,
32
+ name: string,
33
+ symbol: string
34
+ }
35
+
36
+ export interface TxResponse {
37
+ height: string,
38
+ txhash: string,
39
+ codespace: string,
40
+ code: 0,
41
+ data: string,
42
+ raw_log: string,
43
+ }
44
+ export interface DeliverTxResponse {
45
+ readonly height: number;
46
+ readonly txIndex: number;
47
+ readonly code: number;
48
+ readonly transactionHash: string;
49
+ readonly events: readonly Event[];
50
+ readonly rawLog?: string;
51
+ readonly msgResponses: Array<{
52
+ readonly typeUrl: string;
53
+ readonly value: Uint8Array;
54
+ }>;
55
+ readonly gasUsed: bigint;
56
+ readonly gasWanted: bigint;
57
+ }
58
+
59
+ export interface Transaction {
60
+ chainId: string;
61
+ signerAddress: string;
62
+ messages: readonly EncodeObject[];
63
+ fee: StdFee;
64
+ memo: string;
65
+ signerData: SignerData;
66
+ gas?: string;
67
+ bodyBytes: Uint8Array;
68
+ authInfoBytes: Uint8Array;
69
+ signatures: Uint8Array[];
70
+ BroadcastMode: BroadcastMode;
71
+ }
72
+
73
+ export enum BroadcastMode {
74
+ SYNC = 'BROADCAST_MODE_SYNC',
75
+ BLOCK = 'BROADCAST_MODE_BLOCK',
76
+ ASYNC = 'BROADCAST_MODE_ASYNC',
77
+ }