@instadapp/avocado-base 0.0.0-dev.6b57a8a → 0.0.0-dev.6b5e615

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.
@@ -0,0 +1,64 @@
1
+ <script setup lang="ts">
2
+ import CopySVG from '~/assets/images/icons/copy.svg'
3
+ import CheckCircle from '~/assets/images/icons/check-circle.svg'
4
+
5
+ defineProps<{
6
+ text: string
7
+ iconOnly?: boolean
8
+ successText?: string
9
+ }>()
10
+ const { copy, copied } = useClipboard()
11
+ const slots = useSlots()
12
+ </script>
13
+
14
+ <template>
15
+ <button
16
+ class="text-slate-400 font-semibold inline-flex items-center gap-2.5"
17
+ @click.stop="copy(text)"
18
+ >
19
+ <Transition mode="out-in" name="slide-left">
20
+ <span v-if="copied && !iconOnly"> {{ successText || 'Copied' }} </span>
21
+ <span v-else-if="slots.content">
22
+ <slot name="content" />
23
+ </span>
24
+ </Transition>
25
+
26
+ <Transition mode="out-in" name="slide">
27
+ <CheckCircle
28
+ v-if="copied"
29
+ class="w-4 h-4 shrink-0 dark:text-slate-900 text-white svg-circle"
30
+ />
31
+ <slot v-else-if="slots.copy" name="copy" />
32
+ <slot v-else name="copy-icon">
33
+ <CopySVG />
34
+ </slot>
35
+ </Transition>
36
+ </button>
37
+ </template>
38
+
39
+ <style scoped>
40
+ .slide-left-enter-active,
41
+ .slide-left-leave-active {
42
+ transition: all 0.1s ease-out;
43
+ }
44
+
45
+ .slide-left-enter-from {
46
+ opacity: 0;
47
+ transform: translateX(30px);
48
+ }
49
+
50
+ .slide-left-leave-to {
51
+ opacity: 0;
52
+ transform: translateX(-30px);
53
+ }
54
+
55
+ .slide-enter-active,
56
+ .slide-leave-active {
57
+ transition: opacity 0.1s ease;
58
+ }
59
+
60
+ .slide-enter-from,
61
+ .slide-leave-to {
62
+ opacity: 0;
63
+ }
64
+ </style>
@@ -6,11 +6,26 @@ const props = defineProps<{
6
6
  }>();
7
7
 
8
8
  const compact = inject('compact');
9
+ const tokens = inject<ITokenPrice[]>('tokens');
9
10
 
10
11
  const toToken = asyncComputed(() =>
11
- fetchTokenByAddress(props.metadata?.toToken, props.metadata?.toChainId)
12
+ {
13
+ if (Array.isArray(tokens) && !tokens.length) return null;
14
+ return fetchTokenByAddress(props.metadata?.toToken, props.metadata?.toChainId, tokens)
15
+ }
12
16
  );
13
17
 
