@subwallet/extension-base 1.1.65-0 → 1.1.66-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.
- package/cjs/koni/api/dotsama/transfer.js +11 -0
- package/cjs/koni/api/staking/bonding/relayChain.js +6 -0
- package/cjs/koni/api/tokens/wasm/utils.js +5 -3
- package/cjs/koni/background/handlers/State.js +2 -0
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/index.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +67 -0
- package/cjs/services/chain-service/constants.js +8 -1
- package/cjs/services/chain-service/handler/EvmChainHandler.js +1 -1
- package/cjs/services/chain-service/handler/SubstrateApi.js +15 -9
- package/cjs/services/chain-service/handler/SubstrateChainHandler.js +76 -57
- package/cjs/services/chain-service/index.js +45 -30
- package/cjs/services/chain-service/types.js +1 -1
- package/cjs/services/chain-service/utils/index.js +38 -15
- package/cjs/services/chain-service/utils/patch.js +1 -1
- package/cjs/services/earning-service/constants/chains.js +2 -2
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +3 -0
- package/cjs/services/earning-service/handlers/nomination-pool/index.js +1 -0
- package/cjs/services/price-service/index.js +31 -17
- package/cjs/stores/CurrentCurrencyStore.js +18 -0
- package/cjs/stores/index.js +8 -1
- package/cjs/utils/gear/grc20.js +141 -0
- package/cjs/utils/gear/index.js +16 -0
- package/cjs/utils/index.js +40 -28
- package/koni/api/dotsama/transfer.js +13 -2
- package/koni/api/staking/bonding/relayChain.d.ts +1 -2
- package/koni/api/staking/bonding/relayChain.js +6 -0
- package/koni/api/tokens/wasm/utils.js +5 -3
- package/koni/background/handlers/State.js +2 -0
- package/package.json +32 -15
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/subscribe/index.js +1 -1
- package/services/balance-service/helpers/subscribe/substrate/index.js +67 -2
- package/services/chain-service/constants.d.ts +1 -0
- package/services/chain-service/constants.js +8 -1
- package/services/chain-service/handler/EvmChainHandler.d.ts +1 -1
- package/services/chain-service/handler/EvmChainHandler.js +1 -1
- package/services/chain-service/handler/SubstrateApi.js +6 -0
- package/services/chain-service/handler/SubstrateChainHandler.d.ts +4 -1
- package/services/chain-service/handler/SubstrateChainHandler.js +76 -57
- package/services/chain-service/index.js +17 -8
- package/services/chain-service/types.js +1 -1
- package/services/chain-service/utils/index.d.ts +4 -0
- package/services/chain-service/utils/index.js +30 -15
- package/services/chain-service/utils/patch.js +1 -1
- package/services/earning-service/constants/chains.js +2 -2
- package/services/earning-service/handlers/native-staking/relay-chain.js +3 -0
- package/services/earning-service/handlers/nomination-pool/index.js +1 -0
- package/services/price-service/index.d.ts +4 -1
- package/services/price-service/index.js +31 -17
- package/stores/CurrentCurrencyStore.d.ts +5 -0
- package/stores/CurrentCurrencyStore.js +10 -0
- package/stores/index.d.ts +1 -0
- package/stores/index.js +2 -1
- package/utils/gear/grc20.d.ts +29 -0
- package/utils/gear/grc20.js +131 -0
- package/utils/gear/index.d.ts +1 -0
- package/utils/gear/index.js +4 -0
- package/utils/index.d.ts +6 -5
- package/utils/index.js +7 -6
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-koni-ui authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { EXTENSION_PREFIX } from '@subwallet/extension-base/defaults';
|
|
5
|
+
import SubscribableStore from '@subwallet/extension-base/stores/SubscribableStore';
|
|
6
|
+
export default class CurrentCurrencyStore extends SubscribableStore {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(EXTENSION_PREFIX ? `${EXTENSION_PREFIX}current_currency` : null);
|
|
9
|
+
}
|
|
10
|
+
}
|
package/stores/index.d.ts
CHANGED
package/stores/index.js
CHANGED
|
@@ -3,4 +3,5 @@
|
|
|
3
3
|
|
|
4
4
|
export { default as AccountsStore } from "./Accounts.js";
|
|
5
5
|
export { default as MetadataStore } from "./Metadata.js";
|
|
6
|
-
export { default as CurrentAccountStore } from "./CurrentAccountStore.js";
|
|
6
|
+
export { default as CurrentAccountStore } from "./CurrentAccountStore.js";
|
|
7
|
+
export { default as CurrentCurrencyStore } from "./CurrentCurrencyStore.js";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { GearApi } from '@gear-js/api';
|
|
3
|
+
import { TransactionBuilder } from 'sails-js';
|
|
4
|
+
import { ApiPromise } from '@polkadot/api';
|
|
5
|
+
export declare type ActorId = `0x${string}`;
|
|
6
|
+
export declare type U256 = bigint;
|
|
7
|
+
export declare const DEFAULT_GEAR_ADDRESS: {
|
|
8
|
+
ALICE: string;
|
|
9
|
+
BOB: string;
|
|
10
|
+
};
|
|
11
|
+
export declare class GRC20 {
|
|
12
|
+
api: GearApi;
|
|
13
|
+
programId: `0x${string}`;
|
|
14
|
+
private registry;
|
|
15
|
+
constructor(api: GearApi, programId?: `0x${string}`);
|
|
16
|
+
newCtorFromCode(code: Uint8Array | Buffer, name: string, symbol: string, decimals: number | string): TransactionBuilder<null>;
|
|
17
|
+
newCtorFromCodeId(codeId: `0x${string}`, name: string, symbol: string, decimals: number | string): TransactionBuilder<null>;
|
|
18
|
+
approve(spender: ActorId, value: U256): TransactionBuilder<boolean>;
|
|
19
|
+
fromTransfer(from: ActorId, to: ActorId, value: U256): TransactionBuilder<boolean>;
|
|
20
|
+
setBalance(newBalance: U256): TransactionBuilder<boolean>;
|
|
21
|
+
transfer(to: ActorId, value: U256): TransactionBuilder<boolean>;
|
|
22
|
+
allowance(owner: ActorId, spender: ActorId, originAddress: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise<U256>;
|
|
23
|
+
balanceOf(owner: ActorId, originAddress: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise<U256>;
|
|
24
|
+
decimals(originAddress: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise<number | string>;
|
|
25
|
+
name(originAddress: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise<string>;
|
|
26
|
+
symbol(originAddress: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise<string>;
|
|
27
|
+
totalSupply(originAddress: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise<U256>;
|
|
28
|
+
}
|
|
29
|
+
export declare function getGRC20ContractPromise(apiPromise: ApiPromise, contractAddress: string): GRC20;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// https://github.com/breathx/gear-erc20/blob/master/js/src/lib.ts
|
|
5
|
+
|
|
6
|
+
import { decodeAddress } from '@gear-js/api';
|
|
7
|
+
import { TransactionBuilder } from 'sails-js';
|
|
8
|
+
import { TypeRegistry } from '@polkadot/types';
|
|
9
|
+
export const DEFAULT_GEAR_ADDRESS = {
|
|
10
|
+
ALICE: '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY',
|
|
11
|
+
BOB: '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty'
|
|
12
|
+
};
|
|
13
|
+
export class GRC20 {
|
|
14
|
+
constructor(api, programId = '0x') {
|
|
15
|
+
this.api = api;
|
|
16
|
+
this.programId = programId;
|
|
17
|
+
const types = {
|
|
18
|
+
ActorId: '([u8; 32])',
|
|
19
|
+
U256: '([u64; 4])'
|
|
20
|
+
};
|
|
21
|
+
this.registry = new TypeRegistry();
|
|
22
|
+
this.registry.setKnownTypes({
|
|
23
|
+
types
|
|
24
|
+
});
|
|
25
|
+
this.registry.register(types);
|
|
26
|
+
}
|
|
27
|
+
newCtorFromCode(code, name, symbol, decimals) {
|
|
28
|
+
const builder = new TransactionBuilder(this.api, this.registry, 'upload_program', ['New', name, symbol, decimals], '(String, String, String, u8)', 'String', code);
|
|
29
|
+
this.programId = builder.programId;
|
|
30
|
+
return builder;
|
|
31
|
+
}
|
|
32
|
+
newCtorFromCodeId(codeId, name, symbol, decimals) {
|
|
33
|
+
const builder = new TransactionBuilder(this.api, this.registry, 'create_program', ['New', name, symbol, decimals], '(String, String, String, u8)', 'String', codeId);
|
|
34
|
+
this.programId = builder.programId;
|
|
35
|
+
return builder;
|
|
36
|
+
}
|
|
37
|
+
approve(spender, value) {
|
|
38
|
+
return new TransactionBuilder(this.api, this.registry, 'send_message', ['Approve', spender, value], '(String, ActorId, U256)', 'bool', this.programId);
|
|
39
|
+
}
|
|
40
|
+
fromTransfer(from, to, value) {
|
|
41
|
+
return new TransactionBuilder(this.api, this.registry, 'send_message', ['FromTransfer', from, to, value], '(String, ActorId, ActorId, U256)', 'bool', this.programId);
|
|
42
|
+
}
|
|
43
|
+
setBalance(newBalance) {
|
|
44
|
+
return new TransactionBuilder(this.api, this.registry, 'send_message', ['SetBalance', newBalance], '(String, U256)', 'bool', this.programId);
|
|
45
|
+
}
|
|
46
|
+
transfer(to, value) {
|
|
47
|
+
return new TransactionBuilder(this.api, this.registry, 'send_message', ['Transfer', to, value], '(String, ActorId, U256)', 'bool', this.programId);
|
|
48
|
+
}
|
|
49
|
+
async allowance(owner, spender, originAddress, value, atBlock) {
|
|
50
|
+
const payload = this.registry.createType('(String, ActorId, ActorId)', ['Allowance', owner, spender]).toU8a();
|
|
51
|
+
const reply = await this.api.message.calculateReply({
|
|
52
|
+
destination: this.programId,
|
|
53
|
+
origin: decodeAddress(originAddress),
|
|
54
|
+
payload,
|
|
55
|
+
value: value || 0,
|
|
56
|
+
gasLimit: this.api.blockGasLimit.toBigInt(),
|
|
57
|
+
at: atBlock
|
|
58
|
+
});
|
|
59
|
+
const result = this.registry.createType('(String, U256)', reply.payload);
|
|
60
|
+
return result[1].toBigInt();
|
|
61
|
+
}
|
|
62
|
+
async balanceOf(owner, originAddress, value, atBlock) {
|
|
63
|
+
const payload = this.registry.createType('(String, ActorId)', ['BalanceOf', owner]).toU8a();
|
|
64
|
+
const reply = await this.api.message.calculateReply({
|
|
65
|
+
destination: this.programId,
|
|
66
|
+
origin: decodeAddress(originAddress),
|
|
67
|
+
payload,
|
|
68
|
+
value: value || 0,
|
|
69
|
+
gasLimit: this.api.blockGasLimit.toBigInt(),
|
|
70
|
+
at: atBlock
|
|
71
|
+
});
|
|
72
|
+
const result = this.registry.createType('(String, U256)', reply.payload);
|
|
73
|
+
return result[1].toBigInt();
|
|
74
|
+
}
|
|
75
|
+
async decimals(originAddress, value, atBlock) {
|
|
76
|
+
const payload = this.registry.createType('String', 'Decimals').toU8a();
|
|
77
|
+
const reply = await this.api.message.calculateReply({
|
|
78
|
+
destination: this.programId,
|
|
79
|
+
origin: decodeAddress(originAddress),
|
|
80
|
+
payload,
|
|
81
|
+
value: value || 0,
|
|
82
|
+
gasLimit: this.api.blockGasLimit.toBigInt(),
|
|
83
|
+
at: atBlock
|
|
84
|
+
});
|
|
85
|
+
const result = this.registry.createType('(String, u8)', reply.payload);
|
|
86
|
+
return result[1].toNumber();
|
|
87
|
+
}
|
|
88
|
+
async name(originAddress, value, atBlock) {
|
|
89
|
+
const payload = this.registry.createType('String', 'Name').toU8a();
|
|
90
|
+
const reply = await this.api.message.calculateReply({
|
|
91
|
+
destination: this.programId,
|
|
92
|
+
origin: decodeAddress(originAddress),
|
|
93
|
+
payload,
|
|
94
|
+
value: value || 0,
|
|
95
|
+
gasLimit: this.api.blockGasLimit.toBigInt(),
|
|
96
|
+
at: atBlock
|
|
97
|
+
});
|
|
98
|
+
const result = this.registry.createType('(String, String)', reply.payload);
|
|
99
|
+
return result[1].toString();
|
|
100
|
+
}
|
|
101
|
+
async symbol(originAddress, value, atBlock) {
|
|
102
|
+
const payload = this.registry.createType('String', 'Symbol').toU8a();
|
|
103
|
+
const reply = await this.api.message.calculateReply({
|
|
104
|
+
destination: this.programId,
|
|
105
|
+
origin: decodeAddress(originAddress),
|
|
106
|
+
payload,
|
|
107
|
+
value: value || 0,
|
|
108
|
+
gasLimit: this.api.blockGasLimit.toBigInt(),
|
|
109
|
+
at: atBlock
|
|
110
|
+
});
|
|
111
|
+
const result = this.registry.createType('(String, String)', reply.payload);
|
|
112
|
+
return result[1].toString();
|
|
113
|
+
}
|
|
114
|
+
async totalSupply(originAddress, value, atBlock) {
|
|
115
|
+
const payload = this.registry.createType('String', 'TotalSupply').toU8a();
|
|
116
|
+
const reply = await this.api.message.calculateReply({
|
|
117
|
+
destination: this.programId,
|
|
118
|
+
origin: decodeAddress(originAddress),
|
|
119
|
+
payload,
|
|
120
|
+
value: value || 0,
|
|
121
|
+
gasLimit: this.api.blockGasLimit.toBigInt(),
|
|
122
|
+
at: atBlock
|
|
123
|
+
});
|
|
124
|
+
const result = this.registry.createType('(String, U256)', reply.payload);
|
|
125
|
+
return result[1].toBigInt();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
export function getGRC20ContractPromise(apiPromise, contractAddress) {
|
|
129
|
+
const gearApi = apiPromise;
|
|
130
|
+
return new GRC20(gearApi, contractAddress);
|
|
131
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './grc20';
|
package/utils/index.d.ts
CHANGED
|
@@ -45,12 +45,13 @@ export * from './array';
|
|
|
45
45
|
export * from './asset';
|
|
46
46
|
export * from './environment';
|
|
47
47
|
export * from './eth';
|
|
48
|
-
export * from './
|
|
48
|
+
export * from './fetchEvmChainInfo';
|
|
49
|
+
export * from './fetchStaticData';
|
|
50
|
+
export * from './gear';
|
|
49
51
|
export * from './lazy';
|
|
52
|
+
export * from './number';
|
|
53
|
+
export * from './object';
|
|
50
54
|
export * from './promise';
|
|
51
55
|
export * from './registry';
|
|
52
|
-
export * from './translate';
|
|
53
|
-
export * from './object';
|
|
54
|
-
export * from './fetchStaticData';
|
|
55
|
-
export * from './fetchEvmChainInfo';
|
|
56
56
|
export * from './swap';
|
|
57
|
+
export * from './translate';
|
package/utils/index.js
CHANGED
|
@@ -347,12 +347,13 @@ export * from "./array.js";
|
|
|
347
347
|
export * from "./asset.js";
|
|
348
348
|
export * from "./environment.js";
|
|
349
349
|
export * from "./eth.js";
|
|
350
|
-
export * from "./
|
|
350
|
+
export * from "./fetchEvmChainInfo.js";
|
|
351
|
+
export * from "./fetchStaticData.js";
|
|
352
|
+
export * from "./gear/index.js";
|
|
351
353
|
export * from "./lazy.js";
|
|
354
|
+
export * from "./number.js";
|
|
355
|
+
export * from "./object.js";
|
|
352
356
|
export * from "./promise.js";
|
|
353
357
|
export * from "./registry.js";
|
|
354
|
-
export * from "./
|
|
355
|
-
export * from "./
|
|
356
|
-
export * from "./fetchStaticData.js";
|
|
357
|
-
export * from "./fetchEvmChainInfo.js";
|
|
358
|
-
export * from "./swap.js";
|
|
358
|
+
export * from "./swap.js";
|
|
359
|
+
export * from "./translate.js";
|