@subwallet/extension-base 1.3.6-1 → 1.3.8-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/background/KoniTypes.d.ts +20 -5
  2. package/background/KoniTypes.js +1 -1
  3. package/cjs/background/KoniTypes.js +1 -1
  4. package/cjs/constants/blocked-actions.js +108 -0
  5. package/cjs/constants/index.js +4 -4
  6. package/cjs/core/substrate/xcm-parser.js +20 -5
  7. package/cjs/koni/api/contract-handler/utils/index.js +15 -1
  8. package/cjs/koni/api/nft/config.js +6 -4
  9. package/cjs/koni/api/nft/index.js +9 -0
  10. package/cjs/koni/api/nft/story_odyssey_nft/index.js +126 -0
  11. package/cjs/koni/background/handlers/Extension.js +64 -4
  12. package/cjs/koni/background/handlers/State.js +23 -2
  13. package/cjs/packageInfo.js +1 -1
  14. package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +2 -1
  15. package/cjs/services/balance-service/transfer/xcm/index.js +31 -1
  16. package/cjs/services/balance-service/transfer/xcm/polygonBridge.js +108 -0
  17. package/cjs/services/chain-online-service/constants.js +32 -0
  18. package/cjs/services/chain-online-service/index.js +190 -0
  19. package/cjs/services/chain-service/constants.js +2 -1
  20. package/cjs/services/chain-service/index.js +87 -127
  21. package/cjs/services/chain-service/utils/index.js +0 -2
  22. package/cjs/services/chain-service/utils/patch.js +7 -3
  23. package/cjs/services/earning-service/handlers/native-staking/para-chain.js +20 -17
  24. package/cjs/services/environment-service/stores/Environment.js +19 -0
  25. package/cjs/services/fee-service/utils/index.js +14 -0
  26. package/cjs/services/inapp-notification-service/consts.js +6 -4
  27. package/cjs/services/inapp-notification-service/index.js +110 -6
  28. package/cjs/services/inapp-notification-service/interfaces.js +9 -1
  29. package/cjs/services/inapp-notification-service/utils/avail.js +88 -0
  30. package/cjs/services/inapp-notification-service/{utils.js → utils/common.js} +1 -84
  31. package/cjs/services/inapp-notification-service/utils/index.js +38 -0
  32. package/cjs/services/inapp-notification-service/utils/polygon.js +66 -0
  33. package/cjs/services/migration-service/scripts/MigrateTransactionHistoryBridge.js +37 -0
  34. package/cjs/services/migration-service/scripts/index.js +3 -1
  35. package/cjs/services/setting-service/SettingService.js +21 -0
  36. package/cjs/services/setting-service/constants.js +2 -1
  37. package/cjs/services/storage-service/DatabaseService.js +3 -0
  38. package/cjs/services/transaction-service/index.js +13 -7
  39. package/cjs/services/transaction-service/utils.js +3 -0
  40. package/cjs/stores/ChainlistStore.js +18 -0
  41. package/cjs/stores/EnvironmentStore.js +18 -0
  42. package/cjs/stores/index.js +8 -1
  43. package/cjs/types/index.js +11 -0
  44. package/cjs/utils/account/transform.js +1 -1
  45. package/cjs/utils/environment.js +15 -1
  46. package/cjs/utils/staticData/index.js +7 -2
  47. package/constants/blocked-actions.d.ts +29 -0
  48. package/constants/blocked-actions.js +96 -0
  49. package/constants/index.d.ts +1 -1
  50. package/constants/index.js +1 -1
  51. package/core/substrate/xcm-parser.d.ts +2 -1
  52. package/core/substrate/xcm-parser.js +19 -5
  53. package/koni/api/contract-handler/utils/index.d.ts +2 -0
  54. package/koni/api/contract-handler/utils/index.js +12 -0
  55. package/koni/api/contract-handler/utils/polygon_bridge_abi.json +1004 -0
  56. package/koni/api/nft/config.d.ts +1 -1
  57. package/koni/api/nft/config.js +5 -2
  58. package/koni/api/nft/index.js +9 -0
  59. package/koni/api/nft/story_odyssey_nft/index.d.ts +40 -0
  60. package/koni/api/nft/story_odyssey_nft/index.js +119 -0
  61. package/koni/background/handlers/Extension.d.ts +5 -0
  62. package/koni/background/handlers/Extension.js +65 -5
  63. package/koni/background/handlers/State.d.ts +5 -0
  64. package/koni/background/handlers/State.js +23 -2
  65. package/package.json +76 -18
  66. package/packageInfo.js +1 -1
  67. package/services/balance-service/helpers/subscribe/substrate/index.js +2 -1
  68. package/services/balance-service/transfer/xcm/index.d.ts +1 -0
  69. package/services/balance-service/transfer/xcm/index.js +29 -1
  70. package/services/balance-service/transfer/xcm/polygonBridge.d.ts +22 -0
  71. package/services/balance-service/transfer/xcm/polygonBridge.js +95 -0
  72. package/services/chain-online-service/constants.d.ts +4 -0
  73. package/services/chain-online-service/constants.js +23 -0
  74. package/services/chain-online-service/index.d.ts +22 -0
  75. package/services/chain-online-service/index.js +182 -0
  76. package/services/chain-service/constants.d.ts +1 -0
  77. package/services/chain-service/constants.js +2 -1
  78. package/services/chain-service/index.d.ts +6 -7
  79. package/services/chain-service/index.js +78 -116
  80. package/services/chain-service/utils/index.js +0 -2
  81. package/services/chain-service/utils/patch.d.ts +16 -1
  82. package/services/chain-service/utils/patch.js +7 -3
  83. package/services/earning-service/handlers/native-staking/para-chain.js +20 -17
  84. package/services/environment-service/stores/Environment.d.ts +10 -0
  85. package/services/environment-service/stores/Environment.js +12 -0
  86. package/services/fee-service/utils/index.js +14 -0
  87. package/services/inapp-notification-service/consts.d.ts +3 -1
  88. package/services/inapp-notification-service/consts.js +6 -4
  89. package/services/inapp-notification-service/index.d.ts +10 -2
  90. package/services/inapp-notification-service/index.js +111 -7
  91. package/services/inapp-notification-service/interfaces.d.ts +27 -3
  92. package/services/inapp-notification-service/interfaces.js +7 -0
  93. package/services/inapp-notification-service/utils/avail.d.ts +40 -0
  94. package/services/inapp-notification-service/utils/avail.js +73 -0
  95. package/services/inapp-notification-service/utils/common.d.ts +11 -0
  96. package/services/inapp-notification-service/{utils.js → utils/common.js} +1 -72
  97. package/services/inapp-notification-service/utils/index.d.ts +3 -0
  98. package/services/inapp-notification-service/utils/index.js +6 -0
  99. package/services/inapp-notification-service/utils/polygon.d.ts +71 -0
  100. package/services/inapp-notification-service/utils/polygon.js +54 -0
  101. package/services/migration-service/scripts/MigrateTransactionHistoryBridge.d.ts +4 -0
  102. package/services/migration-service/scripts/MigrateTransactionHistoryBridge.js +29 -0
  103. package/services/migration-service/scripts/index.js +3 -1
  104. package/services/setting-service/SettingService.d.ts +9 -0
  105. package/services/setting-service/SettingService.js +21 -0
  106. package/services/setting-service/constants.js +2 -1
  107. package/services/storage-service/DatabaseService.d.ts +1 -0
  108. package/services/storage-service/DatabaseService.js +3 -0
  109. package/services/transaction-service/index.js +14 -8
  110. package/services/transaction-service/utils.js +3 -0
  111. package/stores/ChainlistStore.d.ts +7 -0
  112. package/stores/ChainlistStore.js +10 -0
  113. package/stores/EnvironmentStore.d.ts +5 -0
  114. package/stores/EnvironmentStore.js +10 -0
  115. package/stores/index.d.ts +1 -0
  116. package/stores/index.js +2 -1
  117. package/types/{avail-bridge → bridge}/index.d.ts +1 -1
  118. package/types/index.d.ts +1 -0
  119. package/types/index.js +1 -0
  120. package/types/notification/index.d.ts +5 -0
  121. package/utils/account/transform.js +1 -1
  122. package/utils/environment.d.ts +6 -0
  123. package/utils/environment.js +8 -0
  124. package/utils/staticData/blockedActions.json +1 -0
  125. package/utils/staticData/index.d.ts +7 -3
  126. package/utils/staticData/index.js +5 -1
  127. package/cjs/constants/blocked-actions-list.js +0 -14
  128. package/constants/blocked-actions-list.d.ts +0 -7
  129. package/constants/blocked-actions-list.js +0 -7
  130. package/services/inapp-notification-service/utils.d.ts +0 -55
  131. /package/cjs/types/{avail-bridge → bridge}/index.js +0 -0
  132. /package/types/{avail-bridge → bridge}/index.js +0 -0
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "./cjs/detectPackage.js"
18
18
  ],
