@tari-project/tarijs 0.5.2 → 0.5.3
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/package.json +1 -1
- package/packages/builders/package.json +1 -1
- package/packages/indexer_provider/package.json +1 -1
- package/packages/metamask_signer/package.json +1 -1
- package/packages/tari_permissions/package.json +1 -1
- package/packages/tari_provider/package.json +1 -1
- package/packages/tari_signer/package.json +1 -1
- package/packages/tari_universe/package.json +1 -1
- package/packages/tarijs/package.json +3 -3
- package/packages/tarijs/src/index.ts +13 -10
- package/packages/tarijs/src/templates/Coin.ts +58 -0
- package/packages/tarijs/src/templates/Tex.ts +54 -0
- package/packages/tarijs/src/templates/index.ts +2 -0
- package/packages/tarijs/test/integration-tests/.env +1 -0
- package/packages/tarijs/{integration-tests → test/integration-tests}/wallet_daemon/json_rpc_provider.spec.ts +34 -7
- package/packages/tarijs/{src → test/unit-tests}/cbor.spec.ts +3 -3
- package/packages/tarijs/tsconfig.json +1 -3
- package/packages/tarijs/vitest.config.ts +3 -3
- package/packages/tarijs_types/package.json +1 -1
- package/packages/tarijs_types/src/helpers/index.ts +2 -0
- package/packages/tarijs_types/src/index.ts +8 -0
- package/packages/wallet_daemon/package.json +1 -1
- package/packages/walletconnect/package.json +1 -1
- package/packages/tarijs/integration-tests/.env +0 -1
- /package/packages/{tarijs/src → tarijs_types/src/helpers}/cbor.ts +0 -0
- /package/packages/{tarijs/src/utils.ts → tarijs_types/src/helpers/hexString.ts} +0 -0
- /package/packages/{tarijs → tarijs_types}/src/network.ts +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "@tari-project/tarijs",
|
|
3
|
-
"version": "0.5.
|
|
2
|
+
"name": "@tari-project/tarijs-all",
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "tsc -b",
|
|
11
|
-
"test": "vitest run
|
|
11
|
+
"test": "vitest run unit-tests",
|
|
12
12
|
"integration-tests": "vitest run integration-tests"
|
|
13
13
|
},
|
|
14
14
|
"keywords": [],
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
+
import { MetaMaskInpageProvider } from "@metamask/providers";
|
|
1
2
|
import { TariSigner } from "@tari-project/tari-signer";
|
|
2
3
|
import { TariProvider } from "@tari-project/tari-provider";
|
|
3
|
-
import * as utils from "./utils";
|
|
4
|
-
import { Network } from "./network";
|
|
5
4
|
import { MetamaskTariSigner } from "@tari-project/metamask-signer";
|
|
6
|
-
import { MetaMaskInpageProvider } from "@metamask/providers";
|
|
7
5
|
import { WalletDaemonTariSigner, WalletDaemonParameters, TariPermissions } from "@tari-project/wallet-daemon-signer";
|
|
8
6
|
import { TariUniverseSigner, TariUniverseSignerParameters } from "@tari-project/tari-universe-signer";
|
|
9
|
-
import * as permissions from "@tari-project/tari-permissions";
|
|
10
7
|
import { WalletConnectTariSigner } from "@tari-project/wallet-connect-signer";
|
|
11
8
|
import {
|
|
12
9
|
TransactionBuilder,
|
|
@@ -17,9 +14,6 @@ import {
|
|
|
17
14
|
fromWorkspace,
|
|
18
15
|
toWorkspace,
|
|
19
16
|
} from "@tari-project/tarijs-builders";
|
|
20
|
-
import * as templates from "./templates";
|
|
21
|
-
import { parseCbor, getCborValueByPath } from "./cbor";
|
|
22
|
-
import { IndexerProvider, IndexerProviderParameters } from "@tari-project/indexer-provider";
|
|
23
17
|
import {
|
|
24
18
|
convertStringToTransactionStatus,
|
|
25
19
|
convertHexStringToU256Array,
|
|
@@ -36,11 +30,20 @@ import {
|
|
|
36
30
|
TemplateDefinition,
|
|
37
31
|
SubstateRequirement,
|
|
38
32
|
Substate,
|
|
33
|
+
Network,
|
|
34
|
+
fromHexString,
|
|
35
|
+
toHexString,
|
|
36
|
+
parseCbor,
|
|
37
|
+
getCborValueByPath,
|
|
39
38
|
} from "@tari-project/tarijs-types";
|
|
39
|
+
import { IndexerProvider, IndexerProviderParameters } from "@tari-project/indexer-provider";
|
|
40
|
+
import * as templates from "./templates";
|
|
41
|
+
import * as permissions from "@tari-project/tari-permissions";
|
|
40
42
|
|
|
41
43
|
export * from "@tari-project/tarijs-types";
|
|
42
44
|
export {
|
|
43
|
-
|
|
45
|
+
permissions,
|
|
46
|
+
templates,
|
|
44
47
|
Network,
|
|
45
48
|
TariSigner,
|
|
46
49
|
TariProvider,
|
|
@@ -76,8 +79,8 @@ export {
|
|
|
76
79
|
convertU256ToHexString,
|
|
77
80
|
createNftAddressFromResource,
|
|
78
81
|
createNftAddressFromToken,
|
|
79
|
-
permissions,
|
|
80
|
-
templates,
|
|
81
82
|
parseCbor,
|
|
82
83
|
getCborValueByPath,
|
|
84
|
+
fromHexString,
|
|
85
|
+
toHexString,
|
|
83
86
|
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Amount, ResourceAddress, TariFunctionDefinition, TariMethodDefinition } from "@tari-project/tarijs-builders";
|
|
2
|
+
import { TemplateFactory } from "./TemplateFactory";
|
|
3
|
+
|
|
4
|
+
interface NewFunction extends TariFunctionDefinition {
|
|
5
|
+
functionName: "new";
|
|
6
|
+
args?: [number, string];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface MintFunction extends TariFunctionDefinition {
|
|
10
|
+
functionName: "mint";
|
|
11
|
+
args?: [Amount];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface VaultAddressMethod extends TariMethodDefinition {
|
|
15
|
+
functionName: "vault_address";
|
|
16
|
+
args?: [];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface TakeFreeCoinsMethod extends TariMethodDefinition {
|
|
20
|
+
methodName: "take_free_coins";
|
|
21
|
+
args?: [number];
|
|
22
|
+
}
|
|
23
|
+
interface BalanceMethod extends TariMethodDefinition {
|
|
24
|
+
methodName: "balance";
|
|
25
|
+
args?: [ResourceAddress];
|
|
26
|
+
}
|
|
27
|
+
interface BurnCoinsMethod extends TariMethodDefinition {
|
|
28
|
+
methodName: "burn_coins";
|
|
29
|
+
args?: [Amount];
|
|
30
|
+
}
|
|
31
|
+
interface TotalSupplyMethod extends TariMethodDefinition {
|
|
32
|
+
methodName: "total_supply";
|
|
33
|
+
args?: [];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export class CoinTemplate extends TemplateFactory {
|
|
37
|
+
public new: NewFunction;
|
|
38
|
+
public mint: MintFunction;
|
|
39
|
+
public takeFreeCoins: TakeFreeCoinsMethod;
|
|
40
|
+
public balance: BalanceMethod;
|
|
41
|
+
public burnCoins: BurnCoinsMethod;
|
|
42
|
+
public totalSupply: TotalSupplyMethod;
|
|
43
|
+
public vaultAddress: VaultAddressMethod;
|
|
44
|
+
|
|
45
|
+
constructor(public templateAddress: string) {
|
|
46
|
+
super(templateAddress);
|
|
47
|
+
this.new = this._defineFunction<NewFunction>("new");
|
|
48
|
+
this.mint = this._defineFunction<MintFunction>("mint");
|
|
49
|
+
this.takeFreeCoins = this._defineMethod<TakeFreeCoinsMethod>("take_free_coins");
|
|
50
|
+
this.balance = this._defineMethod<BalanceMethod>("balance");
|
|
51
|
+
this.burnCoins = this._defineMethod<BurnCoinsMethod>("burn_coins");
|
|
52
|
+
this.totalSupply = this._defineMethod<TotalSupplyMethod>("total_supply");
|
|
53
|
+
this.vaultAddress = this._defineMethod<VaultAddressMethod>("vault_address");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
protected _initFunctions(): void {}
|
|
57
|
+
protected _initMethods(): void {}
|
|
58
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ResourceAddress,
|
|
3
|
+
TariFunctionDefinition,
|
|
4
|
+
TariMethodDefinition,
|
|
5
|
+
WorkspaceArg,
|
|
6
|
+
} from "@tari-project/tarijs-builders";
|
|
7
|
+
import { TemplateFactory } from "./TemplateFactory";
|
|
8
|
+
|
|
9
|
+
interface NewFunction extends TariFunctionDefinition {
|
|
10
|
+
functionName: "new";
|
|
11
|
+
args?: [number];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface SwapMethod extends TariMethodDefinition {
|
|
15
|
+
methodName: "swap";
|
|
16
|
+
args?: [WorkspaceArg, ResourceAddress];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface AddLiquidityMethod extends TariMethodDefinition {
|
|
20
|
+
methodName: "add_liquidity";
|
|
21
|
+
args?: WorkspaceArg[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface RemoveLiquidityMethod extends TariMethodDefinition {
|
|
25
|
+
methodName: "remove_liquidity";
|
|
26
|
+
args?: WorkspaceArg[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface PoolsMethod extends TariMethodDefinition {
|
|
30
|
+
methodName: "pools";
|
|
31
|
+
args?: WorkspaceArg[];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export class TexTemplate extends TemplateFactory {
|
|
35
|
+
public new: NewFunction;
|
|
36
|
+
public swap: SwapMethod;
|
|
37
|
+
public addLiquidity: AddLiquidityMethod;
|
|
38
|
+
public removeLiquidity: RemoveLiquidityMethod;
|
|
39
|
+
public pools: PoolsMethod;
|
|
40
|
+
|
|
41
|
+
constructor(public templateAddress: string) {
|
|
42
|
+
super(templateAddress);
|
|
43
|
+
this.new = this._defineFunction<NewFunction>("new");
|
|
44
|
+
this.swap = this._defineMethod<SwapMethod>("swap");
|
|
45
|
+
this.addLiquidity = this._defineMethod<AddLiquidityMethod>("add_liquidity");
|
|
46
|
+
this.removeLiquidity = this._defineMethod<RemoveLiquidityMethod>("remove_liquidity");
|
|
47
|
+
this.pools = this._defineMethod<PoolsMethod>("pools");
|
|
48
|
+
this._initFunctions();
|
|
49
|
+
this._initMethods();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
protected _initFunctions(): void {}
|
|
53
|
+
protected _initMethods(): void {}
|
|
54
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
WALLET_DAEMON_JSON_RPC_URL=http://127.0.0.1:9000/json_rpc
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { assert, describe, expect, it } from "vitest";
|
|
2
2
|
|
|
3
|
-
import { SubmitTransactionRequest, TariPermissions, WalletDaemonTariSigner } from "
|
|
3
|
+
import { Network, SubmitTransactionRequest, TariPermissions, WalletDaemonTariSigner } from "../../../src";
|
|
4
4
|
|
|
5
5
|
function buildSigner(): Promise<WalletDaemonTariSigner> {
|
|
6
6
|
const permissions = new TariPermissions().addPermission("Admin");
|
|
7
7
|
const serverUrl = process.env.WALLET_DAEMON_JSON_RPC_URL;
|
|
8
|
+
|
|
8
9
|
assert(serverUrl, "WALLET_DAEMON_JSON_RPC_URL must be set");
|
|
9
10
|
return WalletDaemonTariSigner.buildFetchSigner({
|
|
10
11
|
permissions,
|
|
@@ -43,8 +44,14 @@ describe("WalletDaemonTariSigner", () => {
|
|
|
43
44
|
describe("getSubstate", () => {
|
|
44
45
|
it("returns substate details", async () => {
|
|
45
46
|
const signer = await buildSigner();
|
|
46
|
-
const listedSubstates = await signer.listSubstates(
|
|
47
|
+
const listedSubstates = await signer.listSubstates({
|
|
48
|
+
filter_by_template: null,
|
|
49
|
+
filter_by_type: null,
|
|
50
|
+
limit: 1,
|
|
51
|
+
offset: 0,
|
|
52
|
+
});
|
|
47
53
|
const firstSubstate = listedSubstates.substates[0];
|
|
54
|
+
console.log(firstSubstate);
|
|
48
55
|
const substate = await signer.getSubstate(firstSubstate.substate_id);
|
|
49
56
|
|
|
50
57
|
expect(substate).toMatchObject({
|
|
@@ -87,7 +94,7 @@ describe("WalletDaemonTariSigner", () => {
|
|
|
87
94
|
];
|
|
88
95
|
|
|
89
96
|
const request: SubmitTransactionRequest = {
|
|
90
|
-
network:
|
|
97
|
+
network: Network.LocalNet,
|
|
91
98
|
account_id: account.account_id,
|
|
92
99
|
fee_instructions,
|
|
93
100
|
instructions: [],
|
|
@@ -163,27 +170,47 @@ describe("WalletDaemonTariSigner", () => {
|
|
|
163
170
|
describe("listSubstates", () => {
|
|
164
171
|
it("returns substates", async () => {
|
|
165
172
|
const signer = await buildSigner();
|
|
166
|
-
const { substates } = await signer.listSubstates(
|
|
173
|
+
const { substates } = await signer.listSubstates({
|
|
174
|
+
filter_by_template: null,
|
|
175
|
+
filter_by_type: null,
|
|
176
|
+
limit: 10,
|
|
177
|
+
offset: 0,
|
|
178
|
+
});
|
|
167
179
|
|
|
168
180
|
expect(substates.length).toBeGreaterThan(0);
|
|
169
181
|
});
|
|
170
182
|
|
|
171
183
|
it("filters substates by template address", async () => {
|
|
172
184
|
const signer = await buildSigner();
|
|
173
|
-
const { substates } = await signer.listSubstates(
|
|
185
|
+
const { substates } = await signer.listSubstates({
|
|
186
|
+
filter_by_template: null,
|
|
187
|
+
filter_by_type: null,
|
|
188
|
+
limit: 10,
|
|
189
|
+
offset: 0,
|
|
190
|
+
});
|
|
174
191
|
|
|
175
192
|
const substateWithTemplate = substates.find((substate) => substate.template_address);
|
|
176
193
|
assert(substateWithTemplate, "No substate with template found");
|
|
177
194
|
|
|
178
195
|
const templateAddress = substateWithTemplate.template_address;
|
|
179
|
-
const { substates: filteredSubstates } = await signer.listSubstates(
|
|
196
|
+
const { substates: filteredSubstates } = await signer.listSubstates({
|
|
197
|
+
filter_by_template: templateAddress,
|
|
198
|
+
filter_by_type: null,
|
|
199
|
+
limit: 10,
|
|
200
|
+
offset: 0,
|
|
201
|
+
});
|
|
180
202
|
|
|
181
203
|
expect(filteredSubstates.every((substate) => substate.template_address === templateAddress)).toBe(true);
|
|
182
204
|
});
|
|
183
205
|
|
|
184
206
|
it("filters substates by type", async () => {
|
|
185
207
|
const signer = await buildSigner();
|
|
186
|
-
const { substates } = await signer.listSubstates(
|
|
208
|
+
const { substates } = await signer.listSubstates({
|
|
209
|
+
filter_by_template: null,
|
|
210
|
+
filter_by_type: "Component",
|
|
211
|
+
limit: 1,
|
|
212
|
+
offset: 0,
|
|
213
|
+
});
|
|
187
214
|
|
|
188
215
|
expect(substates.every((substate) => substate.module_name)).toBe(true);
|
|
189
216
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BinaryTag, CborValue, convertTaggedValue, getCborValueByPath, parseCbor } from "
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { BinaryTag, CborValue, convertTaggedValue, getCborValueByPath, parseCbor } from "@tari-project/tarijs-types";
|
|
3
3
|
|
|
4
4
|
describe("convertTaggedValue", () => {
|
|
5
5
|
it.each([
|
|
@@ -201,7 +201,7 @@ describe("parseCbor", () => {
|
|
|
201
201
|
expect(parseCbor(value as CborValue)).toEqual(expected);
|
|
202
202
|
});
|
|
203
203
|
});
|
|
204
|
-
|
|
204
|
+
|
|
205
205
|
it.each([{}, { Unknown: 2 }])("throws, when data in unknown format is found", (value: unknown) => {
|
|
206
206
|
expect(() => parseCbor(value as CborValue)).toThrow();
|
|
207
207
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { defineConfig } from
|
|
2
|
-
import { loadEnv } from
|
|
1
|
+
import { defineConfig } from "vitest/config";
|
|
2
|
+
import { loadEnv } from "vite";
|
|
3
3
|
|
|
4
4
|
export default defineConfig({
|
|
5
|
-
root:
|
|
5
|
+
root: ".",
|
|
6
6
|
test: {
|
|
7
7
|
env: loadEnv("", "./integration-tests/", ""),
|
|
8
8
|
},
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { NonFungibleId, NonFungibleToken, ResourceAddress } from "@tari-project/typescript-bindings";
|
|
2
2
|
import { TransactionStatus } from "../TransactionStatus";
|
|
3
|
+
export { fromHexString, toHexString } from "./hexString";
|
|
4
|
+
export { BinaryTag, CborValue, convertTaggedValue, getCborValueByPath, parseCbor } from "./cbor";
|
|
3
5
|
export {
|
|
4
6
|
substateIdToString,
|
|
5
7
|
stringToSubstateId,
|
|
@@ -23,6 +23,7 @@ export { UnsignedTransaction } from "./UnsignedTransaction";
|
|
|
23
23
|
export { VersionedSubstateId } from "./VersionedSubstateId";
|
|
24
24
|
export { WorkspaceArg } from "./Workspace";
|
|
25
25
|
export { ListAccountNftFromBalancesRequest } from "./ListAccountNftFromBalancesRequest";
|
|
26
|
+
export { Network } from "./network";
|
|
26
27
|
export {
|
|
27
28
|
AccountData,
|
|
28
29
|
ListSubstatesRequest,
|
|
@@ -51,4 +52,11 @@ export {
|
|
|
51
52
|
shortenSubstateId,
|
|
52
53
|
stringToSubstateId,
|
|
53
54
|
substateIdToString,
|
|
55
|
+
fromHexString,
|
|
56
|
+
toHexString,
|
|
57
|
+
convertTaggedValue,
|
|
58
|
+
getCborValueByPath,
|
|
59
|
+
parseCbor,
|
|
60
|
+
BinaryTag,
|
|
61
|
+
CborValue,
|
|
54
62
|
} from "./helpers";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
WALLET_DAEMON_JSON_RPC_URL=http://127.0.0.1:12011/json_rpc
|
|
File without changes
|
|
File without changes
|
|
File without changes
|