@kontor/kontor-sdk 1.0.0-alpha.24 → 1.0.0-alpha.27
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/dist/cjs/sdk/actions/kontor/public/call-compose.js +7 -9
- package/dist/cjs/sdk/actions/kontor/public/call-compose.js.map +1 -1
- package/dist/cjs/sdk/actions/kontor/public/proc-contract.js +5 -8
- package/dist/cjs/sdk/actions/kontor/public/proc-contract.js.map +1 -1
- package/dist/cjs/sdk/actions/kontor/wallet/sign-commit.js.map +1 -1
- package/dist/cjs/sdk/contracts/wits.js +1 -3
- package/dist/cjs/sdk/contracts/wits.js.map +1 -1
- package/dist/cjs/sdk/utils/wit/decode-wit-parameter.js +2 -2
- package/dist/cjs/sdk/utils/wit/decode-wit-parameter.js.map +1 -1
- package/dist/cjs/tsconfig.build.tsbuildinfo +1 -1
- package/dist/cjs/wit/wit-parser/core/utils.js.map +1 -1
- package/dist/cjs/wit/wit-parser/parse-wit.js.map +1 -1
- package/dist/esm/sdk/actions/kontor/public/call-compose.js +8 -10
- package/dist/esm/sdk/actions/kontor/public/call-compose.js.map +1 -1
- package/dist/esm/sdk/actions/kontor/public/proc-contract.js +5 -9
- package/dist/esm/sdk/actions/kontor/public/proc-contract.js.map +1 -1
- package/dist/esm/sdk/actions/kontor/wallet/sign-commit.js +1 -0
- package/dist/esm/sdk/actions/kontor/wallet/sign-commit.js.map +1 -1
- package/dist/esm/sdk/contracts/wits.js +1 -4
- package/dist/esm/sdk/contracts/wits.js.map +1 -1
- package/dist/esm/sdk/utils/wit/decode-wit-parameter.js +2 -2
- package/dist/esm/sdk/utils/wit/decode-wit-parameter.js.map +1 -1
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
- package/dist/esm/wit/wit-parser/core/utils.js +0 -5
- package/dist/esm/wit/wit-parser/core/utils.js.map +1 -1
- package/dist/esm/wit/wit-parser/parse-wit.js.map +1 -1
- package/dist/types/sdk/actions/kontor/public/call-compose.d.ts +6 -5
- package/dist/types/sdk/actions/kontor/public/call-compose.d.ts.map +1 -1
- package/dist/types/sdk/actions/kontor/public/proc-contract.d.ts +5 -5
- package/dist/types/sdk/actions/kontor/public/proc-contract.d.ts.map +1 -1
- package/dist/types/sdk/actions/kontor/wallet/sign-commit.d.ts +4 -2
- package/dist/types/sdk/actions/kontor/wallet/sign-commit.d.ts.map +1 -1
- package/dist/types/sdk/actions/kontor/wallet/sign-reveal.d.ts +1 -1
- package/dist/types/sdk/actions/kontor/wallet/sign-reveal.d.ts.map +1 -1
- package/dist/types/sdk/clients/decorators/kontor/public.d.ts +2 -2
- package/dist/types/sdk/clients/decorators/kontor/public.d.ts.map +1 -1
- package/dist/types/sdk/clients/decorators/kontor/wallet.d.ts +1 -1
- package/dist/types/sdk/clients/decorators/kontor/wallet.d.ts.map +1 -1
- package/dist/types/sdk/clients/kontor/create-public-client.d.ts +1 -1
- package/dist/types/sdk/clients/kontor/create-public-client.d.ts.map +1 -1
- package/dist/types/sdk/clients/kontor/create-wallet-client.d.ts +1 -1
- package/dist/types/sdk/clients/kontor/create-wallet-client.d.ts.map +1 -1
- package/dist/types/sdk/contracts/wits.d.ts +1 -1
- package/dist/types/sdk/contracts/wits.d.ts.map +1 -1
- package/dist/types/sdk/types/chain.d.ts +1 -0
- package/dist/types/sdk/types/chain.d.ts.map +1 -1
- package/dist/types/wit/wit-parser/core/types/utils.d.ts +2 -0
- package/dist/types/wit/wit-parser/core/types/utils.d.ts.map +1 -1
- package/dist/types/wit/wit-parser/core/utils.d.ts.map +1 -1
- package/dist/types/wit/wit-parser/parse-wit.d.ts +0 -15
- package/dist/types/wit/wit-parser/parse-wit.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/sdk/actions/kontor/public/call-compose.ts +29 -22
- package/src/sdk/actions/kontor/public/proc-contract.test.ts +3 -0
- package/src/sdk/actions/kontor/public/proc-contract.ts +60 -15
- package/src/sdk/actions/kontor/wallet/sign-commit.ts +18 -7
- package/src/sdk/actions/kontor/wallet/sign-reveal.ts +1 -1
- package/src/sdk/clients/decorators/kontor/public.ts +4 -4
- package/src/sdk/clients/decorators/kontor/wallet.ts +2 -2
- package/src/sdk/clients/kontor/create-public-client.ts +3 -3
- package/src/sdk/clients/kontor/create-wallet-client.ts +3 -3
- package/src/sdk/contracts/wits.ts +1 -5
- package/src/sdk/test/e2e.test.ts +8 -12
- package/src/sdk/types/chain.ts +5 -0
- package/src/sdk/types/contract.test-d.ts +21 -103
- package/src/sdk/utils/wit/decode-wit-parameter.ts +2 -2
- package/src/sdk/utils/wit/encode-function-data.test-d.ts +4 -6
- package/src/sdk/utils/wit/encode-function-data.test.ts +3 -47
- package/src/wit/wit-parser/core/types/records.test-d.ts +3 -0
- package/src/wit/wit-parser/core/types/utils.test-d.ts +7 -3
- package/src/wit/wit-parser/core/types/utils.ts +6 -2
- package/src/wit/wit-parser/core/utils.ts +1 -5
- package/src/wit/wit-parser/parse-wit.test.ts +426 -146
- package/src/wit/wit-parser/parse-wit.ts +0 -15
- package/test/src/wits.ts +0 -4
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import type { GetAccountParameter } from "../../../../sdk/types/account.js";
|
|
2
|
+
import type { Account } from "../../../../sdk/accounts/types.js";
|
|
1
3
|
import { Instruction } from "../../../../sdk/types/kontor.js";
|
|
2
4
|
import type { Wit } from "../../../../wit/wit.js";
|
|
3
5
|
import type { KontorPublicClient } from "../../../clients/kontor/create-public-client.js";
|
|
4
6
|
import type { HttpTransport } from "../../../clients/transports/create-http-transport.js";
|
|
5
|
-
import type { Chain } from "../../../types/chain.js";
|
|
7
|
+
import type { Chain, GetChainParameter } from "../../../types/chain.js";
|
|
6
8
|
import type {
|
|
7
9
|
ContractFunctionArgs,
|
|
8
10
|
ContractFunctionName,
|
|
@@ -16,6 +18,52 @@ import {
|
|
|
16
18
|
} from "../../../utils/wit/encode-function-data.js";
|
|
17
19
|
import { callCompose, type CallComposeReturnType } from "./call-compose.js";
|
|
18
20
|
|
|
21
|
+
// export type WriteContractParameters<
|
|
22
|
+
// abi extends Abi | readonly unknown[] = Abi,
|
|
23
|
+
// functionName extends ContractFunctionName<
|
|
24
|
+
// abi,
|
|
25
|
+
// 'nonpayable' | 'payable'
|
|
26
|
+
// > = ContractFunctionName<abi, 'nonpayable' | 'payable'>,
|
|
27
|
+
// args extends ContractFunctionArgs<
|
|
28
|
+
// abi,
|
|
29
|
+
// 'nonpayable' | 'payable',
|
|
30
|
+
// functionName
|
|
31
|
+
// > = ContractFunctionArgs<abi, 'nonpayable' | 'payable', functionName>,
|
|
32
|
+
// chain extends Chain | undefined = Chain | undefined,
|
|
33
|
+
// account extends Account | undefined = Account | undefined,
|
|
34
|
+
// chainOverride extends Chain | undefined = Chain | undefined,
|
|
35
|
+
// ///
|
|
36
|
+
// allFunctionNames = ContractFunctionName<abi, 'nonpayable' | 'payable'>,
|
|
37
|
+
// derivedChain extends Chain | undefined = DeriveChain<chain, chainOverride>,
|
|
38
|
+
// > = ContractFunctionParameters<
|
|
39
|
+
// abi,
|
|
40
|
+
// 'nonpayable' | 'payable',
|
|
41
|
+
// functionName,
|
|
42
|
+
// args,
|
|
43
|
+
// false,
|
|
44
|
+
// allFunctionNames
|
|
45
|
+
// > &
|
|
46
|
+
// GetChainParameter<chain, chainOverride> &
|
|
47
|
+
// Prettify<
|
|
48
|
+
// GetAccountParameter<account, Account | Address, true, true> &
|
|
49
|
+
// GetMutabilityAwareValue<
|
|
50
|
+
// abi,
|
|
51
|
+
// 'nonpayable' | 'payable',
|
|
52
|
+
// functionName,
|
|
53
|
+
// FormattedTransactionRequest<derivedChain>['value'],
|
|
54
|
+
// args
|
|
55
|
+
// > & {
|
|
56
|
+
// /** Data to append to the end of the calldata. Useful for adding a ["domain" tag](https://opensea.notion.site/opensea/Seaport-Order-Attributions-ec2d69bf455041a5baa490941aad307f). */
|
|
57
|
+
// dataSuffix?: Hex | undefined
|
|
58
|
+
// }
|
|
59
|
+
// > &
|
|
60
|
+
// UnionEvaluate<
|
|
61
|
+
// UnionOmit<
|
|
62
|
+
// FormattedTransactionRequest<derivedChain>,
|
|
63
|
+
// 'data' | 'from' | 'to' | 'value'
|
|
64
|
+
// >
|
|
65
|
+
// >
|
|
66
|
+
|
|
19
67
|
export type ProcContractParameters<
|
|
20
68
|
wit extends Wit | readonly unknown[] = Wit,
|
|
21
69
|
functionName extends ContractFunctionName<wit, "proc"> = ContractFunctionName<
|
|
@@ -27,13 +75,15 @@ export type ProcContractParameters<
|
|
|
27
75
|
"proc",
|
|
28
76
|
functionName
|
|
29
77
|
> = ContractFunctionArgs<wit, "proc", functionName>,
|
|
78
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
79
|
+
account extends Account | undefined = Account | undefined,
|
|
80
|
+
chainOverride extends Chain | undefined = Chain | undefined,
|
|
30
81
|
> = ContractFunctionParameters<wit, "proc", functionName, args> & {
|
|
31
|
-
address?: Address;
|
|
32
|
-
xOnlyPubKey?: XOnlyPubKey;
|
|
33
82
|
utxos: UtxoId[];
|
|
34
83
|
gas: bigint;
|
|
35
84
|
satsPerVByte: number;
|
|
36
|
-
}
|
|
85
|
+
} & GetChainParameter<chain, chainOverride> &
|
|
86
|
+
GetAccountParameter<account, Account | [XOnlyPubKey, Address], true, true>;
|
|
37
87
|
|
|
38
88
|
export type ProcContractReturnType = CallComposeReturnType;
|
|
39
89
|
|
|
@@ -55,8 +105,8 @@ export async function procContract<
|
|
|
55
105
|
utxos,
|
|
56
106
|
gas,
|
|
57
107
|
satsPerVByte,
|
|
58
|
-
|
|
59
|
-
|
|
108
|
+
chain: chain_ = client.chain,
|
|
109
|
+
account: account_ = client.account,
|
|
60
110
|
// @ts-ignore
|
|
61
111
|
...rest
|
|
62
112
|
} = parameters as ProcContractParameters;
|
|
@@ -68,14 +118,9 @@ export async function procContract<
|
|
|
68
118
|
functionName,
|
|
69
119
|
} as EncodeFunctionDataParameters);
|
|
70
120
|
|
|
71
|
-
if (!
|
|
72
|
-
// TODO: add custom error
|
|
73
|
-
throw new Error("x_only_public_key is required");
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (!address) {
|
|
121
|
+
if (!account_) {
|
|
77
122
|
// TODO: add custom error
|
|
78
|
-
throw new Error("
|
|
123
|
+
throw new Error("account is required");
|
|
79
124
|
}
|
|
80
125
|
|
|
81
126
|
if (utxos.length === 0) {
|
|
@@ -91,8 +136,8 @@ export async function procContract<
|
|
|
91
136
|
)({
|
|
92
137
|
utxos,
|
|
93
138
|
satsPerVByte,
|
|
94
|
-
|
|
95
|
-
|
|
139
|
+
account: account_,
|
|
140
|
+
chain: chain_,
|
|
96
141
|
instruction: Instruction.call({
|
|
97
142
|
contract: contractAddress,
|
|
98
143
|
gasLimit: gas,
|
|
@@ -8,23 +8,33 @@ import type { Chain, GetChainParameter } from "../../../types/chain.js";
|
|
|
8
8
|
import { getAction } from "../../..//utils/get-action.js";
|
|
9
9
|
import { signPsbt } from "../../wallet/sign-psbt.js";
|
|
10
10
|
import { parseAccount } from "../../../accounts/utils/parse-account.js";
|
|
11
|
+
import type { XOnlyPubKey, Address } from "../../../../sdk/types/misc.js";
|
|
12
|
+
|
|
13
|
+
export type SignCommitRequest = {
|
|
14
|
+
psbt: string;
|
|
15
|
+
};
|
|
11
16
|
|
|
12
17
|
export type SignCommitParameters<
|
|
13
|
-
chain extends Chain | undefined,
|
|
14
|
-
account extends Account | undefined,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
chain extends Chain | undefined = Chain,
|
|
19
|
+
account extends Account | undefined = Account | undefined,
|
|
20
|
+
chainOverride extends Chain | undefined = Chain | undefined,
|
|
21
|
+
accountOverride extends Account | [Address, XOnlyPubKey] | undefined =
|
|
22
|
+
| Account
|
|
23
|
+
| [Address, XOnlyPubKey]
|
|
24
|
+
| undefined,
|
|
25
|
+
> = SignCommitRequest &
|
|
26
|
+
GetAccountParameter<account, accountOverride, false, true> &
|
|
27
|
+
GetChainParameter<chain, chainOverride>;
|
|
18
28
|
|
|
19
29
|
export type SignCommitReturnType = Transaction;
|
|
20
30
|
|
|
21
31
|
export async function signCommit<
|
|
22
|
-
// @ts-ignore
|
|
23
32
|
chain extends Chain | undefined,
|
|
24
33
|
account extends Account | undefined,
|
|
34
|
+
chainOverride extends Chain | undefined = undefined,
|
|
25
35
|
>(
|
|
26
36
|
client: KontorWalletClient<RpcTransport, chain, account>,
|
|
27
|
-
parameters: SignCommitParameters<chain, account>,
|
|
37
|
+
parameters: SignCommitParameters<chain, account, chainOverride>,
|
|
28
38
|
): Promise<SignCommitReturnType> {
|
|
29
39
|
const {
|
|
30
40
|
account: account_ = client.account,
|
|
@@ -33,6 +43,7 @@ export async function signCommit<
|
|
|
33
43
|
} = parameters;
|
|
34
44
|
|
|
35
45
|
if (!account_) throw new Error("AccountNotFoundError");
|
|
46
|
+
// TODO: throw if chain is undefined
|
|
36
47
|
|
|
37
48
|
const account = parseAccount(account_);
|
|
38
49
|
|
|
@@ -18,7 +18,7 @@ import type { ParticipantScripts } from "@kontor/kontor-ts";
|
|
|
18
18
|
export type SignRevealParameters<
|
|
19
19
|
chain extends Chain | undefined,
|
|
20
20
|
account extends Account | undefined,
|
|
21
|
-
> = GetAccountParameter<account> &
|
|
21
|
+
> = GetAccountParameter<account, account, false> &
|
|
22
22
|
// TODO: add chainoverride?
|
|
23
23
|
GetChainParameter<chain> & {
|
|
24
24
|
psbt: string;
|
|
@@ -52,8 +52,8 @@ import type { HttpTransport } from "../../transports/create-http-transport.js";
|
|
|
52
52
|
|
|
53
53
|
export type KontorPublicActions<
|
|
54
54
|
_transport extends HttpTransport = HttpTransport,
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
56
|
+
account extends Account | undefined = Account | undefined,
|
|
57
57
|
> = {
|
|
58
58
|
viewContract: <
|
|
59
59
|
const wit extends Wit | readonly unknown[],
|
|
@@ -83,8 +83,8 @@ export type KontorPublicActions<
|
|
|
83
83
|
args: BuildComposeQueryParameters<chain>,
|
|
84
84
|
) => Promise<BuildComposeQueryReturnType>;
|
|
85
85
|
|
|
86
|
-
callCompose: <
|
|
87
|
-
args: CallComposeParameters<chain>,
|
|
86
|
+
callCompose: <chainOverride extends Chain | undefined>(
|
|
87
|
+
args: CallComposeParameters<chain, account, chainOverride>,
|
|
88
88
|
) => Promise<CallComposeReturnType>;
|
|
89
89
|
inspect: <_chain extends Chain | undefined>(
|
|
90
90
|
args: InspectParameters,
|
|
@@ -33,8 +33,8 @@ export type KontorWalletActions<
|
|
|
33
33
|
signPsbt: (
|
|
34
34
|
params: SignPsbtParameters<chain, account>,
|
|
35
35
|
) => Promise<SignPsbtReturnType>;
|
|
36
|
-
signCommit: (
|
|
37
|
-
params: SignCommitParameters<chain, account>,
|
|
36
|
+
signCommit: <chainOverride extends Chain | undefined>(
|
|
37
|
+
params: SignCommitParameters<chain, account, chainOverride>,
|
|
38
38
|
) => Promise<SignCommitReturnType>;
|
|
39
39
|
signReveal: (
|
|
40
40
|
params: SignRevealParameters<chain, account>,
|
|
@@ -43,17 +43,17 @@ export type KontorPublicClientConfig<
|
|
|
43
43
|
export type KontorPublicClient<
|
|
44
44
|
transport extends HttpTransport = HttpTransport,
|
|
45
45
|
chain extends Chain | undefined = Chain | undefined,
|
|
46
|
-
|
|
46
|
+
account extends Account | undefined = Account | undefined,
|
|
47
47
|
httpSchema extends HttpSchema | undefined = undefined,
|
|
48
48
|
> = Prettify<
|
|
49
49
|
HttpClient<
|
|
50
50
|
transport,
|
|
51
51
|
chain,
|
|
52
|
-
|
|
52
|
+
account,
|
|
53
53
|
httpSchema extends HttpSchema
|
|
54
54
|
? [...KontorSchemaPublic, ...httpSchema]
|
|
55
55
|
: KontorSchemaPublic,
|
|
56
|
-
KontorPublicActions
|
|
56
|
+
KontorPublicActions<transport, chain, account>
|
|
57
57
|
>
|
|
58
58
|
>;
|
|
59
59
|
|
|
@@ -44,17 +44,17 @@ export type KontorWalletClientConfig<
|
|
|
44
44
|
export type KontorWalletClient<
|
|
45
45
|
transport extends RpcTransport = RpcTransport,
|
|
46
46
|
chain extends Chain | undefined = Chain | undefined,
|
|
47
|
-
|
|
47
|
+
account extends Account | undefined = Account | undefined,
|
|
48
48
|
rpcSchema extends RpcSchema | undefined = undefined,
|
|
49
49
|
> = Prettify<
|
|
50
50
|
RpcClient<
|
|
51
51
|
transport,
|
|
52
52
|
chain,
|
|
53
|
-
|
|
53
|
+
account,
|
|
54
54
|
rpcSchema extends RpcSchema
|
|
55
55
|
? [...WBIP001Schema, ...rpcSchema]
|
|
56
56
|
: WBIP001Schema,
|
|
57
|
-
KontorWalletActions
|
|
57
|
+
KontorWalletActions<chain, account>
|
|
58
58
|
>
|
|
59
59
|
>;
|
|
60
60
|
|
|
@@ -12,10 +12,6 @@ const nativeTokenRaw = [
|
|
|
12
12
|
"record transfer { src: string, dst: string, amt: decimal }",
|
|
13
13
|
"record burn { src: string, amt: decimal }",
|
|
14
14
|
"record mint { dst: string, amt: decimal }",
|
|
15
|
-
|
|
16
|
-
"export issuance: func(ctx: borrow<core-context>, amt: decimal) -> result<mint, error>;",
|
|
17
|
-
"export hold: func(ctx: borrow<core-context>, amt: decimal) -> result<transfer, error>;",
|
|
18
|
-
"export release: func(ctx: borrow<core-context>, burn-amt: decimal) -> result<burn, error>;",
|
|
19
15
|
"export init: func(ctx: borrow<proc-context>);",
|
|
20
16
|
"export mint: func(ctx: borrow<proc-context>, amt: decimal) -> result<mint, error>;",
|
|
21
17
|
"export burn: func(ctx: borrow<proc-context>, amt: decimal) -> result<burn, error>;",
|
|
@@ -23,7 +19,7 @@ const nativeTokenRaw = [
|
|
|
23
19
|
"export balance: func(ctx: borrow<view-context>, acc: string) -> option<decimal>;",
|
|
24
20
|
"export balances: func(ctx: borrow<view-context>) -> list<balance>;",
|
|
25
21
|
"export total-supply: func(ctx: borrow<view-context>) -> decimal;",
|
|
26
|
-
|
|
22
|
+
"export attach: func(ctx: borrow<proc-context>, vout: u64, amt: decimal) -> result<transfer, error>;",
|
|
27
23
|
"export detach: func(ctx: borrow<proc-context>) -> result<transfer, error>;",
|
|
28
24
|
] as const;
|
|
29
25
|
|
package/src/sdk/test/e2e.test.ts
CHANGED
|
@@ -120,8 +120,16 @@ test("e2e kontor wallet client", async () => {
|
|
|
120
120
|
|
|
121
121
|
const kontorPublicClient = createKontorPublicClient({
|
|
122
122
|
transport: http("https://signet-staging.kontor.network:35000/api"),
|
|
123
|
+
chain: signet,
|
|
124
|
+
account,
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
const kontorWalletClient = createKontorWalletClient({
|
|
123
128
|
account,
|
|
124
129
|
chain: signet,
|
|
130
|
+
transport: custom({
|
|
131
|
+
request: async (_args: any) => null,
|
|
132
|
+
}),
|
|
125
133
|
});
|
|
126
134
|
|
|
127
135
|
const res = await kontorPublicClient.callCompose({
|
|
@@ -132,23 +140,11 @@ test("e2e kontor wallet client", async () => {
|
|
|
132
140
|
satsPerVByte: 1,
|
|
133
141
|
});
|
|
134
142
|
|
|
135
|
-
const kontorWalletClient = createKontorWalletClient({
|
|
136
|
-
account,
|
|
137
|
-
// TODO: transport is not used for local account.
|
|
138
|
-
transport: custom({
|
|
139
|
-
request: async (_args: any) => null,
|
|
140
|
-
}),
|
|
141
|
-
});
|
|
142
|
-
|
|
143
143
|
const commit: Transaction = await kontorWalletClient.signCommit({
|
|
144
|
-
account: account,
|
|
145
|
-
chain: signet,
|
|
146
144
|
psbt: res.result.commit_psbt_hex,
|
|
147
145
|
});
|
|
148
146
|
|
|
149
147
|
const reveal: Transaction = await kontorWalletClient.signReveal({
|
|
150
|
-
account: account,
|
|
151
|
-
chain: signet,
|
|
152
148
|
psbt: res.result.reveal_psbt_hex,
|
|
153
149
|
parcipantScripts: res.result.per_participant,
|
|
154
150
|
});
|
package/src/sdk/types/chain.ts
CHANGED
|
@@ -108,3 +108,8 @@ export type GetChainParameter<
|
|
|
108
108
|
IsUndefined<chain> extends true
|
|
109
109
|
? { chain: chainOverride | null }
|
|
110
110
|
: { chain?: chainOverride | null | undefined };
|
|
111
|
+
|
|
112
|
+
export type DeriveChain<
|
|
113
|
+
chain extends Chain | undefined,
|
|
114
|
+
chainOverride extends Chain | undefined,
|
|
115
|
+
> = chainOverride extends Chain ? chainOverride : chain;
|
|
@@ -2,63 +2,35 @@ import { expectTypeOf, test } from "vitest";
|
|
|
2
2
|
import type {
|
|
3
3
|
ContractFunctionName,
|
|
4
4
|
ContractFunctionArgs,
|
|
5
|
-
ExtractWitFunctionForArgs,
|
|
6
5
|
ContractFunctionReturnType,
|
|
7
6
|
} from "./contract.js";
|
|
8
7
|
import { nativeToken as nativeToken_ } from "../contracts/wits.js";
|
|
9
8
|
|
|
10
9
|
const nativeToken = nativeToken_.wit;
|
|
11
10
|
|
|
12
|
-
type t = ExtractWitFunctionForArgs<
|
|
13
|
-
typeof nativeToken,
|
|
14
|
-
"proc",
|
|
15
|
-
"transfer",
|
|
16
|
-
[string, [bigint, number]]
|
|
17
|
-
>;
|
|
18
|
-
|
|
19
11
|
test("ContractFunctionName", () => {
|
|
20
12
|
type All = ContractFunctionName<typeof nativeToken>;
|
|
21
13
|
expectTypeOf<All>().toEqualTypeOf<
|
|
22
|
-
| "issuance"
|
|
23
|
-
| "hold"
|
|
24
|
-
| "release"
|
|
25
|
-
// | "init" // init is not valid
|
|
26
14
|
| "mint"
|
|
27
15
|
| "burn"
|
|
28
16
|
| "transfer"
|
|
29
17
|
| "balance"
|
|
30
18
|
| "balances"
|
|
31
19
|
| "total-supply"
|
|
32
|
-
|
|
20
|
+
| "attach"
|
|
33
21
|
| "detach"
|
|
34
22
|
>;
|
|
35
23
|
|
|
36
|
-
type Core = ContractFunctionName<typeof nativeToken, "core">;
|
|
37
|
-
expectTypeOf<Core>().toEqualTypeOf<"issuance" | "hold" | "release">;
|
|
38
|
-
|
|
39
24
|
type View = ContractFunctionName<typeof nativeToken, "view">;
|
|
40
25
|
expectTypeOf<View>().toEqualTypeOf<"balance" | "balances" | "total-supply">;
|
|
41
26
|
|
|
42
27
|
type Proc = ContractFunctionName<typeof nativeToken, "proc">;
|
|
43
28
|
expectTypeOf<Proc>().toEqualTypeOf<
|
|
44
|
-
| "
|
|
45
|
-
| "burn"
|
|
46
|
-
| "transfer"
|
|
47
|
-
//| "attach"
|
|
48
|
-
| "detach"
|
|
29
|
+
"mint" | "burn" | "transfer" | "attach" | "detach"
|
|
49
30
|
>;
|
|
50
31
|
});
|
|
51
32
|
|
|
52
33
|
test("ContractFunctionArgs", () => {
|
|
53
|
-
type Issuance = ContractFunctionArgs<typeof nativeToken, "core", "issuance">;
|
|
54
|
-
expectTypeOf<Issuance>().toEqualTypeOf<readonly [[bigint, number]]>;
|
|
55
|
-
|
|
56
|
-
type Hold = ContractFunctionArgs<typeof nativeToken, "core", "hold">;
|
|
57
|
-
expectTypeOf<Hold>().toEqualTypeOf<readonly [[bigint, number]]>;
|
|
58
|
-
|
|
59
|
-
type Release = ContractFunctionArgs<typeof nativeToken, "core", "release">;
|
|
60
|
-
expectTypeOf<Release>().toEqualTypeOf<readonly [[bigint, number]]>;
|
|
61
|
-
|
|
62
34
|
type Mint = ContractFunctionArgs<typeof nativeToken, "proc", "mint">;
|
|
63
35
|
expectTypeOf<Mint>().toEqualTypeOf<readonly [[bigint, number]]>;
|
|
64
36
|
|
|
@@ -89,60 +61,6 @@ test("ContractFunctionArgs", () => {
|
|
|
89
61
|
});
|
|
90
62
|
|
|
91
63
|
test("ContractFunctionReturnType", () => {
|
|
92
|
-
type Issuance = ContractFunctionReturnType<
|
|
93
|
-
typeof nativeToken,
|
|
94
|
-
"core",
|
|
95
|
-
"issuance"
|
|
96
|
-
>;
|
|
97
|
-
expectTypeOf<Issuance>().toEqualTypeOf<
|
|
98
|
-
| {
|
|
99
|
-
ok: false;
|
|
100
|
-
error: string;
|
|
101
|
-
}
|
|
102
|
-
| {
|
|
103
|
-
ok: true;
|
|
104
|
-
value: {
|
|
105
|
-
dst: string;
|
|
106
|
-
amt: [bigint, number];
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
>;
|
|
110
|
-
|
|
111
|
-
type Hold = ContractFunctionReturnType<typeof nativeToken, "core", "hold">;
|
|
112
|
-
expectTypeOf<Hold>().toEqualTypeOf<
|
|
113
|
-
| {
|
|
114
|
-
ok: false;
|
|
115
|
-
error: string;
|
|
116
|
-
}
|
|
117
|
-
| {
|
|
118
|
-
ok: true;
|
|
119
|
-
value: {
|
|
120
|
-
src: string;
|
|
121
|
-
dst: string;
|
|
122
|
-
amt: [bigint, number];
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
>;
|
|
126
|
-
|
|
127
|
-
type Release = ContractFunctionReturnType<
|
|
128
|
-
typeof nativeToken,
|
|
129
|
-
"core",
|
|
130
|
-
"release"
|
|
131
|
-
>;
|
|
132
|
-
expectTypeOf<Release>().toEqualTypeOf<
|
|
133
|
-
| {
|
|
134
|
-
ok: false;
|
|
135
|
-
error: string;
|
|
136
|
-
}
|
|
137
|
-
| {
|
|
138
|
-
ok: true;
|
|
139
|
-
value: {
|
|
140
|
-
src: string;
|
|
141
|
-
amt: [bigint, number];
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
>;
|
|
145
|
-
|
|
146
64
|
type Mint = ContractFunctionReturnType<typeof nativeToken, "proc", "mint">;
|
|
147
65
|
expectTypeOf<Mint>().toEqualTypeOf<
|
|
148
66
|
| {
|
|
@@ -222,25 +140,25 @@ test("ContractFunctionReturnType", () => {
|
|
|
222
140
|
>;
|
|
223
141
|
expectTypeOf<TotalSupply>().toEqualTypeOf<[bigint, number]>;
|
|
224
142
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
143
|
+
type Attach = ContractFunctionReturnType<
|
|
144
|
+
typeof nativeToken,
|
|
145
|
+
"proc",
|
|
146
|
+
"attach"
|
|
147
|
+
>;
|
|
148
|
+
expectTypeOf<Attach>().toEqualTypeOf<
|
|
149
|
+
| {
|
|
150
|
+
ok: false;
|
|
151
|
+
error: string;
|
|
152
|
+
}
|
|
153
|
+
| {
|
|
154
|
+
ok: true;
|
|
155
|
+
value: {
|
|
156
|
+
src: string;
|
|
157
|
+
dst: string;
|
|
158
|
+
amt: [bigint, number];
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
>;
|
|
244
162
|
|
|
245
163
|
type Detach = ContractFunctionReturnType<
|
|
246
164
|
typeof nativeToken,
|
|
@@ -87,6 +87,8 @@ function decoderForParam(p: WitParameter) {
|
|
|
87
87
|
return listOfDecimalDecoder;
|
|
88
88
|
case "list<tuple>":
|
|
89
89
|
return listOfTupleDecoder(p);
|
|
90
|
+
case "u64":
|
|
91
|
+
return u64Decoder;
|
|
90
92
|
|
|
91
93
|
case "error":
|
|
92
94
|
case "contract-address":
|
|
@@ -98,8 +100,6 @@ function decoderForParam(p: WitParameter) {
|
|
|
98
100
|
case "u8":
|
|
99
101
|
case "u16":
|
|
100
102
|
case "u32":
|
|
101
|
-
case "u64":
|
|
102
|
-
return u64Decoder;
|
|
103
103
|
case "integer":
|
|
104
104
|
case "option<string>":
|
|
105
105
|
case "option<bool>":
|
|
@@ -34,18 +34,16 @@ test("native token", () => {
|
|
|
34
34
|
type P = EncodeFunctionDataParameters<typeof nativeToken.wit>;
|
|
35
35
|
|
|
36
36
|
expectTypeOf<P["functionName"]>().not.toEqualTypeOf<undefined>();
|
|
37
|
-
|
|
38
37
|
expectTypeOf<P["functionName"]>().toEqualTypeOf<
|
|
39
|
-
| "mint"
|
|
40
|
-
| "issuance"
|
|
41
38
|
| "balance"
|
|
42
39
|
| "transfer"
|
|
43
40
|
| "burn"
|
|
44
|
-
| "
|
|
45
|
-
| "release"
|
|
41
|
+
| "mint"
|
|
46
42
|
| "balances"
|
|
47
43
|
| "total-supply"
|
|
44
|
+
| "attach"
|
|
48
45
|
| "detach"
|
|
49
|
-
// | "attach" // TODO: need to handle attach parsing
|
|
50
46
|
>();
|
|
47
|
+
|
|
48
|
+
// TODO: fill out tests
|
|
51
49
|
});
|
|
@@ -2,55 +2,11 @@ import { expect, test } from "vitest";
|
|
|
2
2
|
import { encodeFunctionData } from "./encode-function-data.js";
|
|
3
3
|
import { parseWit } from "../../../wit/wit-parser/parse-wit.js";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
"record balance { acc: string, amt: decimal }",
|
|
7
|
-
"record transfer { src: string, dst: string, amt: decimal }",
|
|
8
|
-
"record burn { src: string, amt: decimal }",
|
|
9
|
-
"record mint { dst: string, amt: decimal }",
|
|
10
|
-
"export issuance: func(ctx: borrow<core-context>, amt: decimal) -> result<mint, error>;",
|
|
11
|
-
"export hold: func(ctx: borrow<core-context>, amt: decimal) -> result<transfer, error>;",
|
|
12
|
-
"export release: func(ctx: borrow<core-context>, burn-amt: decimal) -> result<burn, error>;",
|
|
13
|
-
"export init: func(ctx: borrow<proc-context>);",
|
|
14
|
-
"export mint: func(ctx: borrow<proc-context>, amt: decimal) -> result<mint, error>;",
|
|
15
|
-
"export burn: func(ctx: borrow<proc-context>, amt: decimal) -> result<burn, error>;",
|
|
16
|
-
"export transfer: func(ctx: borrow<proc-context>, dst: string, amt: decimal) -> result<transfer, error>;",
|
|
17
|
-
"export balance: func(ctx: borrow<view-context>, acc: string) -> option<decimal>;",
|
|
18
|
-
"export balances: func(ctx: borrow<view-context>) -> list<balance>;",
|
|
19
|
-
"export total-supply: func(ctx: borrow<view-context>) -> decimal;",
|
|
20
|
-
"export attach: func(ctx: borrow<proc-context>, vout: u64, amt: decimal) -> result<transfer, error>;",
|
|
21
|
-
"export detach: func(ctx: borrow<proc-context>) -> result<transfer, error>;",
|
|
22
|
-
]);
|
|
5
|
+
import { nativeToken as nativeToken_ } from "../../../sdk/contracts/wits.js";
|
|
23
6
|
|
|
24
|
-
|
|
25
|
-
test("issuance", () => {
|
|
26
|
-
expect(
|
|
27
|
-
encodeFunctionData({
|
|
28
|
-
wit: nativeToken,
|
|
29
|
-
functionName: "issuance",
|
|
30
|
-
args: [[7n, 18]],
|
|
31
|
-
}),
|
|
32
|
-
).toEqual("issuance({r0: 7, r1: 0, r2: 0, r3: 0, sign: plus})");
|
|
33
|
-
});
|
|
7
|
+
export const nativeToken = parseWit(nativeToken_.raw);
|
|
34
8
|
|
|
35
|
-
|
|
36
|
-
expect(
|
|
37
|
-
encodeFunctionData({
|
|
38
|
-
wit: nativeToken,
|
|
39
|
-
functionName: "hold",
|
|
40
|
-
args: [[7n, 18]],
|
|
41
|
-
}),
|
|
42
|
-
).toEqual("hold({r0: 7, r1: 0, r2: 0, r3: 0, sign: plus})");
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
test("release", () => {
|
|
46
|
-
expect(
|
|
47
|
-
encodeFunctionData({
|
|
48
|
-
wit: nativeToken,
|
|
49
|
-
functionName: "release",
|
|
50
|
-
args: [[7n, 18]],
|
|
51
|
-
}),
|
|
52
|
-
).toEqual("release({r0: 7, r1: 0, r2: 0, r3: 0, sign: plus})");
|
|
53
|
-
});
|
|
9
|
+
//TODO: change functionName to func
|
|
54
10
|
|
|
55
11
|
test("mint", () => {
|
|
56
12
|
expect(
|
|
@@ -119,6 +119,7 @@ test("ParseRecords", () => {
|
|
|
119
119
|
{
|
|
120
120
|
readonly name: "values";
|
|
121
121
|
readonly type: "list<contract-address>";
|
|
122
|
+
readonly internalType: "list<contract-address>";
|
|
122
123
|
},
|
|
123
124
|
];
|
|
124
125
|
}>();
|
|
@@ -306,6 +307,7 @@ test("ParseRecordProperties", () => {
|
|
|
306
307
|
{
|
|
307
308
|
readonly name: "values";
|
|
308
309
|
readonly type: "list<string>";
|
|
310
|
+
readonly internalType: "list<string>";
|
|
309
311
|
},
|
|
310
312
|
]
|
|
311
313
|
>();
|
|
@@ -317,6 +319,7 @@ test("ParseRecordProperties", () => {
|
|
|
317
319
|
{
|
|
318
320
|
readonly name: "values";
|
|
319
321
|
readonly type: "list<tuple>";
|
|
322
|
+
readonly internalType: "list<contract-address>";
|
|
320
323
|
readonly components: readonly [
|
|
321
324
|
{ readonly name: "name"; readonly type: "string" },
|
|
322
325
|
{ readonly name: "height"; readonly type: "s64" },
|