@talismn/balances 0.3.0 → 0.3.1
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/CHANGELOG.md +13 -0
- package/dist/{BalanceModule.d.ts → declarations/src/BalanceModule.d.ts} +5 -5
- package/dist/{TalismanBalancesDatabase.d.ts → declarations/src/TalismanBalancesDatabase.d.ts} +0 -0
- package/dist/{helpers.d.ts → declarations/src/helpers.d.ts} +0 -0
- package/dist/{index.d.ts → declarations/src/index.d.ts} +0 -0
- package/dist/{log.d.ts → declarations/src/log.d.ts} +0 -0
- package/dist/{plugins.d.ts → declarations/src/plugins.d.ts} +0 -0
- package/dist/declarations/src/types/addresses.d.ts +4 -0
- package/dist/{types → declarations/src/types}/balances.d.ts +4 -4
- package/dist/{types → declarations/src/types}/balancetypes.d.ts +12 -12
- package/dist/{types → declarations/src/types}/index.d.ts +0 -0
- package/dist/{types → declarations/src/types}/subscriptions.d.ts +1 -1
- package/dist/talismn-balances.cjs.d.ts +1 -0
- package/dist/talismn-balances.cjs.dev.js +705 -0
- package/dist/talismn-balances.cjs.js +7 -0
- package/dist/talismn-balances.cjs.prod.js +705 -0
- package/dist/talismn-balances.esm.js +683 -0
- package/package.json +20 -15
- package/plugins/dist/talismn-balances-plugins.cjs.d.ts +1 -0
- package/plugins/dist/talismn-balances-plugins.cjs.dev.js +2 -0
- package/plugins/dist/talismn-balances-plugins.cjs.js +7 -0
- package/plugins/dist/talismn-balances-plugins.cjs.prod.js +2 -0
- package/plugins/dist/talismn-balances-plugins.esm.js +1 -0
- package/plugins/package.json +2 -3
- package/dist/BalanceModule.js +0 -29
- package/dist/TalismanBalancesDatabase.js +0 -23
- package/dist/helpers.js +0 -99
- package/dist/index.js +0 -31
- package/dist/log.js +0 -10
- package/dist/plugins.js +0 -2
- package/dist/types/addresses.d.ts +0 -4
- package/dist/types/addresses.js +0 -2
- package/dist/types/balances.js +0 -471
- package/dist/types/balancetypes.js +0 -34
- package/dist/types/index.js +0 -20
- package/dist/types/subscriptions.js +0 -2
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@talismn/balances",
|
3
|
-
"version": "0.3.
|
3
|
+
"version": "0.3.1",
|
4
4
|
"author": "Talisman",
|
5
5
|
"homepage": "https://talisman.xyz",
|
6
6
|
"license": "UNLICENSED",
|
@@ -12,8 +12,8 @@
|
|
12
12
|
"type": "git",
|
13
13
|
"url": "https://github.com/talismansociety/talisman.git"
|
14
14
|
},
|
15
|
-
"main": "dist/
|
16
|
-
"
|
15
|
+
"main": "dist/talismn-balances.cjs.js",
|
16
|
+
"module": "dist/talismn-balances.esm.js",
|
17
17
|
"files": [
|
18
18
|
"/dist",
|
19
19
|
"/plugins"
|
@@ -22,36 +22,41 @@
|
|
22
22
|
"node": ">=14"
|
23
23
|
},
|
24
24
|
"scripts": {
|
25
|
-
"dev": "tsc --watch --declarationMap",
|
26
|
-
"build": "tsc --declarationMap",
|
27
|
-
"build:packages:prod": "rm -rf dist && tsc",
|
28
|
-
"prepack": "yarn build:packages:prod",
|
29
25
|
"test": "jest",
|
30
26
|
"lint": "eslint . --max-warnings 0",
|
31
27
|
"clean": "rm -rf dist && rm -rf .turbo rm -rf node_modules"
|
32
28
|
},
|
33
29
|
"dependencies": {
|
34
|
-
"@
|
35
|
-
"@talismn/chain-connector
|
36
|
-
"@talismn/
|
37
|
-
"@talismn/
|
38
|
-
"@talismn/
|
30
|
+
"@polkadot/types": "9.10.5",
|
31
|
+
"@talismn/chain-connector": "^0.4.1",
|
32
|
+
"@talismn/chain-connector-evm": "^0.4.1",
|
33
|
+
"@talismn/chaindata-provider": "^0.4.1",
|
34
|
+
"@talismn/token-rates": "^0.1.13",
|
35
|
+
"@talismn/util": "^0.1.6",
|
36
|
+
"anylogger": "^1.0.11",
|
37
|
+
"dexie": "^3.2.2",
|
39
38
|
"lodash": "^4.17.21",
|
40
39
|
"typescript-memoize": "^1.1.0"
|
41
40
|
},
|
42
41
|
"devDependencies": {
|
43
|
-
"@talismn/eslint-config": "^0.0.
|
44
|
-
"@talismn/tsconfig": "^0.0.
|
42
|
+
"@talismn/eslint-config": "^0.0.1",
|
43
|
+
"@talismn/tsconfig": "^0.0.2",
|
45
44
|
"@types/jest": "^27.5.1",
|
46
45
|
"eslint": "^8.4.0",
|
47
46
|
"jest": "^28.1.0",
|
48
47
|
"ts-jest": "^28.0.2",
|
49
48
|
"typescript": "^4.6.4"
|
50
49
|
},
|
50
|
+
"preconstruct": {
|
51
|
+
"entrypoints": [
|
52
|
+
"index.ts",
|
53
|
+
"plugins.ts"
|
54
|
+
]
|
55
|
+
},
|
51
56
|
"eslintConfig": {
|
52
57
|
"root": true,
|
53
58
|
"extends": [
|
54
|
-
"@talismn/eslint-config"
|
59
|
+
"@talismn/eslint-config/base"
|
55
60
|
]
|
56
61
|
}
|
57
62
|
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from "../../dist/declarations/src/plugins";
|
@@ -0,0 +1 @@
|
|
1
|
+
|
package/plugins/package.json
CHANGED
package/dist/BalanceModule.js
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.DefaultBalanceModule = void 0;
|
4
|
-
// TODO: Document default balances module purpose/usage
|
5
|
-
const DefaultBalanceModule = (type) => ({
|
6
|
-
get type() {
|
7
|
-
return type;
|
8
|
-
},
|
9
|
-
async fetchSubstrateChainMeta() {
|
10
|
-
return null;
|
11
|
-
},
|
12
|
-
async fetchEvmChainMeta() {
|
13
|
-
return null;
|
14
|
-
},
|
15
|
-
async fetchSubstrateChainTokens() {
|
16
|
-
return Promise.resolve({});
|
17
|
-
},
|
18
|
-
async fetchEvmChainTokens() {
|
19
|
-
return Promise.resolve({});
|
20
|
-
},
|
21
|
-
async subscribeBalances(_chainConnectors, _chaindataProvider, _addressesByToken, callback) {
|
22
|
-
callback(new Error("Balance subscriptions are not implemented in this module."));
|
23
|
-
return () => { };
|
24
|
-
},
|
25
|
-
async fetchBalances() {
|
26
|
-
throw new Error("Balance fetching is not implemented in this module.");
|
27
|
-
},
|
28
|
-
});
|
29
|
-
exports.DefaultBalanceModule = DefaultBalanceModule;
|
@@ -1,23 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.db = exports.TalismanBalancesDatabase = void 0;
|
4
|
-
const dexie_1 = require("dexie");
|
5
|
-
class TalismanBalancesDatabase extends dexie_1.Dexie {
|
6
|
-
balances;
|
7
|
-
constructor() {
|
8
|
-
super("TalismanBalances");
|
9
|
-
// https://dexie.org/docs/Tutorial/Design#database-versioning
|
10
|
-
this.version(1).stores({
|
11
|
-
// You only need to specify properties that you wish to index.
|
12
|
-
// The object store will allow any properties on your stored objects but you can only query them by indexed properties
|
13
|
-
// https://dexie.org/docs/API-Reference#declare-database
|
14
|
-
//
|
15
|
-
// Never index properties containing images, movies or large (huge) strings. Store them in IndexedDB, yes! but just don’t index them!
|
16
|
-
// https://dexie.org/docs/Version/Version.stores()#warning
|
17
|
-
balances: "id, source, status, address, tokenId",
|
18
|
-
});
|
19
|
-
// this.on("ready", async () => {})
|
20
|
-
}
|
21
|
-
}
|
22
|
-
exports.TalismanBalancesDatabase = TalismanBalancesDatabase;
|
23
|
-
exports.db = new TalismanBalancesDatabase();
|
package/dist/helpers.js
DELETED
@@ -1,99 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.StorageHelper = exports.filterMirrorTokens = exports.balances = void 0;
|
7
|
-
const types_1 = require("@polkadot/types");
|
8
|
-
const log_1 = __importDefault(require("./log"));
|
9
|
-
async function balances(balanceModule, chainConnectors, chaindataProvider, addressesByToken, callback) {
|
10
|
-
// subscription request
|
11
|
-
if (callback !== undefined)
|
12
|
-
return await balanceModule.subscribeBalances(chainConnectors, chaindataProvider, addressesByToken, callback);
|
13
|
-
// one-off request
|
14
|
-
return await balanceModule.fetchBalances(chainConnectors, chaindataProvider, addressesByToken);
|
15
|
-
}
|
16
|
-
exports.balances = balances;
|
17
|
-
const filterMirrorTokens = (balance, i, balances) => {
|
18
|
-
// TODO implement a mirrorOf property, which should be set from chaindata
|
19
|
-
const mirrorOf = balance.token?.mirrorOf;
|
20
|
-
return !mirrorOf || !balances.find((b) => b.tokenId === mirrorOf);
|
21
|
-
};
|
22
|
-
exports.filterMirrorTokens = filterMirrorTokens;
|
23
|
-
/**
|
24
|
-
* Used by a variety of balance modules to help encode and decode substrate state calls.
|
25
|
-
*/
|
26
|
-
class StorageHelper {
|
27
|
-
#registry;
|
28
|
-
#storageKey;
|
29
|
-
#module;
|
30
|
-
#method;
|
31
|
-
#parameters;
|
32
|
-
tags = null;
|
33
|
-
constructor(registry, module, method, ...parameters) {
|
34
|
-
this.#registry = registry;
|
35
|
-
this.#module = module;
|
36
|
-
this.#method = method;
|
37
|
-
this.#parameters = parameters;
|
38
|
-
const _metadataVersion = 0; // is not used inside the decorateStorage function
|
39
|
-
let query;
|
40
|
-
try {
|
41
|
-
query = (0, types_1.decorateStorage)(registry, registry.metadata, _metadataVersion);
|
42
|
-
}
|
43
|
-
catch (error) {
|
44
|
-
log_1.default.debug(`Failed to decorate storage: ${error.message}`);
|
45
|
-
this.#storageKey = null;
|
46
|
-
}
|
47
|
-
try {
|
48
|
-
if (!query)
|
49
|
-
throw new Error(`decoratedStorage unavailable`);
|
50
|
-
this.#storageKey = new types_1.StorageKey(registry, parameters ? [query[module][method], parameters] : query[module][method]);
|
51
|
-
}
|
52
|
-
catch (error) {
|
53
|
-
log_1.default.debug(`Failed to create storageKey ${module || "unknown"}.${method || "unknown"}: ${error.message}`);
|
54
|
-
this.#storageKey = null;
|
55
|
-
}
|
56
|
-
}
|
57
|
-
get stateKey() {
|
58
|
-
return this.#storageKey?.toHex();
|
59
|
-
}
|
60
|
-
get module() {
|
61
|
-
return this.#module;
|
62
|
-
}
|
63
|
-
get method() {
|
64
|
-
return this.#method;
|
65
|
-
}
|
66
|
-
get parameters() {
|
67
|
-
return this.#parameters;
|
68
|
-
}
|
69
|
-
tag(tags) {
|
70
|
-
this.tags = tags;
|
71
|
-
return this;
|
72
|
-
}
|
73
|
-
decode(input) {
|
74
|
-
if (!this.#storageKey)
|
75
|
-
return;
|
76
|
-
return this.#decodeStorageScaleResponse(this.#registry, this.#storageKey, input);
|
77
|
-
}
|
78
|
-
#decodeStorageScaleResponse(typeRegistry, storageKey, input) {
|
79
|
-
if (input === undefined || input === null)
|
80
|
-
return;
|
81
|
-
const type = storageKey.outputType || "Raw";
|
82
|
-
const meta = storageKey.meta || {
|
83
|
-
fallback: undefined,
|
84
|
-
modifier: { isOptional: true },
|
85
|
-
type: { asMap: { linked: { isTrue: false } }, isMap: false },
|
86
|
-
};
|
87
|
-
try {
|
88
|
-
return typeRegistry.createTypeUnsafe(type, [
|
89
|
-
meta.modifier.isOptional
|
90
|
-
? typeRegistry.createTypeUnsafe(type, [input], { isPedantic: true })
|
91
|
-
: input,
|
92
|
-
], { isOptional: meta.modifier.isOptional, isPedantic: !meta.modifier.isOptional });
|
93
|
-
}
|
94
|
-
catch (error) {
|
95
|
-
throw new Error(`Unable to decode storage ${storageKey.section || "unknown"}.${storageKey.method || "unknown"}: ${error.message}`);
|
96
|
-
}
|
97
|
-
}
|
98
|
-
}
|
99
|
-
exports.StorageHelper = StorageHelper;
|
package/dist/index.js
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
//
|
3
|
-
// NOTE: Do not export `./plugins` from here!
|
4
|
-
// Doing so will introduce a circular dependency!
|
5
|
-
// It is a separate entrypoint meant to be used like this:
|
6
|
-
//
|
7
|
-
// import { PluginBalanceTypes } from '@talismn/balances/plugins'
|
8
|
-
//
|
9
|
-
// Not this:
|
10
|
-
//
|
11
|
-
// import { PluginBalanceTypes } from '@talismn/balances'
|
12
|
-
//
|
13
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
14
|
-
if (k2 === undefined) k2 = k;
|
15
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
16
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
17
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
18
|
-
}
|
19
|
-
Object.defineProperty(o, k2, desc);
|
20
|
-
}) : (function(o, m, k, k2) {
|
21
|
-
if (k2 === undefined) k2 = k;
|
22
|
-
o[k2] = m[k];
|
23
|
-
}));
|
24
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
25
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
26
|
-
};
|
27
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
28
|
-
__exportStar(require("./BalanceModule"), exports);
|
29
|
-
__exportStar(require("./TalismanBalancesDatabase"), exports);
|
30
|
-
__exportStar(require("./helpers"), exports);
|
31
|
-
__exportStar(require("./types"), exports);
|
package/dist/log.js
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
const anylogger_1 = __importDefault(require("anylogger"));
|
7
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
8
|
-
const { name } = require("../package.json");
|
9
|
-
// import { name } from "../package.json"
|
10
|
-
exports.default = (0, anylogger_1.default)(name);
|
package/dist/plugins.js
DELETED
package/dist/types/addresses.js
DELETED