@subwallet/extension-base 1.2.14-0 → 1.2.16-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 (96) hide show
  1. package/background/KoniTypes.d.ts +6 -1
  2. package/cjs/core/substrate/nominationpools-pallet.js +2 -1
  3. package/cjs/koni/api/nft/config.js +9 -5
  4. package/cjs/koni/api/nft/index.js +9 -1
  5. package/cjs/koni/api/nft/unique_network_nft/index.js +12 -20
  6. package/cjs/koni/background/handlers/Extension.js +45 -7
  7. package/cjs/koni/background/handlers/State.js +11 -1
  8. package/cjs/packageInfo.js +1 -1
  9. package/cjs/services/balance-service/helpers/subscribe/index.js +1 -1
  10. package/cjs/services/balance-service/helpers/subscribe/substrate/gear.js +135 -0
  11. package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +9 -62
  12. package/cjs/services/balance-service/transfer/token.js +4 -3
  13. package/cjs/services/chain-service/constants.js +1 -0
  14. package/cjs/services/chain-service/handler/SubstrateApi.js +3 -1
  15. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +21 -26
  16. package/cjs/services/chain-service/health-check/constants/index.js +4 -4
  17. package/cjs/services/chain-service/health-check/utils/asset-info.js +23 -6
  18. package/cjs/services/chain-service/health-check/utils/chain-info.js +25 -2
  19. package/cjs/services/chain-service/health-check/utils/new-utils/asset-asset-validate.js +160 -0
  20. package/cjs/services/chain-service/health-check/utils/new-utils/asset-validate.js +45 -0
  21. package/cjs/services/chain-service/health-check/utils/new-utils/chain-asset-validate.js +73 -0
  22. package/cjs/services/chain-service/health-check/utils/new-utils/chain-validate.js +34 -0
  23. package/cjs/services/chain-service/index.js +77 -3
  24. package/cjs/services/chain-service/types.js +1 -1
  25. package/cjs/services/chain-service/utils/index.js +18 -12
  26. package/cjs/services/earning-service/handlers/liquid-staking/acala.js +49 -19
  27. package/cjs/services/earning-service/service.js +3 -0
  28. package/cjs/services/migration-service/scripts/databases/ClearMetadataDatabase.js +16 -0
  29. package/cjs/services/migration-service/scripts/index.js +7 -7
  30. package/cjs/services/price-service/coingecko.js +57 -32
  31. package/cjs/services/price-service/index.js +30 -11
  32. package/cjs/services/transaction-service/index.js +12 -7
  33. package/cjs/utils/gear/combine.js +28 -0
  34. package/cjs/utils/gear/grc20.js +56 -49
  35. package/cjs/utils/gear/index.js +22 -0
  36. package/cjs/utils/gear/vft.js +173 -0
  37. package/cjs/utils/metadata.js +45 -34
  38. package/core/substrate/nominationpools-pallet.js +2 -1
  39. package/koni/api/nft/config.d.ts +1 -0
  40. package/koni/api/nft/config.js +3 -1
  41. package/koni/api/nft/index.js +9 -1
  42. package/koni/api/nft/unique_network_nft/index.js +12 -20
  43. package/koni/background/handlers/Extension.d.ts +2 -0
  44. package/koni/background/handlers/Extension.js +37 -1
  45. package/koni/background/handlers/State.d.ts +2 -0
  46. package/koni/background/handlers/State.js +11 -1
  47. package/package.json +44 -8
  48. package/packageInfo.js +1 -1
  49. package/services/balance-service/helpers/subscribe/index.js +1 -1
  50. package/services/balance-service/helpers/subscribe/substrate/gear.d.ts +4 -0
  51. package/services/balance-service/helpers/subscribe/substrate/gear.js +123 -0
  52. package/services/balance-service/helpers/subscribe/substrate/index.js +10 -61
  53. package/services/balance-service/transfer/token.js +5 -4
  54. package/services/chain-service/constants.d.ts +1 -0
  55. package/services/chain-service/constants.js +1 -0
  56. package/services/chain-service/handler/SubstrateApi.d.ts +1 -1
  57. package/services/chain-service/handler/SubstrateApi.js +3 -1
  58. package/services/chain-service/handler/SubstrateChainHandler.d.ts +1 -0
  59. package/services/chain-service/handler/SubstrateChainHandler.js +22 -27
  60. package/services/chain-service/health-check/constants/index.js +4 -4
  61. package/services/chain-service/health-check/utils/asset-info.d.ts +1 -0
  62. package/services/chain-service/health-check/utils/asset-info.js +20 -4
  63. package/services/chain-service/health-check/utils/chain-info.d.ts +4 -2
  64. package/services/chain-service/health-check/utils/chain-info.js +20 -0
  65. package/services/chain-service/health-check/utils/new-utils/asset-asset-validate.d.ts +10 -0
  66. package/services/chain-service/health-check/utils/new-utils/asset-asset-validate.js +146 -0
  67. package/services/chain-service/health-check/utils/new-utils/asset-validate.d.ts +3 -0
  68. package/services/chain-service/health-check/utils/new-utils/asset-validate.js +38 -0
  69. package/services/chain-service/health-check/utils/new-utils/chain-asset-validate.d.ts +5 -0
  70. package/services/chain-service/health-check/utils/new-utils/chain-asset-validate.js +64 -0
  71. package/services/chain-service/health-check/utils/new-utils/chain-validate.d.ts +4 -0
  72. package/services/chain-service/health-check/utils/new-utils/chain-validate.js +26 -0
  73. package/services/chain-service/index.d.ts +4 -0
  74. package/services/chain-service/index.js +78 -4
  75. package/services/chain-service/types.d.ts +6 -0
  76. package/services/chain-service/types.js +1 -1
  77. package/services/chain-service/utils/index.d.ts +1 -0
  78. package/services/chain-service/utils/index.js +16 -12
  79. package/services/earning-service/handlers/liquid-staking/acala.js +46 -17
  80. package/services/earning-service/service.js +3 -0
  81. package/services/migration-service/scripts/databases/ClearMetadataDatabase.js +16 -0
  82. package/services/migration-service/scripts/index.js +7 -7
  83. package/services/price-service/coingecko.js +54 -32
  84. package/services/price-service/index.js +29 -11
  85. package/services/transaction-service/index.js +13 -8
  86. package/types/metadata.d.ts +9 -2
  87. package/utils/gear/combine.d.ts +10 -0
  88. package/utils/gear/combine.js +18 -0
  89. package/utils/gear/grc20.d.ts +18 -20
  90. package/utils/gear/grc20.js +53 -45
  91. package/utils/gear/index.d.ts +2 -0
  92. package/utils/gear/index.js +3 -1
  93. package/utils/gear/vft.d.ts +36 -0
  94. package/utils/gear/vft.js +162 -0
  95. package/utils/metadata.d.ts +7 -2
  96. package/utils/metadata.js +41 -31