19
19
  "type": "module",
20
- "version": "1.3.6-1",
20
+ "version": "1.3.8-0",
21
21
  "main": "./cjs/index.js",
22
22
  "module": "./index.js",
23
23
  "types": "./index.d.ts",
@@ -114,10 +114,10 @@
114
114
  "require": "./cjs/constants/index.js",
115
115
  "default": "./constants/index.js"
116
116
  },
117
- "./constants/blocked-actions-list": {
118
- "types": "./constants/blocked-actions-list.d.ts",
119
- "require": "./cjs/constants/blocked-actions-list.js",
120
- "default": "./constants/blocked-actions-list.js"
117
+ "./constants/blocked-actions": {
118
+ "types": "./constants/blocked-actions.d.ts",
119
+ "require": "./cjs/constants/blocked-actions.js",
120
+ "default": "./constants/blocked-actions.js"
121
121
  },
122
122
  "./constants/environment": {
123
123
  "types": "./constants/environment.d.ts",
@@ -271,6 +271,7 @@
271
271
  "./koni/api/contract-handler/utils/erc721_abi.json": "./koni/api/contract-handler/utils/erc721_abi.json",
272
272
  "./koni/api/contract-handler/utils/neuroguns_psp34_abi.json": "./koni/api/contract-handler/utils/neuroguns_psp34_abi.json",
273
273
  "./koni/api/contract-handler/utils/pink_psp34_abi.json": "./koni/api/contract-handler/utils/pink_psp34_abi.json",
274
+ "./koni/api/contract-handler/utils/polygon_bridge_abi.json": "./koni/api/contract-handler/utils/polygon_bridge_abi.json",
274
275
  "./koni/api/contract-handler/utils/psp22_abi.json": "./koni/api/contract-handler/utils/psp22_abi.json",
275
276
  "./koni/api/contract-handler/utils/psp34_abi.json": "./koni/api/contract-handler/utils/psp34_abi.json",
276
277
  "./koni/api/contract-handler/utils/snowbridge_gateway_abi.json": "./koni/api/contract-handler/utils/snowbridge_gateway_abi.json",
@@ -400,6 +401,11 @@
400
401
  "require": "./cjs/koni/api/nft/rmrk_nft/index.js",
401
402
  "default": "./koni/api/nft/rmrk_nft/index.js"
402
403
  },
404
+ "./koni/api/nft/story_odyssey_nft": {
405
+ "types": "./koni/api/nft/story_odyssey_nft/index.d.ts",
406
+ "require": "./cjs/koni/api/nft/story_odyssey_nft/index.js",
407
+ "default": "./koni/api/nft/story_odyssey_nft/index.js"
408
+ },
403
409
  "./koni/api/nft/ternoa_nft": {
404
410
  "types": "./koni/api/nft/ternoa_nft/index.d.ts",
405
411
  "require": "./cjs/koni/api/nft/ternoa_nft/index.js",
@@ -711,6 +717,11 @@
711
717
  "require": "./cjs/services/balance-service/transfer/xcm/polkadotXcm.js",
712
718
  "default": "./services/balance-service/transfer/xcm/polkadotXcm.js"
713
719
  },
720
+ "./services/balance-service/transfer/xcm/polygonBridge": {
721
+ "types": "./services/balance-service/transfer/xcm/polygonBridge.d.ts",
722
+ "require": "./cjs/services/balance-service/transfer/xcm/polygonBridge.js",
723
+ "default": "./services/balance-service/transfer/xcm/polygonBridge.js"
724
+ },
714
725
  "./services/balance-service/transfer/xcm/snowBridge": {
715
726
  "types": "./services/balance-service/transfer/xcm/snowBridge.d.ts",
716
727
  "require": "./cjs/services/balance-service/transfer/xcm/snowBridge.js",
@@ -771,6 +782,16 @@
771
782
  "require": "./cjs/services/campaign-service/types.js",
772
783
  "default": "./services/campaign-service/types.js"
773
784
  },
785
+ "./services/chain-online-service": {
786
+ "types": "./services/chain-online-service/index.d.ts",
787
+ "require": "./cjs/services/chain-online-service/index.js",
788
+ "default": "./services/chain-online-service/index.js"
789
+ },
790
+ "./services/chain-online-service/constants": {
791
+ "types": "./services/chain-online-service/constants.d.ts",
792
+ "require": "./cjs/services/chain-online-service/constants.js",
793
+ "default": "./services/chain-online-service/constants.js"
794
+ },
774
795
  "./services/chain-service": {
775
796
  "types": "./services/chain-service/index.d.ts",
776
797
  "require": "./cjs/services/chain-service/index.js",
@@ -1043,6 +1064,11 @@
1043
1064
  "require": "./cjs/services/earning-service/utils/index.js",
1044
1065
  "default": "./services/earning-service/utils/index.js"
1045
1066
  },
1067
+ "./services/environment-service/stores/Environment": {
1068
+ "types": "./services/environment-service/stores/Environment.d.ts",
1069
+ "require": "./cjs/services/environment-service/stores/Environment.js",
1070
+ "default": "./services/environment-service/stores/Environment.js"
1071
+ },
1046
1072
  "./services/event-service": {
1047
1073
  "types": "./services/event-service/index.d.ts",
1048
1074
  "require": "./cjs/services/event-service/index.js",
@@ -1114,9 +1140,24 @@
1114
1140
  "default": "./services/inapp-notification-service/interfaces.js"
1115
1141
  },
1116
1142
  "./services/inapp-notification-service/utils": {
1117
- "types": "./services/inapp-notification-service/utils.d.ts",
1118
- "require": "./cjs/services/inapp-notification-service/utils.js",
1119
- "default": "./services/inapp-notification-service/utils.js"
1143
+ "types": "./services/inapp-notification-service/utils/index.d.ts",
1144
+ "require": "./cjs/services/inapp-notification-service/utils/index.js",
1145
+ "default": "./services/inapp-notification-service/utils/index.js"
1146
+ },
1147
+ "./services/inapp-notification-service/utils/avail": {
1148
+ "types": "./services/inapp-notification-service/utils/avail.d.ts",
1149
+ "require": "./cjs/services/inapp-notification-service/utils/avail.js",
1150
+ "default": "./services/inapp-notification-service/utils/avail.js"
1151
+ },
1152
+ "./services/inapp-notification-service/utils/common": {
1153
+ "types": "./services/inapp-notification-service/utils/common.d.ts",
1154
+ "require": "./cjs/services/inapp-notification-service/utils/common.js",
1155
+ "default": "./services/inapp-notification-service/utils/common.js"
1156
+ },
1157
+ "./services/inapp-notification-service/utils/polygon": {
1158
+ "types": "./services/inapp-notification-service/utils/polygon.d.ts",
1159
+ "require": "./cjs/services/inapp-notification-service/utils/polygon.js",
1160
+ "default": "./services/inapp-notification-service/utils/polygon.js"
1120
1161
  },
1121
1162
  "./services/keyring-service": {
1122
1163
  "types": "./services/keyring-service/index.d.ts",
@@ -1348,6 +1389,11 @@
1348
1389
  "require": "./cjs/services/migration-service/scripts/MigrateTransactionHistory.js",
1349
1390
  "default": "./services/migration-service/scripts/MigrateTransactionHistory.js"
1350
1391
  },
1392
+ "./services/migration-service/scripts/MigrateTransactionHistoryBridge": {
1393
+ "types": "./services/migration-service/scripts/MigrateTransactionHistoryBridge.d.ts",
1394
+ "require": "./cjs/services/migration-service/scripts/MigrateTransactionHistoryBridge.js",
1395
+ "default": "./services/migration-service/scripts/MigrateTransactionHistoryBridge.js"
1396
+ },
1351
1397
  "./services/migration-service/scripts/MigrateTransactionHistoryBySymbol": {
1352
1398
  "types": "./services/migration-service/scripts/MigrateTransactionHistoryBySymbol.d.ts",
1353
1399
  "require": "./cjs/services/migration-service/scripts/MigrateTransactionHistoryBySymbol.js",
@@ -1838,6 +1884,11 @@
1838
1884
  "require": "./cjs/stores/Base.js",
1839
1885
  "default": "./stores/Base.js"
1840
1886
  },
1887
+ "./stores/ChainlistStore": {
1888
+ "types": "./stores/ChainlistStore.d.ts",
1889
+ "require": "./cjs/stores/ChainlistStore.js",
1890
+ "default": "./stores/ChainlistStore.js"
1891
+ },
1841
1892
  "./stores/CurrentAccountStore": {
1842
1893
  "types": "./stores/CurrentAccountStore.d.ts",
1843
1894
  "require": "./cjs/stores/CurrentAccountStore.js",
@@ -1853,6 +1904,11 @@
1853
1904
  "require": "./cjs/stores/DetectAccountBalance.js",
1854
1905
  "default": "./stores/DetectAccountBalance.js"
1855
1906
  },
1907
+ "./stores/EnvironmentStore": {
1908
+ "types": "./stores/EnvironmentStore.d.ts",
1909
+ "require": "./cjs/stores/EnvironmentStore.js",
1910
+ "default": "./stores/EnvironmentStore.js"
1911
+ },
1856
1912
  "./stores/Keyring": {
1857
1913
  "types": "./stores/Keyring.d.ts",
1858
1914
  "require": "./cjs/stores/Keyring.js",
@@ -1993,16 +2049,16 @@
1993
2049
  "require": "./cjs/types/account/info/proxy.js",
1994
2050
  "default": "./types/account/info/proxy.js"
1995
2051
  },
1996
- "./types/avail-bridge": {
1997
- "types": "./types/avail-bridge/index.d.ts",
1998
- "require": "./cjs/types/avail-bridge/index.js",
1999
- "default": "./types/avail-bridge/index.js"
2000
- },
2001
2052
  "./types/balance": {
2002
2053
  "types": "./types/balance/index.d.ts",
2003
2054
  "require": "./cjs/types/balance/index.js",
2004
2055
  "default": "./types/balance/index.js"
2005
2056
  },
2057
+ "./types/bridge": {
2058
+ "types": "./types/bridge/index.d.ts",
2059
+ "require": "./cjs/types/bridge/index.js",
2060
+ "default": "./types/bridge/index.js"
2061
+ },
2006
2062
  "./types/buy": {
2007
2063
  "types": "./types/buy.d.ts",
2008
2064
  "require": "./cjs/types/buy.js",
@@ -2378,6 +2434,7 @@
2378
2434
  "require": "./cjs/utils/staticData/index.js",
2379
2435
  "default": "./utils/staticData/index.js"
2380
2436
  },
2437
+ "./utils/staticData/blockedActions.json": "./utils/staticData/blockedActions.json",
2381
2438
  "./utils/staticData/blockedActionsFeatures.json": "./utils/staticData/blockedActionsFeatures.json",
2382
2439
  "./utils/staticData/buyServiceInfos.json": "./utils/staticData/buyServiceInfos.json",
2383
2440
  "./utils/staticData/buyTokenConfigs.json": "./utils/staticData/buyTokenConfigs.json",
@@ -2434,11 +2491,11 @@
2434
2491
  "@reduxjs/toolkit": "^1.9.1",
2435
2492
  "@sora-substrate/type-definitions": "^1.17.7",
2436
2493
  "@substrate/connect": "^0.8.9",
2437
- "@subwallet/chain-list": "0.2.93",
2438
- "@subwallet/extension-base": "^1.3.6-1",
2439
- "@subwallet/extension-chains": "^1.3.6-1",
2440
- "@subwallet/extension-dapp": "^1.3.6-1",
2441
- "@subwallet/extension-inject": "^1.3.6-1",
2494
+ "@subwallet/chain-list": "0.2.95-beta.1",
2495
+ "@subwallet/extension-base": "^1.3.8-0",
2496
+ "@subwallet/extension-chains": "^1.3.8-0",
2497
+ "@subwallet/extension-dapp": "^1.3.8-0",
2498
+ "@subwallet/extension-inject": "^1.3.8-0",
2442
2499
  "@subwallet/keyring": "^0.1.8-beta.0",
2443
2500
  "@subwallet/ui-keyring": "^0.1.8-beta.0",
2444
2501
  "@ton/core": "^0.56.3",
@@ -2472,6 +2529,7 @@
2472
2529
  "protobufjs": "^7.2.4",
2473
2530
  "rxjs": "^7.8.1",
2474
2531
  "sails-js": "^0.1.6",
2532
+ "ts-md5": "^1.3.1",
2475
2533
  "tweetnacl": "^1.0.3",
2476
2534
  "uuid": "^9.0.0",
2477
2535
  "web3": "^1.10.0",
package/packageInfo.js CHANGED
@@ -7,5 +7,5 @@ export const packageInfo = {
7
7
  name: '@subwallet/extension-base',
8
8
  path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
9
9
  type: 'esm',
10
- version: '1.3.6-1'
10
+ version: '1.3.8-0'
11
11
  };
@@ -192,11 +192,12 @@ const subscribeForeignAssetBalance = async ({
192
192
  const unsubList = await Promise.all(Object.values(tokenMap).map(tokenInfo => {
193
193
  try {
194
194
  if (_isBridgedToken(tokenInfo)) {
195
+ const version = ['statemint', 'statemine'].includes(chainInfo.slug) ? 4 : 3;
195
196
  const params = [{
196
197
  section: 'query',
197
198
  module: foreignAssetsAccountKey.split('_')[1],
198
199
  method: foreignAssetsAccountKey.split('_')[2],
199
- args: addresses.map(address => [_getTokenOnChainInfo(tokenInfo) || _adaptX1Interior(_getXcmAssetMultilocation(tokenInfo), 3), address])
200
+ args: addresses.map(address => [_getTokenOnChainInfo(tokenInfo) || _adaptX1Interior(_getXcmAssetMultilocation(tokenInfo), version), address])
200
201
  }];
201
202
  return substrateApi.subscribeDataWithMulti(params, rs => {
202
203
  const balances = rs[foreignAssetsAccountKey];
@@ -18,4 +18,5 @@ export declare const createSnowBridgeExtrinsic: ({ chainInfoMap, destinationToke
18
18
  export declare const createXcmExtrinsic: ({ chainInfoMap, destinationTokenInfo, originTokenInfo, recipient, sendingValue, substrateApi }: CreateXcmExtrinsicProps) => Promise<SubmittableExtrinsic<'promise'>>;
19
19
  export declare const createAvailBridgeTxFromEth: ({ chainInfoMap, evmApi, originTokenInfo, recipient, sender, sendingValue }: CreateXcmExtrinsicProps) => Promise<TransactionConfig>;
20
20
  export declare const createAvailBridgeExtrinsicFromAvail: ({ recipient, sendingValue, substrateApi }: CreateXcmExtrinsicProps) => Promise<SubmittableExtrinsic<'promise'>>;
21
+ export declare const createPolygonBridgeExtrinsic: ({ chainInfoMap, destinationTokenInfo, evmApi, originTokenInfo, recipient, sender, sendingValue }: CreateXcmExtrinsicProps) => Promise<TransactionConfig>;
21
22
  export declare const getXcmMockTxFee: (substrateApi: _SubstrateApi, chainInfoMap: Record<string, _ChainInfo>, originTokenInfo: _ChainAsset, destinationTokenInfo: _ChainAsset) => Promise<BigN>;
@@ -1,9 +1,10 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { _isSnowBridgeXcm } from '@subwallet/extension-base/core/substrate/xcm-parser';
4
+ import { _isPolygonBridgeXcm, _isSnowBridgeXcm } from '@subwallet/extension-base/core/substrate/xcm-parser';
5
5
  import { getAvailBridgeExtrinsicFromAvail, getAvailBridgeTxFromEth } from '@subwallet/extension-base/services/balance-service/transfer/xcm/availBridge';
6
6
  import { getExtrinsicByPolkadotXcmPallet } from '@subwallet/extension-base/services/balance-service/transfer/xcm/polkadotXcm';
7
+ import { _createPolygonBridgeL1toL2Extrinsic, _createPolygonBridgeL2toL1Extrinsic } from '@subwallet/extension-base/services/balance-service/transfer/xcm/polygonBridge';
7
8
  import { getSnowBridgeEvmTransfer } from '@subwallet/extension-base/services/balance-service/transfer/xcm/snowBridge';
8
9
  import { getExtrinsicByXcmPalletPallet } from '@subwallet/extension-base/services/balance-service/transfer/xcm/xcmPallet';
9
10
  import { getExtrinsicByXtokensPallet } from '@subwallet/extension-base/services/balance-service/transfer/xcm/xTokens';
@@ -85,6 +86,33 @@ export const createAvailBridgeExtrinsicFromAvail = async ({
85
86
  }
86
87
  return await getAvailBridgeExtrinsicFromAvail(recipient, sendingValue, substrateApi);
87
88
  };
89
+ export const createPolygonBridgeExtrinsic = async ({
90
+ chainInfoMap,
91
+ destinationTokenInfo,
92
+ evmApi,
93
+ originTokenInfo,
94
+ recipient,
95
+ sender,
96
+ sendingValue
97
+ }) => {
98
+ const originChainInfo = chainInfoMap[originTokenInfo.originChain];
99
+ const destinationChainInfo = chainInfoMap[destinationTokenInfo.originChain];
100
+ if (!_isPolygonBridgeXcm(originChainInfo, destinationChainInfo)) {
101
+ throw new Error('This is not a valid PolygonBridge transfer');
102
+ }
103
+ if (!evmApi) {
104
+ throw Error('Evm API is not available');
105
+ }
106
+ if (!sender) {
107
+ throw Error('Sender is required');
108
+ }
109
+ const sourceChain = originChainInfo.slug;
110
+ if (sourceChain === 'polygonzkEvm_cardona' || sourceChain === 'polygonZkEvm') {
111
+ return _createPolygonBridgeL2toL1Extrinsic(originTokenInfo, originChainInfo, sender, recipient, sendingValue, evmApi);
112
+ } else {
113
+ return _createPolygonBridgeL1toL2Extrinsic(originTokenInfo, originChainInfo, sender, recipient, sendingValue, evmApi);
114
+ }
115
+ };
88
116
  export const getXcmMockTxFee = async (substrateApi, chainInfoMap, originTokenInfo, destinationTokenInfo) => {
89
117
  try {
90
118
  var _paymentInfo$partialF;
@@ -0,0 +1,22 @@
1
+ import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
2
+ import { _EvmApi } from '@subwallet/extension-base/services/chain-service/types';
3
+ import { _NotificationInfo } from '@subwallet/extension-base/services/inapp-notification-service/interfaces';
4
+ import { TransactionConfig } from 'web3-core';
5
+ export interface gasStation {
6
+ safeLow: number;
7
+ standard: number;
8
+ fastLow: number;
9
+ }
10
+ export declare const POLYGON_PROOF_INDEXER: {
11
+ MAINNET: string;
12
+ TESTNET: string;
13
+ };
14
+ export declare const POLYGON_GAS_INDEXER: {
15
+ MAINNET: string;
16
+ TESTNET: string;
17
+ };
18
+ export declare function _createPolygonBridgeL1toL2Extrinsic(tokenInfo: _ChainAsset, originChainInfo: _ChainInfo, sender: string, recipientAddress: string, value: string, evmApi: _EvmApi): Promise<TransactionConfig>;
19
+ export declare function _createPolygonBridgeL2toL1Extrinsic(tokenInfo: _ChainAsset, originChainInfo: _ChainInfo, sender: string, recipientAddress: string, value: string, evmApi: _EvmApi): Promise<TransactionConfig>;
20
+ export declare function getClaimPolygonBridge(chainSlug: string, notification: _NotificationInfo, evmApi: _EvmApi): Promise<TransactionConfig>;
21
+ export declare function isClaimedPolygonBridge(chainSlug: string, counter: number, sourceNetwork: number, evmApi: _EvmApi): Promise<any>;
22
+ export declare function _isPolygonChainBridge(srcChain: string, destChain: string): boolean;
@@ -0,0 +1,95 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { COMMON_CHAIN_SLUGS } from '@subwallet/chain-list';
5
+ import { getWeb3Contract } from '@subwallet/extension-base/koni/api/contract-handler/evm/web3';
6
+ import { _POLYGON_BRIDGE_ABI, getPolygonBridgeContract } from '@subwallet/extension-base/koni/api/contract-handler/utils';
7
+ import { _getContractAddressOfToken } from '@subwallet/extension-base/services/chain-service/utils';
8
+ import { calculateGasFeeParams } from '@subwallet/extension-base/services/fee-service/utils';
9
+ export const POLYGON_PROOF_INDEXER = {
10
+ MAINNET: 'https://api-gateway.polygon.technology/api/v3/proof/mainnet/merkle-proof',
11
+ TESTNET: 'https://api-gateway.polygon.technology/api/v3/proof/testnet/merkle-proof'
12
+ };
13
+ export const POLYGON_GAS_INDEXER = {
14
+ MAINNET: 'https://gasstation.polygon.technology/zkevm',
15
+ TESTNET: 'https://gasstation.polygon.technology/zkevm/cardona'
16
+ };
17
+ async function createPolygonBridgeTransaction(tokenInfo, originChainInfo, sender, recipientAddress, value, destinationNetwork, evmApi) {
18
+ var _priority$maxFeePerGa, _priority$maxPriority;
19
+ const polygonBridgeContractAddress = getPolygonBridgeContract(originChainInfo.slug);
20
+ const polygonBridgeContract = getWeb3Contract(polygonBridgeContractAddress, evmApi, _POLYGON_BRIDGE_ABI);
21
+ const tokenContract = _getContractAddressOfToken(tokenInfo) || '0x0000000000000000000000000000000000000000'; // FOR Ethereum: use null address
22
+
23
+ if (tokenContract !== '0x0000000000000000000000000000000000000000') {
24
+ throw new Error('Only native token transfer is supported');
25
+ }
26
+
27
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
28
+ const transferCall = polygonBridgeContract.methods.bridgeAsset(destinationNetwork, recipientAddress, value, tokenContract, true, '0x');
29
+ const transferEncodedCall = transferCall.encodeABI();
30
+ const priority = await calculateGasFeeParams(evmApi, evmApi.chainSlug);
31
+ const transactionConfig = {
32
+ from: sender,
33
+ to: polygonBridgeContractAddress,
34
+ value: value,
35
+ data: transferEncodedCall,
36
+ gasPrice: priority.gasPrice,
37
+ maxFeePerGas: priority === null || priority === void 0 ? void 0 : (_priority$maxFeePerGa = priority.maxFeePerGas) === null || _priority$maxFeePerGa === void 0 ? void 0 : _priority$maxFeePerGa.toString(),
38
+ maxPriorityFeePerGas: priority === null || priority === void 0 ? void 0 : (_priority$maxPriority = priority.maxPriorityFeePerGas) === null || _priority$maxPriority === void 0 ? void 0 : _priority$maxPriority.toString()
39
+ };
40
+ const gasLimit = await evmApi.api.eth.estimateGas(transactionConfig).catch(() => 200000);
41
+ transactionConfig.gas = gasLimit.toString();
42
+ return transactionConfig;
43
+ }
44
+ export async function _createPolygonBridgeL1toL2Extrinsic(tokenInfo, originChainInfo, sender, recipientAddress, value, evmApi) {
45
+ return createPolygonBridgeTransaction(tokenInfo, originChainInfo, sender, recipientAddress, value, 1, evmApi);
46
+ }
47
+ export async function _createPolygonBridgeL2toL1Extrinsic(tokenInfo, originChainInfo, sender, recipientAddress, value, evmApi) {
48
+ return createPolygonBridgeTransaction(tokenInfo, originChainInfo, sender, recipientAddress, value, 0, evmApi);
49
+ }
50
+ export async function getClaimPolygonBridge(chainSlug, notification, evmApi) {
51
+ var _priority$maxFeePerGa2, _priority$maxPriority2;
52
+ const polygonBridgeContractAddress = getPolygonBridgeContract(chainSlug);
53
+ const polygonBridgeContract = getWeb3Contract(polygonBridgeContractAddress, evmApi, _POLYGON_BRIDGE_ABI);
54
+ const metadata = notification.metadata;
55
+ const isTestnet = chainSlug === COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA;
56
+ const proofDomain = isTestnet ? POLYGON_PROOF_INDEXER.TESTNET : POLYGON_PROOF_INDEXER.MAINNET;
57
+ const proofResponse = await fetch(`${proofDomain}?networkId=${metadata.sourceNetwork}&depositCount=${metadata.counter}`).then(res => res.json());
58
+ const proof = proofResponse.proof;
59
+
60
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
61
+ const transferCall = polygonBridgeContract.methods.claimAsset(proof.merkle_proof, proof.rollup_merkle_proof, metadata.counter, proof.main_exit_root, proof.rollup_exit_root, metadata.originTokenNetwork, metadata.originTokenAddress, metadata.destinationNetwork, metadata.receiver, metadata.amounts[0], '0x');
62
+ const transferEncodedCall = transferCall.encodeABI();
63
+ const priority = await calculateGasFeeParams(evmApi, evmApi.chainSlug);
64
+ const transactionConfig = {
65
+ from: metadata.userAddress,
66
+ to: polygonBridgeContractAddress,
67
+ value: '0',
68
+ data: transferEncodedCall,
69
+ gasPrice: priority.gasPrice,
70
+ maxFeePerGas: (_priority$maxFeePerGa2 = priority.maxFeePerGas) === null || _priority$maxFeePerGa2 === void 0 ? void 0 : _priority$maxFeePerGa2.toString(),
71
+ maxPriorityFeePerGas: (_priority$maxPriority2 = priority.maxPriorityFeePerGas) === null || _priority$maxPriority2 === void 0 ? void 0 : _priority$maxPriority2.toString()
72
+ };
73
+ const gasLimit = await evmApi.api.eth.estimateGas(transactionConfig).catch(() => 200000);
74
+ transactionConfig.gas = gasLimit.toString();
75
+ return transactionConfig;
76
+ }
77
+ export async function isClaimedPolygonBridge(chainSlug, counter, sourceNetwork, evmApi) {
78
+ const polygonBridgeContractAddress = getPolygonBridgeContract(chainSlug);
79
+ const polygonBridgeContract = getWeb3Contract(polygonBridgeContractAddress, evmApi, _POLYGON_BRIDGE_ABI);
80
+
81
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-return,@typescript-eslint/no-unsafe-member-access
82
+ return await polygonBridgeContract.methods.isClaimed(counter, sourceNetwork).call();
83
+ }
84
+ export function _isPolygonChainBridge(srcChain, destChain) {
85
+ if (srcChain === 'polygonzkEvm_cardona' && destChain === COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA) {
86
+ return true;
87
+ } else if (srcChain === COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA && destChain === 'polygonzkEvm_cardona') {
88
+ return true;
89
+ } else if (srcChain === 'polygonZkEvm' && destChain === COMMON_CHAIN_SLUGS.ETHEREUM) {
90
+ return true;
91
+ } else if (srcChain === COMMON_CHAIN_SLUGS.ETHEREUM && destChain === 'polygonZkEvm') {
92
+ return true;
93
+ }
94
+ return false;
95
+ }
@@ -0,0 +1,4 @@
1
+ import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
2
+ export declare const LATEST_CHAIN_PATCH_FETCHING_INTERVAL = 180000;
3
+ export declare function md5HashChainInfo(data: _ChainInfo): string;
4
+ export declare function md5HashChainAsset(data: _ChainAsset): string;
@@ -0,0 +1,23 @@
1
+ // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { Md5 } from 'ts-md5';
5
+ export const LATEST_CHAIN_PATCH_FETCHING_INTERVAL = 180000;
6
+ export function md5HashChainInfo(data) {
7
+ // todo: use from chain list package later
8
+ const {
9
+ chainStatus,
10
+ icon,
11
+ providers,
12
+ ...chainBaseInfo
13
+ } = data;
14
+ return Md5.hashStr(JSON.stringify(chainBaseInfo));
15
+ }
16
+ export function md5HashChainAsset(data) {
17
+ // todo: use from chain list package later
18
+ const {
19
+ icon,
20
+ ...assetBaseInfo
21
+ } = data;
22
+ return Md5.hashStr(JSON.stringify(assetBaseInfo));
23
+ }
@@ -0,0 +1,22 @@
1
+ /// <reference types="node" />
2
+ import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
3
+ import { ChainService } from '@subwallet/extension-base/services/chain-service';
4
+ import { PatchInfo } from '@subwallet/extension-base/services/chain-service/utils';
5
+ import { EventService } from '@subwallet/extension-base/services/event-service';
6
+ import SettingService from '@subwallet/extension-base/services/setting-service/SettingService';
7
+ import DatabaseService from '@subwallet/extension-base/services/storage-service/DatabaseService';
8
+ export declare class ChainOnlineService {
9
+ private chainService;
10
+ private settingService;
11
+ private eventService;
12
+ private dbService;
13
+ private firstApplied;
14
+ refreshLatestChainDataTimeOut: NodeJS.Timer | undefined;
15
+ constructor(chainService: ChainService, settingService: SettingService, eventService: EventService, dbService: DatabaseService);
16
+ validatePatchWithHash(latestPatch: PatchInfo): boolean;
17
+ validatePatchBeforeStore(candidateChainInfoMap: Record<string, _ChainInfo>, candidateAssetRegistry: Record<string, _ChainAsset>, latestPatch: PatchInfo): boolean;
18
+ handleLatestPatch(latestPatch: PatchInfo): Promise<void>;
19
+ private fetchLatestPatchData;
20
+ handleLatestPatchData(): void;
21
+ checkLatestData(): void;
22
+ }
@@ -0,0 +1,182 @@
1
+ // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { AssetLogoMap, ChainLogoMap } from '@subwallet/chain-list';
5
+ import { LATEST_CHAIN_PATCH_FETCHING_INTERVAL, md5HashChainAsset, md5HashChainInfo } from '@subwallet/extension-base/services/chain-online-service/constants';
6
+ import { filterAssetInfoMap } from '@subwallet/extension-base/services/chain-service';
7
+ import { _ChainConnectionStatus } from '@subwallet/extension-base/services/chain-service/types';
8
+ import { fetchPatchData, randomizeProvider } from '@subwallet/extension-base/services/chain-service/utils';
9
+ export class ChainOnlineService {
10
+ constructor(chainService, settingService, eventService, dbService) {
11
+ this.chainService = chainService;
12
+ this.settingService = settingService;
13
+ this.eventService = eventService;
14
+ this.dbService = dbService;
15
+ this.firstApplied = false;
16
+ }
17
+ validatePatchWithHash(latestPatch) {
18
+ const {
19
+ ChainAsset,
20
+ ChainAssetHashMap,
21
+ ChainInfo,
22
+ ChainInfoHashMap
23
+ } = latestPatch;
24
+ for (const [chainSlug, chain] of Object.entries(ChainInfo)) {
25
+ if (md5HashChainInfo(chain) !== ChainInfoHashMap[chainSlug]) {
26
+ return false;
27
+ }
28
+ }
29
+ for (const [assetSlug, asset] of Object.entries(ChainAsset)) {
30
+ if (md5HashChainAsset(asset) !== ChainAssetHashMap[assetSlug]) {
31
+ return false;
32
+ }
33
+ }
34
+ return true;
35
+ }
36
+ validatePatchBeforeStore(candidateChainInfoMap, candidateAssetRegistry, latestPatch) {
37
+ for (const [chainSlug, chainHash] of Object.entries(latestPatch.ChainInfoHashMap)) {
38
+ if (md5HashChainInfo(candidateChainInfoMap[chainSlug]) !== chainHash) {
39
+ return false;
40
+ }
41
+ }
42
+ for (const [assetSlug, assetHash] of Object.entries(latestPatch.ChainAssetHashMap)) {
43
+ if (!candidateAssetRegistry[assetSlug]) {
44
+ if (!latestPatch.ChainInfo[assetSlug]) {
45
+ // assets are not existed in case chain is removed
46
+ continue;
47
+ }
48
+ return false;
49
+ }
50
+ if (md5HashChainAsset(candidateAssetRegistry[assetSlug]) !== assetHash) {
51
+ return false;
52
+ }
53
+ }
54
+ return true;
55
+ }
56
+ async handleLatestPatch(latestPatch) {
57
+ try {
58
+ var _await$this$settingSe;
59
+ // 1. validate fetch data with its hash
60
+ const isSafePatch = this.validatePatchWithHash(latestPatch);
61
+ const {
62
+ AssetLogoMap: latestAssetLogoMap,
63
+ ChainAsset: latestAssetInfo,
64
+ ChainInfo: latestChainInfo,
65
+ ChainLogoMap: latestChainLogoMap,
66
+ patchVersion: latestPatchVersion
67
+ } = latestPatch;
68
+ const currentPatchVersion = ((_await$this$settingSe = await this.settingService.getChainlistSetting()) === null || _await$this$settingSe === void 0 ? void 0 : _await$this$settingSe.patchVersion) || '';
69
+ const oldChainInfoMap = structuredClone(this.chainService.getChainInfoMap());
70
+ const oldAssetRegistry = structuredClone(this.chainService.getAssetRegistry());
71
+ let chainInfoMap = structuredClone(this.chainService.getChainInfoMap());
72
+ let assetRegistry = structuredClone(this.chainService.getAssetRegistry());
73
+ const currentChainStateMap = structuredClone(this.chainService.getChainStateMap());
74
+ const currentChainStatusMap = structuredClone(this.chainService.getChainStatusMap());
75
+ let addedChain = [];
76
+ if (isSafePatch && (!this.firstApplied || currentPatchVersion !== latestPatchVersion)) {
77
+ this.firstApplied = true;
78
+
79
+ // 2. merge data map
80
+ if (latestChainInfo && Object.keys(latestChainInfo).length > 0) {
81
+ chainInfoMap = Object.assign({}, oldChainInfoMap, latestChainInfo);
82
+ const [currentChainStateKey, newChainKey] = [Object.keys(currentChainStateMap), Object.keys(chainInfoMap)];
83
+ addedChain = newChainKey.filter(chain => !currentChainStateKey.includes(chain));
84
+ addedChain.forEach(key => {
85
+ currentChainStateMap[key] = {
86
+ active: false,
87
+ currentProvider: randomizeProvider(chainInfoMap[key].providers).providerKey,
88
+ manualTurnOff: false,
89
+ slug: key
90
+ };
91
+ currentChainStatusMap[key] = {
92
+ slug: key,
93
+ connectionStatus: _ChainConnectionStatus.DISCONNECTED,
94
+ lastUpdated: Date.now()
95
+ };
96
+ });
97
+ }
98
+ if (latestAssetInfo && Object.keys(latestAssetInfo).length > 0) {
99
+ assetRegistry = filterAssetInfoMap(oldChainInfoMap, Object.assign({}, oldAssetRegistry, latestAssetInfo), addedChain);
100
+ }
101
+
102
+ // 3. validate data before write
103
+ const isCorrectPatch = this.validatePatchBeforeStore(chainInfoMap, assetRegistry, latestPatch);
104
+
105
+ // 4. write to subject
106
+ if (isCorrectPatch) {
107
+ this.chainService.setChainInfoMap(chainInfoMap);
108
+ this.chainService.subscribeChainInfoMap().next(chainInfoMap);
109
+ this.chainService.setAssetRegistry(assetRegistry);
110
+ this.chainService.subscribeAssetRegistry().next(assetRegistry);
111
+ this.chainService.autoEnableTokens().then(() => {
112
+ this.eventService.emit('asset.updateState', '');
113
+ }).catch(console.error);
114
+ this.chainService.setChainStateMap(currentChainStateMap);
115
+ this.chainService.subscribeChainStateMap().next(currentChainStateMap);
116
+ this.chainService.subscribeChainStatusMap().next(currentChainStatusMap);
117
+ const storedChainInfoList = Object.keys(chainInfoMap).map(chainSlug => {
118
+ return {
119
+ ...chainInfoMap[chainSlug],
120
+ ...currentChainStateMap[chainSlug]
121
+ };
122
+ });
123
+ await this.dbService.bulkUpdateChainStore(storedChainInfoList);
124
+ const addedAssets = [];
125
+
126
+ // todo: the stored asset is lack of adding new assets and edited assets of old chain, update to tracking exactly updated assets from patch online.
127
+ Object.entries(assetRegistry).forEach(([slug, asset]) => {
128
+ if (addedChain.includes(asset.originChain)) {
129
+ addedAssets.push(asset);
130
+ }
131
+ });
132
+ await this.dbService.bulkUpdateAssetsStore(addedAssets);
133
+ if (latestChainLogoMap) {
134
+ const logoMap = Object.assign({}, ChainLogoMap, latestChainLogoMap);
135
+ this.chainService.subscribeChainLogoMap().next(logoMap);
136
+ }
137
+ if (latestAssetLogoMap) {
138
+ const logoMap = Object.assign({}, AssetLogoMap, latestAssetLogoMap);
139
+ this.chainService.subscribeAssetLogoMap().next(logoMap);
140
+ }
141
+ this.settingService.setChainlist({
142
+ patchVersion: latestPatchVersion
143
+ });
144
+ }
145
+ }
146
+ } catch (e) {
147
+ console.error('Error fetching latest patch data');
148
+ }
149
+ }
150
+ async fetchLatestPatchData() {
151
+ return await fetchPatchData();
152
+ }
153
+ handleLatestPatchData() {
154
+ this.fetchLatestPatchData().then(latestPatch => {
155
+ return new Promise(resolve => {
156
+ if (latestPatch && !this.chainService.getlockChainInfoMap()) {
157
+ this.eventService.waitAssetReady.then(() => {
158
+ this.chainService.setLockChainInfoMap(true);
159
+ this.handleLatestPatch(latestPatch).then(() => this.chainService.setLockChainInfoMap(false)).catch(e => {
160
+ this.chainService.setLockChainInfoMap(false);
161
+ console.error('Error update latest patch', e);
162
+ }).finally(resolve);
163
+ }).catch(e => {
164
+ console.error('Asset fail to ready', e);
165
+ resolve();
166
+ });
167
+ } else {
168
+ resolve();
169
+ }
170
+ });
171
+ }).catch(e => {
172
+ console.error('Error get latest patch or data map is locking', e);
173
+ }).finally(() => {
174
+ this.eventService.emit('asset.online.ready', true);
175
+ });
176
+ }
177
+ checkLatestData() {
178
+ clearInterval(this.refreshLatestChainDataTimeOut);
179
+ this.handleLatestPatchData();
180
+ this.refreshLatestChainDataTimeOut = setInterval(this.handleLatestPatchData.bind(this), LATEST_CHAIN_PATCH_FETCHING_INTERVAL);
181
+ }
182
+ }
@@ -38,6 +38,7 @@ export declare const _NFT_CHAIN_GROUP: {
38
38
  avail: string[];
39
39
  ternoa: string[];
40
40
  rari: string[];
41
+ story_odyssey: string[];
41
42
  };
42
43
  export declare const _STAKING_ERA_LENGTH_MAP: Record<string, number>;
43
44
  export declare const _EXPECTED_BLOCK_TIME: Record<string, number>;