18
+ const fromToken = asyncComputed(() =>
19
+ {
20
+ if (Array.isArray(tokens) && !tokens.length) return null;
21
+ return fetchTokenByAddress(props.metadata?.fromToken, props.chain_id, tokens)
22
+ }
23
+ );
24
+
25
+ const isTokensSame = computed(() => {
26
+ return toToken.value?.symbol === fromToken.value?.symbol
27
+ })
28
+
14
29
  const bridgeAmountFormatted = computed(() =>
15
30
  formatDecimal(
16
31
  fromWei(props.metadata?.amount, toToken?.value?.decimals).toFixed()
@@ -19,18 +34,23 @@ const bridgeAmountFormatted = computed(() =>
19
34
  </script>
20
35
 
21
36
  <template>
22
- <div v-if="!toToken" class="rounded-5 w-24 h-4 loading-box" />
37
+ <div v-if="!toToken || !fromToken" class="rounded-5 w-24 h-4 loading-box" />
23
38
  <div
24
39
  class="flex gap-5 items-center"
25
- v-if="metadata.type === 'bridge' && toToken"
40
+ v-if="toToken && fromToken"
26
41
  >
27
42
  <span v-if="!compact" class="capitalize text-xs sm:text-sm">{{ metadata.type }}</span>
28
43
  <span class="inline-flex gap-2.5 items-center">
29
- <img width="20" height="20" class="w-5 h-5" :src="toToken.logo_url" />
44
+ <img width="20" height="20" class="w-5 h-5" :src="fromToken.logo_url" />
30
45
  {{ bridgeAmountFormatted }}
31
- <span class="uppercase">{{ toToken?.symbol }}</span>
46
+ <span class="uppercase">{{ fromToken?.symbol }}</span>
32
47
  <SvgoBridge class="text-slate-400 w-4 h-4" />
48
+ <template v-if="!isTokensSame">
49
+ <img width="20" height="20" class="w-5 h-5" :src="toToken.logo_url" />
50
+ <span class="uppercase">{{ toToken?.symbol }}</span>
51
+ </template>
33
52
  <span class="flex items-center gap-2.5">
53
+ on
34
54
  <ChainLogo class="w-5" :chain="metadata.toChainId" />
35
55
  <span>{{ chainIdToName(metadata.toChainId) }}</span>
36
56
  </span>
@@ -6,13 +6,17 @@ const props = defineProps<{
6
6
  }>();
7
7
 
8
8
  const compact = inject('compact');
9
+ const tokens = inject<ITokenPrice[]>('tokens');
9
10
 
10
11
  const fromToken = asyncComputed(() => {
11
12
  if (!props?.chain_id) return null;
12
13
 
14
+ if (Array.isArray(tokens) && !tokens.length) return null;
15
+
13
16
  return fetchTokenByAddress(
14
17
  props.metadata?.fromToken,
15
- props?.chain_id
18
+ props?.chain_id,
19
+ tokens
16
20
  );
17
21
  });
18
22
 
@@ -5,8 +5,14 @@ const props = defineProps<{
5
5
  chain_id: number | string
6
6
  }>();
7
7
 
8
+ const tokens = inject<ITokenPrice[]>('tokens');
9
+
8
10
  const token = asyncComputed(() =>
9
- fetchTokenByAddress(props.metadata?.token, props?.chain_id)
11
+ {
12
+ if (Array.isArray(tokens) && !tokens.length) return null;
13
+
14
+ return fetchTokenByAddress(props.metadata?.token, props?.chain_id, tokens)
15
+ }
10
16
  );
11
17
 
12
18
  const compact = inject('compact');
@@ -5,8 +5,13 @@ const props = defineProps<{
5
5
  chain_id: number | string
6
6
  }>();
7
7
 
8
+ const tokens = inject<ITokenPrice[]>('tokens');
9
+
8
10
  const token = asyncComputed(() =>
9
- fetchTokenByAddress(props.metadata?.token, props?.chain_id)
11
+ {
12
+ if (Array.isArray(tokens) && !tokens.length) return null;
13
+ return fetchTokenByAddress(props.metadata?.token, props?.chain_id, tokens)
14
+ }
10
15
  );
11
16
 
12
17
  const calculateDate = (timestamp: number) => {
@@ -0,0 +1,45 @@
1
+ <script setup lang="ts">
2
+ import { Tippy } from 'vue-tippy'
3
+ const props = defineProps<{
4
+ metadata: {
5
+ type: MetadataTypes,
6
+ [key: string]: any
7
+ };
8
+ compact?: boolean;
9
+ }>();
10
+ </script>
11
+
12
+ <template>
13
+ <div>
14
+ <div v-if="!compact || metadata.addresses.length < 3" class="flex gap-[14px] flex-wrap">
15
+ <div v-for="address of metadata.addresses" :key="address" class="flex gap-[8px] rounded-full bg-slate-50 dark:bg-gray-850 justify-start items-center px-[8px] py-[6px]">
16
+ <AuthorityAvatar :address="address" class="w-[18px] h-[18px]" />
17
+ <p class="text-xs leading-5">
18
+ {{ shortenHash(address, compact ? 2 : 4) }}
19
+ </p>
20
+ </div>
21
+ </div>
22
+ <div v-else class="flex gap-2 flex-wrap items-center">
23
+ <div v-for="address of [metadata.addresses[0], metadata.addresses[1]]" :key="address" class="flex gap-[8px] rounded-full bg-slate-50 dark:bg-gray-850 justify-start items-center px-[8px] py-[6px]">
24
+ <AuthorityAvatar :address="address" class="w-[18px] h-[18px]" />
25
+ <p class="text-xs leading-5">
26
+ {{ shortenHash(address, 2) }}
27
+ </p>
28
+ </div>
29
+ ...
30
+ <Tippy max-width="none" interactive tag="button" content-tag="div" content-class="content-wrapper">
31
+ <template #default>
32
+ <SvgoInfo2 class="w-[16px] h-[16px] text-slate-500 rounded-full" />
33
+ </template>
34
+ <template #content>
35
+ <ul class="flex flex-col gap-2.5">
36
+ <li v-for="address in metadata.addresses" :key="address" class="flex text-xs items-center gap-2.5">
37
+ <AuthorityAvatar class="shrink-0 w-5 h-5" :address="address" />
38
+ {{ address }}
39
+ </li>
40
+ </ul>
41
+ </template>
42
+ </Tippy>
43
+ </div>
44
+ </div>
45
+ </template>
@@ -6,12 +6,19 @@ const props = defineProps<{
6
6
  }>();
7
7
 
8
8
  const compact = inject('compact');
9
+ const tokens = inject<ITokenPrice[]>('tokens');
9
10
 
10
11
  const buyToken = asyncComputed(() =>
11
- fetchTokenByAddress(props.metadata?.buyToken, props?.chain_id)
12
+ {
13
+ if (Array.isArray(tokens) && !tokens.length) return null;
14
+ return fetchTokenByAddress(props.metadata?.buyToken, props?.chain_id, tokens)
15
+ }
12
16
  );
13
17
  const sellToken = asyncComputed(() =>
14
- fetchTokenByAddress(props.metadata?.sellToken, props?.chain_id)
18
+ {
19
+ if (Array.isArray(tokens) && !tokens.length) return null;
20
+ return fetchTokenByAddress(props.metadata?.sellToken, props?.chain_id, tokens)
21
+ }
15
22
  );
16
23
 
17
24
  const sellAmountFormatted = computed(() =>
@@ -6,13 +6,17 @@ const props = defineProps<{
6
6
  }>();
7
7
 
8
8
  const compact = inject('compact');
9
+ const tokens = inject<ITokenPrice[]>('tokens');
9
10
 
10
11
  const token = asyncComputed(() => {
11
12
  if (!props?.chain_id) return null;
12
13
 
14
+ if (Array.isArray(tokens) && !tokens.length) return null;
15
+
13
16
  return fetchTokenByAddress(
14
17
  props.metadata?.token,
15
- props?.chain_id
18
+ props?.chain_id,
19
+ tokens
16
20
  );
17
21
  });
18
22
 
@@ -28,9 +32,9 @@ const formattedAmount = computed(() =>
28
32
  <div class="flex items-center gap-5" v-else>
29
33
  <span v-if="!compact" class="capitalize text-xs sm:text-sm">{{ metadata.type }}</span>
30
34
  <span class="inline-flex gap-2.5 items-center">
31
- <img width="20" height="20" class="w-5 h-5" :src="token?.logo_url" />
32
35
  {{ formattedAmount }}
33
36
  <span class="uppercase">{{ token?.symbol }}</span>
37
+ <img width="20" height="20" class="w-5 h-5" :src="token?.logo_url" />
34
38
  <SvgoArrowRight class="w-4 h-4 text-slate-400 mx-2" />
35
39
  <NuxtLink
36
40
  class="text-primary"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instadapp/avocado-base",
3
- "version": "0.0.0-dev.6b57a8a",
3
+ "version": "0.0.0-dev.6b5e615",
4
4
  "type": "module",
5
5
  "main": "./nuxt.config.ts",
6
6
  "types": "global.d.ts",
@@ -20,11 +20,13 @@
20
20
  "nuxt-svgo": "^3.1.0",
21
21
  "rimraf": "^3.0.2",
22
22
  "typechain": "^8.1.1",
23
- "unplugin-vue-components": "^0.25.1"
23
+ "unplugin-vue-components": "^0.25.1",
24
+ "vue-tippy": "^6.0.0"
24
25
  },
25
26
  "dependencies": {
26
27
  "@vueuse/nuxt": "^10.2.0",
27
28
  "bignumber.js": "^9.1.1",
28
- "ethers": "^5.7.2"
29
+ "ethers": "^5.7.2",
30
+ "xxhashjs": "^0.2.2"
29
31
  }
30
32
  }
@@ -72,7 +72,7 @@ export function formatDecimal(value: string | number, fractionDigits?: number) {
72
72
  let decimals;
73
73
 
74
74
  if (num.lt(1)) {
75
- decimals = 8;
75
+ decimals = 4;
76
76
  } else if (num.lt(10)) {
77
77
  decimals = 6;
78
78
  } else if (num.lt(100)) {
package/utils/helper.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import * as XXH from 'xxhashjs';
2
+
1
3
  export const indexSorter = (aIndex: number, bIndex: number) => {
2
4
  if (aIndex === -1 && bIndex === -1) {
3
5
  return 0; // fallback to other sorting criteria
@@ -58,4 +60,14 @@ export function formatMultipleAddresses(addresses: string[], shorten = true) {
58
60
  const formattedString = formatter.format(addresses.map(i => shorten ? shortenHash(i) || '' : i))
59
61
 
60
62
  return formattedString
63
+ }
64
+
65
+ export function generateColor(address: string): string {
66
+ const hash = XXH.h32(address, 0xABCD).toNumber()
67
+
68
+ const hue = hash % 360
69
+ const saturation = 80 + (hash % 30)
70
+ const lightness = 70 + (hash % 20)
71
+
72
+ return `hsl(${hue}, ${saturation}%, ${lightness}%)`
61
73
  }
package/utils/network.ts CHANGED
@@ -175,7 +175,6 @@ export const networks: Network[] = [
175
175
  params: {
176
176
  chainName: "polygon zkEVM",
177
177
  rpcUrls: ["https://zkevm-rpc.com"],
178
-
179
178
  nativeCurrency: {
180
179
  name: "Ethereum",
181
180
  symbol: "ETH",
@@ -225,6 +224,26 @@ export const networks: Network[] = [
225
224
  decimals: 18,
226
225
  },
227
226
  },
227
+ },
228
+ {
229
+ name: 'Base',
230
+ chainId: 8453,
231
+ color: '#1E2024',
232
+ explorerUrl: 'https://basescan.org',
233
+ get serverRpcUrl() {
234
+ return process.env?.BASE_RPC_URL || this.params.rpcUrls[0];
235
+ },
236
+ usdcAddress: '0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA',
237
+ balanceResolverAddress: '0x23c8EAb8a4373dD16b0947Ebe8bf76Ff7A49d13C',
238
+ params: {
239
+ rpcUrls: ['https://rpc.ankr.com/base'],
240
+ chainName: "Base",
241
+ nativeCurrency: {
242
+ name: "Ethereum",
243
+ symbol: "ETH",
244
+ decimals: 18,
245
+ },
246
+ }
228
247
  },
229
248
  {
230
249
  name: AVO_PROD_CHAIN_NAME,
@@ -268,6 +287,22 @@ export const networks: Network[] = [
268
287
  },
269
288
  ];
270
289
 
290
+ export const chainUsdcAddresses = [
291
+ { chainId: 1, address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48' },
292
+ { chainId: 10, address: '0x7f5c764cbc14f9669b88837ca1490cca17c31607' },
293
+ { chainId: 56, address: '0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d' },
294
+ { chainId: 100, address: '0xddafbb505ad214d7b80b1f830fccc89b60fb7a83' },
295
+ { chainId: 137, address: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174' },
296
+ { chainId: 250, address: '0x04068da6c83afcfa0e13ba15a6696662335d5b75' },
297
+ { chainId: 42161, address: '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8' },
298
+ { chainId: 42161, address: '0xaf88d065e77c8cc2239327c5edb3a432268e5831' },
299
+ { chainId: 43114, address: '0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e' },
300
+ { chainId: 43114, address: '0xa7d7079b0fead91f3e65f86e8915cb59c1a4c664' },
301
+ { chainId: 1101, address: '0xa8ce8aee21bc2a48a5ef670afcc9274c7bbbc035' },
302
+ { chainId: 1313161554, address: '0xB12BFcA5A55806AaF64E99521918A4bf0fC40802' },
303
+ { chainId: 8453, address: '0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA'}
304
+ ];
305
+
271
306
  export const getNetworkByChainId = (
272
307
  chainId: ChainId | number | string
273
308
  ): Network => {
package/utils/services.ts CHANGED
@@ -1,8 +1,15 @@
1
1
  export const fetchTokenByAddress = async (
2
2
  address: string,
3
- chainId: string | number
3
+ chainId: string | number,
4
+ tokens?: ITokenPrice[]
4
5
  ) => {
5
6
  if (!address || !chainId) return null;
7
+
8
+ if (tokens?.length) {
9
+ const token = tokens.find((token) => token.address?.toLocaleLowerCase() === address?.toLocaleLowerCase() && token.chain_id == chainId);
10
+ if (token) return token;
11
+ }
12
+
6
13
  const [token] = (await $fetch(`${blockQueryURL}/${chainId}/tokens`, {
7
14
  params: {
8
15
  sparkline: false,
package/utils/utils.d.ts CHANGED
@@ -11,6 +11,7 @@ declare global {
11
11
  | 250
12
12
  | 634
13
13
  | 1313161554
14
+ | 8453
14
15
  | 63400;
15
16
 
16
17
  type ISlackMessageType = "danger" | "error" | "success" | "banner";