@@ -3,21 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.GRC20 = exports.DEFAULT_GEAR_ADDRESS = void 0;
7
- exports.getGRC20ContractPromise = getGRC20ContractPromise;
6
+ exports.Grc20Service = exports.GRC20 = void 0;
8
7
  var _api = require("@gear-js/api");
9
8
  var _sailsJs = require("sails-js");
10
9
  var _types = require("@polkadot/types");
11
- // Copyright 2019-2022 @subwallet/extension-base
10
+ // Copyright 2019-2022 @subwallet/extension-base authors & contributors
12
11
  // SPDX-License-Identifier: Apache-2.0
13
12
 
14
- // https://github.com/breathx/gear-erc20/blob/master/js/src/lib.ts
15
-
16
- const DEFAULT_GEAR_ADDRESS = {
17
- ALICE: '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY',
18
- BOB: '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty'
19
- };
20
- exports.DEFAULT_GEAR_ADDRESS = DEFAULT_GEAR_ADDRESS;
21
13
  class GRC20 {
22
14
  constructor(api) {
23
15
  let programId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '0x';
@@ -32,6 +24,7 @@ class GRC20 {
32
24
  types
33
25
  });
34
26
  this.registry.register(types);
27
+ this.service = new Grc20Service(this);
35
28
  }
36
29
  newCtorFromCode(code, name, symbol, decimals) {
37
30
  const builder = new _sailsJs.TransactionBuilder(this.api, this.registry, 'upload_program', ['New', name, symbol, decimals], '(String, String, String, u8)', 'String', code);
@@ -43,99 +36,113 @@ class GRC20 {
43
36
  this.programId = builder.programId;
44
37
  return builder;
45
38
  }
39
+ }
40
+ exports.GRC20 = GRC20;
41
+ class Grc20Service {
42
+ constructor(_program) {
43
+ this._program = _program;
44
+ }
46
45
  approve(spender, value) {
47
- return new _sailsJs.TransactionBuilder(this.api, this.registry, 'send_message', ['Approve', spender, value], '(String, ActorId, U256)', 'bool', this.programId);
46
+ if (!this._program.programId) {
47
+ throw new Error('Program ID is not set');
48
+ }
49
+ return new _sailsJs.TransactionBuilder(this._program.api, this._program.registry, 'send_message', ['Approve', spender, value], '(String, ActorId, U256)', 'bool', this._program.programId);
48
50
  }
49
51
  fromTransfer(from, to, value) {
50
- return new _sailsJs.TransactionBuilder(this.api, this.registry, 'send_message', ['FromTransfer', from, to, value], '(String, ActorId, ActorId, U256)', 'bool', this.programId);
52
+ if (!this._program.programId) {
53
+ throw new Error('Program ID is not set');
54
+ }
55
+ return new _sailsJs.TransactionBuilder(this._program.api, this._program.registry, 'send_message', ['FromTransfer', from, to, value], '(String, ActorId, ActorId, U256)', 'bool', this._program.programId);
51
56
  }
52
57
  setBalance(newBalance) {
53
- return new _sailsJs.TransactionBuilder(this.api, this.registry, 'send_message', ['SetBalance', newBalance], '(String, U256)', 'bool', this.programId);
58
+ if (!this._program.programId) {
59
+ throw new Error('Program ID is not set');
60
+ }
61
+ return new _sailsJs.TransactionBuilder(this._program.api, this._program.registry, 'send_message', ['SetBalance', newBalance], '(String, U256)', 'bool', this._program.programId);
54
62
  }
55
63
  transfer(to, value) {
56
- return new _sailsJs.TransactionBuilder(this.api, this.registry, 'send_message', ['Transfer', to, value], '(String, ActorId, U256)', 'bool', this.programId);
64
+ if (!this._program.programId) {
65
+ throw new Error('Program ID is not set');
66
+ }
67
+ return new _sailsJs.TransactionBuilder(this._program.api, this._program.registry, 'send_message', ['Transfer', to, value], '(String, ActorId, U256)', 'bool', this._program.programId);
57
68
  }
58
69
  async allowance(owner, spender, originAddress, value, atBlock) {
59
- const payload = this.registry.createType('(String, ActorId, ActorId)', ['Allowance', owner, spender]).toU8a();
60
- const reply = await this.api.message.calculateReply({
61
- destination: this.programId,
70
+ const payload = this._program.registry.createType('(String, ActorId, ActorId)', ['Allowance', owner, spender]).toHex();
71
+ const reply = await this._program.api.message.calculateReply({
72
+ destination: this._program.programId,
62
73
  origin: (0, _api.decodeAddress)(originAddress),
63
74
  payload,
64
75
  value: value || 0,
65
- gasLimit: this.api.blockGasLimit.toBigInt(),
76
+ gasLimit: this._program.api.blockGasLimit.toBigInt(),
66
77
  at: atBlock
67
78
  });
68
- const result = this.registry.createType('(String, U256)', reply.payload);
79
+ const result = this._program.registry.createType('(String, U256)', reply.payload);
69
80
  return result[1].toBigInt();
70
81
  }
71
82
  async balanceOf(owner, originAddress, value, atBlock) {
72
- const payload = this.registry.createType('(String, ActorId)', ['BalanceOf', owner]).toU8a();
73
- const reply = await this.api.message.calculateReply({
74
- destination: this.programId,
83
+ const payload = this._program.registry.createType('(String, ActorId)', ['BalanceOf', owner]).toHex();
84
+ const reply = await this._program.api.message.calculateReply({
85
+ destination: this._program.programId,
75
86
  origin: (0, _api.decodeAddress)(originAddress),
76
87
  payload,
77
88
  value: value || 0,
78
- gasLimit: this.api.blockGasLimit.toBigInt(),
89
+ gasLimit: this._program.api.blockGasLimit.toBigInt(),
79
90
  at: atBlock
80
91
  });
81
- const result = this.registry.createType('(String, U256)', reply.payload);
92
+ const result = this._program.registry.createType('(String, U256)', reply.payload);
82
93
  return result[1].toBigInt();
83
94
  }
84
95
  async decimals(originAddress, value, atBlock) {
85
- const payload = this.registry.createType('String', 'Decimals').toU8a();
86
- const reply = await this.api.message.calculateReply({
87
- destination: this.programId,
96
+ const payload = this._program.registry.createType('String', 'Decimals').toHex();
97
+ const reply = await this._program.api.message.calculateReply({
98
+ destination: this._program.programId,
88
99
  origin: (0, _api.decodeAddress)(originAddress),
89
100
  payload,
90
101
  value: value || 0,
91
- gasLimit: this.api.blockGasLimit.toBigInt(),
102
+ gasLimit: this._program.api.blockGasLimit.toBigInt(),
92
103
  at: atBlock
93
104
  });
94
- const result = this.registry.createType('(String, u8)', reply.payload);
105
+ const result = this._program.registry.createType('(String, u8)', reply.payload);
95
106
  return result[1].toNumber();
96
107
  }
97
108
  async name(originAddress, value, atBlock) {
98
- const payload = this.registry.createType('String', 'Name').toU8a();
99
- const reply = await this.api.message.calculateReply({
100
- destination: this.programId,
109
+ const payload = this._program.registry.createType('String', 'Name').toHex();
110
+ const reply = await this._program.api.message.calculateReply({
111
+ destination: this._program.programId,
101
112
  origin: (0, _api.decodeAddress)(originAddress),
102
113
  payload,
103
114
  value: value || 0,
104
- gasLimit: this.api.blockGasLimit.toBigInt(),
115
+ gasLimit: this._program.api.blockGasLimit.toBigInt(),
105
116
  at: atBlock
106
117
  });
107
- const result = this.registry.createType('(String, String)', reply.payload);
118
+ const result = this._program.registry.createType('(String, String)', reply.payload);
108
119
  return result[1].toString();
109
120
  }
110
121
  async symbol(originAddress, value, atBlock) {
111
- const payload = this.registry.createType('String', 'Symbol').toU8a();
112
- const reply = await this.api.message.calculateReply({
113
- destination: this.programId,
122
+ const payload = this._program.registry.createType('String', 'Symbol').toHex();
123
+ const reply = await this._program.api.message.calculateReply({
124
+ destination: this._program.programId,
114
125
  origin: (0, _api.decodeAddress)(originAddress),
115
126
  payload,
116
127
  value: value || 0,
117
- gasLimit: this.api.blockGasLimit.toBigInt(),
128
+ gasLimit: this._program.api.blockGasLimit.toBigInt(),
118
129
  at: atBlock
119
130
  });
120
- const result = this.registry.createType('(String, String)', reply.payload);
131
+ const result = this._program.registry.createType('(String, String)', reply.payload);
121
132
  return result[1].toString();
122
133
  }
123
134
  async totalSupply(originAddress, value, atBlock) {
124
- const payload = this.registry.createType('String', 'TotalSupply').toU8a();
125
- const reply = await this.api.message.calculateReply({
126
- destination: this.programId,
135
+ const payload = this._program.registry.createType('String', 'TotalSupply').toHex();
136
+ const reply = await this._program.api.message.calculateReply({
137
+ destination: this._program.programId,
127
138
  origin: (0, _api.decodeAddress)(originAddress),
128
139
  payload,
129
140
  value: value || 0,
130
- gasLimit: this.api.blockGasLimit.toBigInt(),
141
+ gasLimit: this._program.api.blockGasLimit.toBigInt(),
131
142
  at: atBlock
132
143
  });
133
- const result = this.registry.createType('(String, U256)', reply.payload);
144
+ const result = this._program.registry.createType('(String, U256)', reply.payload);
134
145
  return result[1].toBigInt();
135
146
  }
136
147
  }
137
- exports.GRC20 = GRC20;
138
- function getGRC20ContractPromise(apiPromise, contractAddress) {
139
- const gearApi = apiPromise;
140
- return new GRC20(gearApi, contractAddress);
141
- }
148
+ exports.Grc20Service = Grc20Service;
@@ -3,6 +3,17 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ var _combine = require("./combine");
7
+ Object.keys(_combine).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _combine[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _combine[key];
14
+ }
15
+ });
16
+ });
6
17
  var _grc = require("./grc20");
7
18
  Object.keys(_grc).forEach(function (key) {
8
19
  if (key === "default" || key === "__esModule") return;
@@ -13,4 +24,15 @@ Object.keys(_grc).forEach(function (key) {
13
24
  return _grc[key];
14
25
  }
15
26
  });
27
+ });
28
+ var _vft = require("./vft");
29
+ Object.keys(_vft).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (key in exports && exports[key] === _vft[key]) return;
32
+ Object.defineProperty(exports, key, {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _vft[key];
36
+ }
37
+ });
16
38
  });
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.VftService = exports.VFT = void 0;
7
+ var _api = require("@gear-js/api");
8
+ var _sailsJs = require("sails-js");
9
+ var _types = require("@polkadot/types");
10
+ // Copyright 2019-2022 @subwallet/extension-base authors & contributors
11
+ // SPDX-License-Identifier: Apache-2.0
12
+
13
+ class VFT {
14
+ constructor(api) {
15
+ let programId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '0x';
16
+ this.api = api;
17
+ this.programId = programId;
18
+ const types = {};
19
+ this.registry = new _types.TypeRegistry();
20
+ this.registry.setKnownTypes({
21
+ types
22
+ });
23
+ this.registry.register(types);
24
+ this.service = new VftService(this);
25
+ }
26
+ newCtorFromCode(code, name, symbol, decimals) {
27
+ const builder = new _sailsJs.TransactionBuilder(this.api, this.registry, 'upload_program', ['New', name, symbol, decimals], '(String, String, String, u8)', 'String', code);
28
+ this.programId = builder.programId;
29
+ return builder;
30
+ }
31
+ newCtorFromCodeId(codeId, name, symbol, decimals) {
32
+ const builder = new _sailsJs.TransactionBuilder(this.api, this.registry, 'create_program', ['New', name, symbol, decimals], '(String, String, String, u8)', 'String', codeId);
33
+ this.programId = builder.programId;
34
+ return builder;
35
+ }
36
+ }
37
+ exports.VFT = VFT;
38
+ class VftService {
39
+ constructor(_program) {
40
+ this._program = _program;
41
+ }
42
+ approve(spender, value) {
43
+ if (!this._program.programId) {
44
+ throw new Error('Program ID is not set');
45
+ }
46
+ return new _sailsJs.TransactionBuilder(this._program.api, this._program.registry, 'send_message', ['Vft', 'Approve', spender, value], '(String, String, [u8;32], U256)', 'bool', this._program.programId);
47
+ }
48
+ transfer(to, value) {
49
+ if (!this._program.programId) {
50
+ throw new Error('Program ID is not set');
51
+ }
52
+ return new _sailsJs.TransactionBuilder(this._program.api, this._program.registry, 'send_message', ['Vft', 'Transfer', to, value], '(String, String, [u8;32], U256)', 'bool', this._program.programId);
53
+ }
54
+ transferFrom(from, to, value) {
55
+ if (!this._program.programId) {
56
+ throw new Error('Program ID is not set');
57
+ }
58
+ return new _sailsJs.TransactionBuilder(this._program.api, this._program.registry, 'send_message', ['Vft', 'TransferFrom', from, to, value], '(String, String, [u8;32], [u8;32], U256)', 'bool', this._program.programId);
59
+ }
60
+ async allowance(owner, spender, originAddress, value, atBlock) {
61
+ const payload = this._program.registry.createType('(String, String, [u8;32], [u8;32])', ['Vft', 'Allowance', owner, spender]).toHex();
62
+ const reply = await this._program.api.message.calculateReply({
63
+ destination: this._program.programId,
64
+ origin: (0, _api.decodeAddress)(originAddress),
65
+ payload,
66
+ value: value || 0,
67
+ gasLimit: this._program.api.blockGasLimit.toBigInt(),
68
+ at: atBlock
69
+ });
70
+ const result = this._program.registry.createType('(String, String, U256)', reply.payload);
71
+ return result[2].toBigInt();
72
+ }
73
+ async balanceOf(account, originAddress, value, atBlock) {
74
+ const payload = this._program.registry.createType('(String, String, [u8;32])', ['Vft', 'BalanceOf', account]).toHex();
75
+ const reply = await this._program.api.message.calculateReply({
76
+ destination: this._program.programId,
77
+ origin: (0, _api.decodeAddress)(originAddress),
78
+ payload,
79
+ value: value || 0,
80
+ gasLimit: this._program.api.blockGasLimit.toBigInt(),
81
+ at: atBlock
82
+ });
83
+ const result = this._program.registry.createType('(String, String, U256)', reply.payload);
84
+ return result[2].toBigInt();
85
+ }
86
+ async decimals(originAddress, value, atBlock) {
87
+ const payload = this._program.registry.createType('(String, String)', ['Vft', 'Decimals']).toHex();
88
+ const reply = await this._program.api.message.calculateReply({
89
+ destination: this._program.programId,
90
+ origin: (0, _api.decodeAddress)(originAddress),
91
+ payload,
92
+ value: value || 0,
93
+ gasLimit: this._program.api.blockGasLimit.toBigInt(),
94
+ at: atBlock
95
+ });
96
+ const result = this._program.registry.createType('(String, String, u8)', reply.payload);
97
+ return result[2].toNumber();
98
+ }
99
+ async name(originAddress, value, atBlock) {
100
+ const payload = this._program.registry.createType('(String, String)', ['Vft', 'Name']).toHex();
101
+ const reply = await this._program.api.message.calculateReply({
102
+ destination: this._program.programId,
103
+ origin: (0, _api.decodeAddress)(originAddress),
104
+ payload,
105
+ value: value || 0,
106
+ gasLimit: this._program.api.blockGasLimit.toBigInt(),
107
+ at: atBlock
108
+ });
109
+ const result = this._program.registry.createType('(String, String, String)', reply.payload);
110
+ return result[2].toString();
111
+ }
112
+ async symbol(originAddress, value, atBlock) {
113
+ const payload = this._program.registry.createType('(String, String)', ['Vft', 'Symbol']).toHex();
114
+ const reply = await this._program.api.message.calculateReply({
115
+ destination: this._program.programId,
116
+ origin: (0, _api.decodeAddress)(originAddress),
117
+ payload,
118
+ value: value || 0,
119
+ gasLimit: this._program.api.blockGasLimit.toBigInt(),
120
+ at: atBlock
121
+ });
122
+ const result = this._program.registry.createType('(String, String, String)', reply.payload);
123
+ return result[2].toString();
124
+ }
125
+ async totalSupply(originAddress, value, atBlock) {
126
+ const payload = this._program.registry.createType('(String, String)', ['Vft', 'TotalSupply']).toHex();
127
+ const reply = await this._program.api.message.calculateReply({
128
+ destination: this._program.programId,
129
+ origin: (0, _api.decodeAddress)(originAddress),
130
+ payload,
131
+ value: value || 0,
132
+ gasLimit: this._program.api.blockGasLimit.toBigInt(),
133
+ at: atBlock
134
+ });
135
+ const result = this._program.registry.createType('(String, String, U256)', reply.payload);
136
+ return result[2].toBigInt();
137
+ }
138
+ subscribeToApprovalEvent(callback) {
139
+ return this._program.api.gearEvents.subscribeToGearEvent('UserMessageSent', _ref => {
140
+ let {
141
+ data: {
142
+ message
143
+ }
144
+ } = _ref;
145
+ if (!message.source.eq(this._program.programId) || !message.destination.eq(_sailsJs.ZERO_ADDRESS)) {
146
+ return;
147
+ }
148
+ const payload = message.payload.toHex();
149
+ if ((0, _sailsJs.getServiceNamePrefix)(payload) === 'Vft' && (0, _sailsJs.getFnNamePrefix)(payload) === 'Approval') {
150
+ // eslint-disable-next-line node/no-callback-literal,@typescript-eslint/no-floating-promises
151
+ callback(this._program.registry.createType('(String, String, {"owner":"[u8;32]","spender":"[u8;32]","value":"U256"})', message.payload)[2].toJSON());
152
+ }
153
+ });
154
+ }
155
+ subscribeToTransferEvent(callback) {
156
+ return this._program.api.gearEvents.subscribeToGearEvent('UserMessageSent', _ref2 => {
157
+ let {
158
+ data: {
159
+ message
160
+ }
161
+ } = _ref2;
162
+ if (!message.source.eq(this._program.programId) || !message.destination.eq(_sailsJs.ZERO_ADDRESS)) {
163
+ return;
164
+ }
165
+ const payload = message.payload.toHex();
166
+ if ((0, _sailsJs.getServiceNamePrefix)(payload) === 'Service' && (0, _sailsJs.getFnNamePrefix)(payload) === 'Transfer') {
167
+ // eslint-disable-next-line node/no-callback-literal,@typescript-eslint/no-floating-promises
168
+ callback(this._program.registry.createType('(String, String, {"from":"[u8;32]","to":"[u8;32]","value":"U256"})', message.payload)[2].toJSON());
169
+ }
170
+ });
171
+ }
172
+ }
173
+ exports.VftService = VftService;
@@ -3,46 +3,57 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getShortMetadata = exports.getMetadataHash = exports._isRuntimeUpdated = void 0;
6
+ exports.getShortMetadata = exports.calculateMetadataHash = exports.cacheMetadata = exports._isRuntimeUpdated = void 0;
7
+ var _typesKnown = require("@polkadot/types-known");
8
+ var _util = require("@polkadot/util");
9
+ var _merkleizeMetadata2 = require("@polkadot-api/merkleize-metadata");
7
10
  // Copyright 2019-2022 @subwallet/extension-base
8
11
  // SPDX-License-Identifier: Apache-2.0
9
12
 
10
- const LEDGER_API_URL = 'https://ledger-api.subwallet.app';
11
- const createUrl = path => `${LEDGER_API_URL}/${path}`;
12
13
  const _isRuntimeUpdated = signedExtensions => {
13
14
  return signedExtensions ? signedExtensions.includes('CheckMetadataHash') : false;
14
15
  };
15
16
  exports._isRuntimeUpdated = _isRuntimeUpdated;
16
- const getMetadataHash = async chain => {
17
- const data = {
18
- id: chain
19
- };
20
- const resp = await fetch(createUrl('node/metadata/hash'), {
21
- method: 'POST',
22
- headers: {
23
- 'Content-Type': 'application/json'
24
- },
25
- body: JSON.stringify(data)
26
- });
27
- const rs = await resp.json();
28
- return rs.metadataHash;
17
+ const calculateMetadataHash = (extraInfo, metadataV15) => {
18
+ const _merkleizeMetadata = (0, _merkleizeMetadata2.merkleizeMetadata)(metadataV15, extraInfo);
19
+ return (0, _util.u8aToHex)(_merkleizeMetadata.digest());
29
20
  };
30
- exports.getMetadataHash = getMetadataHash;
31
- const getShortMetadata = async (chain, blob) => {
32
- const data = {
33
- chain: {
34
- id: chain
35
- },
36
- txBlob: blob
37
- };
38
- const resp = await fetch(createUrl('transaction/metadata'), {
39
- method: 'POST',
40
- headers: {
41
- 'Content-Type': 'application/json'
42
- },
43
- body: JSON.stringify(data)
44
- });
45
- const rs = await resp.json();
46
- return rs.txMetadata;
21
+ exports.calculateMetadataHash = calculateMetadataHash;
22
+ const getShortMetadata = (blob, extraInfo, metadata) => {
23
+ const _merkleizeMetadata = (0, _merkleizeMetadata2.merkleizeMetadata)(metadata, extraInfo);
24
+ return (0, _util.u8aToHex)(_merkleizeMetadata.getProofForExtrinsicPayload(blob));
47
25
  };
48
- exports.getShortMetadata = getShortMetadata;
26
+ exports.getShortMetadata = getShortMetadata;
27
+ const cacheMetadata = (chain, substrateApi, chainService) => {
28
+ // Update metadata to database with async methods
29
+ substrateApi.api.isReady.then(async api => {
30
+ const currentSpecVersion = api.runtimeVersion.specVersion.toString();
31
+ const specName = api.runtimeVersion.specName.toString();
32
+ const genesisHash = api.genesisHash.toHex();
33
+ const metadata = await (chainService === null || chainService === void 0 ? void 0 : chainService.getMetadata(chain));
34
+
35
+ // Avoid date existed metadata
36
+ if (metadata && metadata.specVersion === currentSpecVersion && metadata.genesisHash === genesisHash) {
37
+ return;
38
+ }
39
+ const systemChain = await api.rpc.system.chain();
40
+ // const _metadata: Option<OpaqueMetadata> = await api.call.metadata.metadataAtVersion(15);
41
+ // const metadataHex = _metadata.isSome ? _metadata.unwrap().toHex().slice(2) : ''; // Need unwrap to create metadata object
42
+ let hexV15;
43
+ const metadataV15 = await api.call.metadata.metadataAtVersion(15);
44
+ if (!metadataV15.isEmpty) {
45
+ hexV15 = metadataV15.unwrap().toHex();
46
+ }
47
+ chainService === null || chainService === void 0 ? void 0 : chainService.upsertMetadata(chain, {
48
+ chain: chain,
49
+ genesisHash: genesisHash,
50
+ specName: specName,
51
+ specVersion: currentSpecVersion,
52
+ hexValue: api.runtimeMetadata.toHex(),
53
+ types: (0, _typesKnown.getSpecTypes)(api.registry, systemChain, api.runtimeVersion.specName, api.runtimeVersion.specVersion),
54
+ userExtensions: (0, _typesKnown.getSpecExtensions)(api.registry, systemChain, api.runtimeVersion.specName),
55
+ hexV15
56
+ }).catch(console.error);
57
+ }).catch(console.error);
58
+ };
59
+ exports.cacheMetadata = cacheMetadata;
@@ -6,7 +6,8 @@ export function _getActiveStakeInNominationPool(memberInfo) {
6
6
  return new BigN(memberInfo.points.toString());
7
7
  }
8
8
  export function _getUnbondingStakeInNominationPool(memberInfo) {
9
- return new BigN(Object.values(memberInfo.unbondingEras).reduce((a, b) => a + b, 0));
9
+ const unbondingValues = Object.values(memberInfo.unbondingEras).map(unbonding => new BigN(unbonding));
10
+ return new BigN(Object.values(unbondingValues).reduce((a, b) => a.plus(b), new BigN(0)));
10
11
  }
11
12
  export function _getTotalStakeInNominationPool(memberInfo) {
12
13
  return _getActiveStakeInNominationPool(memberInfo).plus(_getUnbondingStakeInNominationPool(memberInfo));
@@ -47,6 +47,7 @@ export declare enum SUPPORTED_TRANSFER_EVM_CHAIN_NAME {
47
47
  shibuya = "shibuya"
48
48
  }
49
49
  export declare const SUPPORTED_TRANSFER_EVM_CHAIN: string[];
50
+ export declare const UNSUPPORTED_TRANSFER_EVM_CHAIN_NAME: string[];
50
51
  export declare const TRANSFER_CHAIN_ID: {
51
52
  [x: string]: number;
52
53
  };
@@ -1,7 +1,8 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { isFirefox, RuntimeInfo } from '@subwallet/extension-base/utils';
4
+ import { isFirefox, RuntimeInfo } from '@subwallet/extension-base/utils/environment'; // do not change to shorten path, avoid circle import
5
+
5
6
  export const SINGULAR_V1_ENDPOINT = 'https://singular.rmrk-api.xyz/api/account-rmrk1/';
6
7
  export const SINGULAR_V2_ENDPOINT = 'https://singular.rmrk-api.xyz/api/account/';
7
8
  export const KANARIA_ENDPOINT = 'https://kanaria.rmrk.app/api/rmrk2/';
@@ -73,6 +74,7 @@ export let SUPPORTED_TRANSFER_EVM_CHAIN_NAME;
73
74
  SUPPORTED_TRANSFER_EVM_CHAIN_NAME["shibuya"] = "shibuya";
74
75
  })(SUPPORTED_TRANSFER_EVM_CHAIN_NAME || (SUPPORTED_TRANSFER_EVM_CHAIN_NAME = {}));
75
76
  export const SUPPORTED_TRANSFER_EVM_CHAIN = [SUPPORTED_TRANSFER_EVM_CHAIN_NAME.moonbase, SUPPORTED_TRANSFER_EVM_CHAIN_NAME.moonbeam, SUPPORTED_TRANSFER_EVM_CHAIN_NAME.moonriver, SUPPORTED_TRANSFER_EVM_CHAIN_NAME.astarEvm, SUPPORTED_TRANSFER_EVM_CHAIN_NAME.shiden, SUPPORTED_TRANSFER_EVM_CHAIN_NAME.shibuya];
77
+ export const UNSUPPORTED_TRANSFER_EVM_CHAIN_NAME = ['unique_evm'];
76
78
  export const TRANSFER_CHAIN_ID = {
77
79
  [SUPPORTED_TRANSFER_EVM_CHAIN_NAME.moonbase]: 1287,
78
80
  [SUPPORTED_TRANSFER_EVM_CHAIN_NAME.moonbeam]: 1284,
@@ -17,7 +17,7 @@ import { _isChainSupportEvmNft, _isChainSupportNativeNft, _isChainSupportWasmNft
17
17
  import { categoryAddresses, targetIsWeb } from '@subwallet/extension-base/utils';
18
18
  import AssetHubNftsPalletApi from "./assethub_nft/index.js";
19
19
  function createSubstrateNftApi(chain, substrateApi, addresses) {
20
- const [substrateAddresses] = categoryAddresses(addresses);
20
+ const [substrateAddresses, evmAddresses] = categoryAddresses(addresses);
21
21
  if (_NFT_CHAIN_GROUP.acala.includes(chain)) {
22
22
  return [new AcalaNftApi(substrateApi, substrateAddresses, chain)];
23
23
  } else if (_NFT_CHAIN_GROUP.karura.includes(chain)) {
@@ -30,6 +30,8 @@ function createSubstrateNftApi(chain, substrateApi, addresses) {
30
30
  return [new AssetHubUniquesPalletApi(substrateApi, substrateAddresses, chain), new AssetHubNftsPalletApi(substrateApi, substrateAddresses, chain)];
31
31
  } else if (_NFT_CHAIN_GROUP.unique_network.includes(chain)) {
32
32
  return [new UniqueNftApi(chain, substrateAddresses)];
33
+ } else if (_NFT_CHAIN_GROUP.unique_evm.includes(chain)) {
34
+ return [new UniqueNftApi(chain, evmAddresses)];
33
35
  } else if (_NFT_CHAIN_GROUP.bitcountry.includes(chain)) {
34
36
  return [new BitCountryNftApi(substrateApi, substrateAddresses, chain)];
35
37
  } else if (_NFT_CHAIN_GROUP.vara.includes(chain)) {
@@ -119,6 +121,12 @@ export class NftHandler {
119
121
  }
120
122
  }
121
123
  }
124
+ if (chain === 'unique_evm') {
125
+ const handlers = createSubstrateNftApi(chain, null, evmAddresses);
126
+ if (handlers && !!handlers.length) {
127
+ this.handlers.push(...handlers);
128
+ }
129
+ }
122
130
  if (_isChainSupportWasmNft(chainInfo)) {
123
131
  if (this.substrateApiMap[chain]) {
124
132
  const handler = createWasmNftApi(chain, this.substrateApiMap[chain], substrateAddresses);
@@ -3,6 +3,7 @@
3
3
 
4
4
  import { OPAL_SCAN_ENDPOINT, QUARTZ_SCAN_ENDPOINT, UNIQUE_IPFS_GATEWAY, UNIQUE_SCAN_ENDPOINT } from '@subwallet/extension-base/koni/api/nft/config';
5
5
  import { BaseNftApi } from '@subwallet/extension-base/koni/api/nft/nft';
6
+ import { _NFT_CHAIN_GROUP } from '@subwallet/extension-base/services/chain-service/constants';
6
7
  import { baseParseIPFSUrl } from '@subwallet/extension-base/utils';
7
8
  import { decodeAddress, encodeAddress } from '@polkadot/util-crypto';
8
9
  export class UniqueNftApi extends BaseNftApi {
@@ -15,23 +16,13 @@ export class UniqueNftApi extends BaseNftApi {
15
16
  handleProperties(nft) {
16
17
  const propertiesMap = {};
17
18
  const attRecord = nft.attributes;
18
- if (attRecord) {
19
- for (const item in attRecord) {
20
- const attName = attRecord[item].name._;
21
- const attInfo = attRecord[item].value;
22
- if (Array.isArray(attInfo)) {
23
- const attList = [];
24
- for (const trait of attInfo) {
25
- attList.push(trait._);
26
- }
27
- propertiesMap[attName] = {
28
- value: attList
29
- };
30
- } else {
31
- propertiesMap[attName] = {
32
- value: attInfo._
33
- };
34
- }
19
+ if (attRecord.length) {
20
+ for (const item of attRecord) {
21
+ const attName = item.trait_type;
22
+ const attInfo = item.value;
23
+ propertiesMap[attName] = {
24
+ value: attInfo
25
+ };
35
26
  }
36
27
  }
37
28
  return propertiesMap;
@@ -78,8 +69,10 @@ export class UniqueNftApi extends BaseNftApi {
78
69
  endpoint = OPAL_SCAN_ENDPOINT;
79
70
  uniqueAddress = address;
80
71
  // Opal address: Normal address
72
+ } else if (_NFT_CHAIN_GROUP.unique_evm.includes(this.chain)) {
73
+ endpoint = UNIQUE_SCAN_ENDPOINT;
74
+ uniqueAddress = address.toLowerCase();
81
75
  }
82
-
83
76
  const resp = await fetch(endpoint, {
84
77
  method: 'post',
85
78
  headers: {
@@ -99,7 +92,6 @@ export class UniqueNftApi extends BaseNftApi {
99
92
  if (nfts) {
100
93
  const collectionMap = {};
101
94
  for (const nft of nfts) {
102
- var _nft$image;
103
95
  // Handle case rendering image on Quartz Network (Temporary solution)
104
96
  if (this.chain === 'quartz' && nft.collection_id.toString() === '141') {
105
97
  continue;
@@ -114,7 +106,7 @@ export class UniqueNftApi extends BaseNftApi {
114
106
  chain: this.chain,
115
107
  owner: address,
116
108
  name: nft.token_name,
117
- image: this.parseUrl((_nft$image = nft.image) === null || _nft$image === void 0 ? void 0 : _nft$image.fullUrl),
109
+ image: this.parseUrl(nft.image),
118
110
  description: nft.collection_description,
119
111
  collectionId: nft.collection_id.toString(),
120
112
  properties: propertiesMap
@@ -219,6 +219,8 @@ export default class KoniExtension {
219
219
  private subscribeMantaPayConfig;
220
220
  private subscribeMantaPaySyncState;
221
221
  private findRawMetadata;
222
+ private calculateMetadataHash;
223
+ private shortenMetadata;
222
224
  private resolveDomainByAddress;
223
225
  private resolveAddressByDomain;
224
226
  private addInjects;