@thalalabs/surf 0.0.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/LICENSE +21 -0
- package/README.md +196 -0
- package/build/cjs/core/Client.js +80 -0
- package/build/cjs/core/Client.js.map +1 -0
- package/build/cjs/core/WalletClient.js +52 -0
- package/build/cjs/core/WalletClient.js.map +1 -0
- package/build/cjs/core/createEntryPayload.js +91 -0
- package/build/cjs/core/createEntryPayload.js.map +1 -0
- package/build/cjs/core/createViewPayload.js +78 -0
- package/build/cjs/core/createViewPayload.js.map +1 -0
- package/build/cjs/core/index.js +13 -0
- package/build/cjs/core/index.js.map +1 -0
- package/build/cjs/ensureTypes.js +40 -0
- package/build/cjs/ensureTypes.js.map +1 -0
- package/build/cjs/hooks/index.js +8 -0
- package/build/cjs/hooks/index.js.map +1 -0
- package/build/cjs/hooks/useSubmitTransaction.js +88 -0
- package/build/cjs/hooks/useSubmitTransaction.js.map +1 -0
- package/build/cjs/hooks/useWalletClient.js +14 -0
- package/build/cjs/hooks/useWalletClient.js.map +1 -0
- package/build/cjs/index.js +8 -0
- package/build/cjs/index.js.map +1 -0
- package/build/cjs/package.json +1 -0
- package/build/cjs/types/abi.js +3 -0
- package/build/cjs/types/abi.js.map +1 -0
- package/build/cjs/types/abiClient.js +3 -0
- package/build/cjs/types/abiClient.js.map +1 -0
- package/build/cjs/types/client.js +3 -0
- package/build/cjs/types/client.js.map +1 -0
- package/build/cjs/types/common.js +3 -0
- package/build/cjs/types/common.js.map +1 -0
- package/build/cjs/types/index.js +3 -0
- package/build/cjs/types/index.js.map +1 -0
- package/build/cjs/types/walletClient.js +3 -0
- package/build/cjs/types/walletClient.js.map +1 -0
- package/build/esm/core/Client.js +75 -0
- package/build/esm/core/Client.js.map +1 -0
- package/build/esm/core/WalletClient.js +48 -0
- package/build/esm/core/WalletClient.js.map +1 -0
- package/build/esm/core/createEntryPayload.js +87 -0
- package/build/esm/core/createEntryPayload.js.map +1 -0
- package/build/esm/core/createViewPayload.js +74 -0
- package/build/esm/core/createViewPayload.js.map +1 -0
- package/build/esm/core/index.js +5 -0
- package/build/esm/core/index.js.map +1 -0
- package/build/esm/ensureTypes.js +34 -0
- package/build/esm/ensureTypes.js.map +1 -0
- package/build/esm/hooks/index.js +3 -0
- package/build/esm/hooks/index.js.map +1 -0
- package/build/esm/hooks/useSubmitTransaction.js +84 -0
- package/build/esm/hooks/useSubmitTransaction.js.map +1 -0
- package/build/esm/hooks/useWalletClient.js +10 -0
- package/build/esm/hooks/useWalletClient.js.map +1 -0
- package/build/esm/index.js +2 -0
- package/build/esm/index.js.map +1 -0
- package/build/esm/package.json +1 -0
- package/build/esm/types/abi.js +2 -0
- package/build/esm/types/abi.js.map +1 -0
- package/build/esm/types/abiClient.js +2 -0
- package/build/esm/types/abiClient.js.map +1 -0
- package/build/esm/types/client.js +2 -0
- package/build/esm/types/client.js.map +1 -0
- package/build/esm/types/common.js +2 -0
- package/build/esm/types/common.js.map +1 -0
- package/build/esm/types/index.js +2 -0
- package/build/esm/types/index.js.map +1 -0
- package/build/esm/types/walletClient.js +2 -0
- package/build/esm/types/walletClient.js.map +1 -0
- package/build/types/core/Client.d.ts +20 -0
- package/build/types/core/Client.d.ts.map +1 -0
- package/build/types/core/WalletClient.d.ts +17 -0
- package/build/types/core/WalletClient.d.ts.map +1 -0
- package/build/types/core/createEntryPayload.d.ts +4 -0
- package/build/types/core/createEntryPayload.d.ts.map +1 -0
- package/build/types/core/createViewPayload.d.ts +4 -0
- package/build/types/core/createViewPayload.d.ts.map +1 -0
- package/build/types/core/index.d.ts +5 -0
- package/build/types/core/index.d.ts.map +1 -0
- package/build/types/ensureTypes.d.ts +4 -0
- package/build/types/ensureTypes.d.ts.map +1 -0
- package/build/types/hooks/index.d.ts +3 -0
- package/build/types/hooks/index.d.ts.map +1 -0
- package/build/types/hooks/useSubmitTransaction.d.ts +19 -0
- package/build/types/hooks/useSubmitTransaction.d.ts.map +1 -0
- package/build/types/hooks/useWalletClient.d.ts +8 -0
- package/build/types/hooks/useWalletClient.d.ts.map +1 -0
- package/build/types/index.d.ts +3 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/types/abi.d.ts +31 -0
- package/build/types/types/abi.d.ts.map +1 -0
- package/build/types/types/abiClient.d.ts +18 -0
- package/build/types/types/abiClient.d.ts.map +1 -0
- package/build/types/types/client.d.ts +24 -0
- package/build/types/types/client.d.ts.map +1 -0
- package/build/types/types/common.d.ts +60 -0
- package/build/types/types/common.d.ts.map +1 -0
- package/build/types/types/index.d.ts +5 -0
- package/build/types/types/index.d.ts.map +1 -0
- package/build/types/types/walletClient.d.ts +9 -0
- package/build/types/types/walletClient.d.ts.map +1 -0
- package/package.json +78 -0
- package/src/core/Client.ts +120 -0
- package/src/core/WalletClient.ts +64 -0
- package/src/core/__tests__/createEntryPayload.test.ts +262 -0
- package/src/core/__tests__/createViewPayload.test.ts +297 -0
- package/src/core/__tests__/submitTransaction.test.ts +112 -0
- package/src/core/__tests__/useABI.test.ts +139 -0
- package/src/core/__tests__/view.test.ts +145 -0
- package/src/core/createEntryPayload.ts +128 -0
- package/src/core/createViewPayload.ts +100 -0
- package/src/core/index.ts +4 -0
- package/src/ensureTypes.ts +42 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/useSubmitTransaction.ts +117 -0
- package/src/hooks/useWalletClient.ts +10 -0
- package/src/index.ts +10 -0
- package/src/types/abi.ts +35 -0
- package/src/types/abiClient.ts +19 -0
- package/src/types/client.ts +32 -0
- package/src/types/common.ts +157 -0
- package/src/types/index.ts +9 -0
- package/src/types/walletClient.ts +10 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { useState, useRef } from "react";
|
|
2
|
+
import { useWallet } from "@aptos-labs/wallet-adapter-react";
|
|
3
|
+
import { AptosClient, Types } from "aptos";
|
|
4
|
+
import { EntryPayload } from "../types";
|
|
5
|
+
|
|
6
|
+
export type submitTransactionOptions = {
|
|
7
|
+
nodeUrl: string,
|
|
8
|
+
onSuccess?: (result: Types.Transaction_UserTransaction) => void,
|
|
9
|
+
onFailed?: (error: Error) => void,
|
|
10
|
+
max_gas_amount?: string,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function isRawPayload(payload: EntryPayload | Types.TransactionPayload_EntryFunctionPayload,): payload is EntryPayload {
|
|
14
|
+
return (<EntryPayload>payload).rawPayload !== undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const useSubmitTransaction = () => {
|
|
18
|
+
const { signAndSubmitTransaction } = useWallet();
|
|
19
|
+
|
|
20
|
+
const [isIdle, setIsIdle] = useState(true);
|
|
21
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
22
|
+
const [data, setResult] = useState<Types.Transaction_UserTransaction>();
|
|
23
|
+
const [error, setError] = useState<Error>();
|
|
24
|
+
const idRef = useRef<number>(0);
|
|
25
|
+
|
|
26
|
+
function reset() {
|
|
27
|
+
setIsIdle(true);
|
|
28
|
+
setIsLoading(false);
|
|
29
|
+
setResult(undefined);
|
|
30
|
+
setError(undefined);
|
|
31
|
+
idRef.current = idRef.current + 1;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function submitTransaction(
|
|
35
|
+
payload: EntryPayload | Types.TransactionPayload_EntryFunctionPayload,
|
|
36
|
+
{
|
|
37
|
+
nodeUrl,
|
|
38
|
+
onSuccess,
|
|
39
|
+
onFailed,
|
|
40
|
+
max_gas_amount
|
|
41
|
+
}: submitTransactionOptions
|
|
42
|
+
): Promise<void> {
|
|
43
|
+
// TODO: remove this
|
|
44
|
+
if (signAndSubmitTransaction === undefined) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const id = idRef.current;
|
|
48
|
+
|
|
49
|
+
if (!isIdle) {
|
|
50
|
+
throw new Error("Transaction is already in progress");
|
|
51
|
+
}
|
|
52
|
+
setIsLoading(true);
|
|
53
|
+
setIsIdle(false);
|
|
54
|
+
|
|
55
|
+
// TODO: make it better. This way to determine the type is tricky.
|
|
56
|
+
const request = isRawPayload(payload) ? payload.rawPayload : payload;
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
// TODO: use the BCS API instead
|
|
60
|
+
const { hash } = await signAndSubmitTransaction({
|
|
61
|
+
type: "entry_function_payload",
|
|
62
|
+
...request,
|
|
63
|
+
arguments: request.arguments.map((arg: any) => {
|
|
64
|
+
if (Array.isArray(arg)) {
|
|
65
|
+
// TODO: support nested array, or use the BCS API instead
|
|
66
|
+
return arg.map((item: any) => item.toString());
|
|
67
|
+
} else if (typeof arg === "object") {
|
|
68
|
+
throw new Error(`a value of struct type: ${arg} is not supported`);
|
|
69
|
+
} else {
|
|
70
|
+
return arg.toString();
|
|
71
|
+
}
|
|
72
|
+
}),
|
|
73
|
+
}, { max_gas_amount });
|
|
74
|
+
|
|
75
|
+
const client = new AptosClient(nodeUrl);
|
|
76
|
+
const result = (await client.waitForTransactionWithResult(hash, {
|
|
77
|
+
checkSuccess: true,
|
|
78
|
+
})) as Types.Transaction_UserTransaction;
|
|
79
|
+
|
|
80
|
+
// Only update the status if the request is not stale.
|
|
81
|
+
if (id === idRef.current) {
|
|
82
|
+
try {
|
|
83
|
+
onSuccess?.(result);
|
|
84
|
+
}
|
|
85
|
+
catch (e) {
|
|
86
|
+
// error from user's callback
|
|
87
|
+
console.error(e);
|
|
88
|
+
}
|
|
89
|
+
setResult(result);
|
|
90
|
+
}
|
|
91
|
+
} catch (e) {
|
|
92
|
+
// Only update the status if the request is not stale.
|
|
93
|
+
if (id === idRef.current) {
|
|
94
|
+
const error = e instanceof Error ? e :
|
|
95
|
+
e ? new Error(String(e)) :
|
|
96
|
+
new Error("unknown error");
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
onFailed?.(error);
|
|
100
|
+
}
|
|
101
|
+
catch (e2) {
|
|
102
|
+
// error from user's callback
|
|
103
|
+
console.error(e2);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
setError(error);
|
|
107
|
+
}
|
|
108
|
+
} finally {
|
|
109
|
+
// Only update the status if the request is not stale.
|
|
110
|
+
if (id === idRef.current) {
|
|
111
|
+
setIsLoading(false);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return { submitTransaction, reset, isLoading, isIdle, data, error };
|
|
117
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useWallet } from "@aptos-labs/wallet-adapter-react";
|
|
2
|
+
import { MoveTsWalletClient } from "../core";
|
|
3
|
+
|
|
4
|
+
export const useWalletClient = ({ nodeUrl }: { nodeUrl: string }) => {
|
|
5
|
+
const wallet = useWallet();
|
|
6
|
+
return {
|
|
7
|
+
connected: wallet.connected,
|
|
8
|
+
client: wallet.connected ? new MoveTsWalletClient({ wallet, nodeUrl }) : undefined
|
|
9
|
+
};
|
|
10
|
+
}
|
package/src/index.ts
ADDED
package/src/types/abi.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
|
|
2
|
+
export interface ABIRoot {
|
|
3
|
+
address: string;
|
|
4
|
+
name: string;
|
|
5
|
+
friends: readonly string[];
|
|
6
|
+
exposed_functions: readonly ABIFunction[];
|
|
7
|
+
structs: readonly ABIStruct[];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface ABIFunction {
|
|
11
|
+
name: string;
|
|
12
|
+
visibility: "friend" | "public";
|
|
13
|
+
is_entry: boolean;
|
|
14
|
+
is_view: boolean;
|
|
15
|
+
generic_type_params: readonly ABIFunctionGenericTypeParam[];
|
|
16
|
+
params: readonly string[];
|
|
17
|
+
return: readonly string[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ABIFunctionGenericTypeParam {
|
|
21
|
+
constraints: readonly any[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ABIStruct {
|
|
25
|
+
name: string;
|
|
26
|
+
is_native: boolean;
|
|
27
|
+
abilities: readonly string[];
|
|
28
|
+
generic_type_params: readonly ABIFunctionGenericTypeParam[];
|
|
29
|
+
fields: readonly ABIStructField[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface ABIStructField {
|
|
33
|
+
name: string;
|
|
34
|
+
type: string;
|
|
35
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AptosAccount } from "aptos";
|
|
2
|
+
import { ABIRoot } from "./abi";
|
|
3
|
+
import { EntryFunctionName, ExtractGenericParamsType, ExtractParamsType, ExtractParamsTypeOmitSigner, ExtractReturnType, TransactionResponse, ViewFunctionName } from "./common";
|
|
4
|
+
|
|
5
|
+
export type ABIViewClient<T extends ABIRoot> = {
|
|
6
|
+
[TFuncName in ViewFunctionName<T>]: (payload: {
|
|
7
|
+
type_arguments: ExtractGenericParamsType<T, TFuncName>
|
|
8
|
+
arguments: ExtractParamsType<T, TFuncName>,
|
|
9
|
+
}) => Promise<ExtractReturnType<T, TFuncName>>
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type ABIEntryClient<T extends ABIRoot> = {
|
|
13
|
+
[TFuncName in EntryFunctionName<T>]: (payload: {
|
|
14
|
+
type_arguments: ExtractGenericParamsType<T, TFuncName>,
|
|
15
|
+
arguments: ExtractParamsTypeOmitSigner<T, TFuncName>,
|
|
16
|
+
account: AptosAccount,
|
|
17
|
+
isSimulation?: boolean
|
|
18
|
+
}) => Promise<TransactionResponse>
|
|
19
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { AptosAccount, TxnBuilderTypes } from "aptos";
|
|
2
|
+
|
|
3
|
+
export type EntryOptions = {
|
|
4
|
+
account: AptosAccount,
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export type ViewOptions = {
|
|
8
|
+
ledger_version?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type EntryPayload = {
|
|
12
|
+
rawPayload: {
|
|
13
|
+
function: string;
|
|
14
|
+
type_arguments: string[];
|
|
15
|
+
arguments: any[];
|
|
16
|
+
},
|
|
17
|
+
entryRequest: TxnBuilderTypes.EntryFunction,
|
|
18
|
+
// readonly abi: any,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
//@ts-ignore TODO: remove this ignore
|
|
22
|
+
export type ViewPayload<TReturn> = {
|
|
23
|
+
viewRequest: {
|
|
24
|
+
function: string;
|
|
25
|
+
type_arguments: string[];
|
|
26
|
+
arguments: any[];
|
|
27
|
+
};
|
|
28
|
+
decoders: (((value: any) => any) | null)[],
|
|
29
|
+
// readonly abi: any,
|
|
30
|
+
// readonly return: TReturn,
|
|
31
|
+
};
|
|
32
|
+
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { ABIRoot } from "./abi";
|
|
2
|
+
|
|
3
|
+
// TODO: rename this variable, not only primitive, but also struct and vector
|
|
4
|
+
export type Primitive =
|
|
5
|
+
'bool' | 'u8' | 'u16' | 'u32' |
|
|
6
|
+
'u64' | 'u128' | 'u256' | 'address' |
|
|
7
|
+
'0x1::string::String';
|
|
8
|
+
|
|
9
|
+
type Vector = `vector<${Primitive}>`;
|
|
10
|
+
type VectorOfVector = `vector<vector<${Primitive}>>`;
|
|
11
|
+
|
|
12
|
+
// TODO: support struct, vector<struct>, and vector<vector<vector>>
|
|
13
|
+
export type AllTypes = Primitive | Vector | VectorOfVector;
|
|
14
|
+
type ConvertPrimitiveArgsType<T extends Primitive> =
|
|
15
|
+
T extends 'bool' ? boolean :
|
|
16
|
+
T extends 'u8' ? number :
|
|
17
|
+
T extends 'u16' ? number :
|
|
18
|
+
T extends 'u32' ? number :
|
|
19
|
+
T extends 'u64' ? AnyNumber :
|
|
20
|
+
T extends 'u128' ? AnyNumber :
|
|
21
|
+
T extends 'u256' ? AnyNumber :
|
|
22
|
+
T extends 'address' ? `0x${string}` :
|
|
23
|
+
T extends '0x1::string::String' ? string :
|
|
24
|
+
never;
|
|
25
|
+
|
|
26
|
+
type ConvertVectorArgsType<TInner> = TInner extends Primitive ? ConvertPrimitiveArgsType<TInner>[] :
|
|
27
|
+
(
|
|
28
|
+
TInner extends `vector<${infer TInnerInner}>` ? (
|
|
29
|
+
TInnerInner extends Primitive ? ConvertPrimitiveArgsType<TInnerInner>[][] :
|
|
30
|
+
any[][]) : (
|
|
31
|
+
object[]
|
|
32
|
+
)
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
export type ConvertArgsType<T extends AllTypes> =
|
|
36
|
+
T extends Primitive ? ConvertPrimitiveArgsType<T> :
|
|
37
|
+
T extends `vector<${infer TInner}>` ? ConvertVectorArgsType<TInner> :
|
|
38
|
+
Struct<T>;
|
|
39
|
+
|
|
40
|
+
//@ts-ignore TODO: remove this ignore
|
|
41
|
+
type Struct<T extends string> = object;
|
|
42
|
+
|
|
43
|
+
type AnyNumber = number | bigint | string;
|
|
44
|
+
|
|
45
|
+
export type ConvertPrimitiveReturnType<T extends Primitive> =
|
|
46
|
+
T extends 'bool' ? boolean :
|
|
47
|
+
T extends 'u8' ? number :
|
|
48
|
+
T extends 'u16' ? number :
|
|
49
|
+
T extends 'u32' ? number :
|
|
50
|
+
T extends 'u64' ? bigint :
|
|
51
|
+
T extends 'u128' ? bigint :
|
|
52
|
+
T extends 'u256' ? bigint :
|
|
53
|
+
T extends 'address' ? `0x${string}` :
|
|
54
|
+
T extends '0x1::string::String' ? string :
|
|
55
|
+
never;
|
|
56
|
+
|
|
57
|
+
type ConvertVectorReturnType<TInner> = TInner extends Primitive ? ConvertPrimitiveReturnType<TInner>[] :
|
|
58
|
+
(
|
|
59
|
+
TInner extends `vector<${infer TInnerInner}>` ? (
|
|
60
|
+
TInnerInner extends Primitive ? ConvertPrimitiveReturnType<TInnerInner>[][] :
|
|
61
|
+
any[][]) : (
|
|
62
|
+
object[]
|
|
63
|
+
)
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
export type ConvertReturnType<T extends AllTypes> =
|
|
67
|
+
T extends Primitive ? ConvertPrimitiveReturnType<T> :
|
|
68
|
+
T extends `vector<${infer TInner}>` ? ConvertVectorReturnType<TInner> :
|
|
69
|
+
Struct<T>;
|
|
70
|
+
|
|
71
|
+
type Functions<T extends ABIRoot> = T['exposed_functions'];
|
|
72
|
+
type MoveFunction<T extends ABIRoot> = Functions<T>[number];
|
|
73
|
+
type FunctionName<T extends ABIRoot> = MoveFunction<T>['name'];
|
|
74
|
+
|
|
75
|
+
export type ExtractFunction<T extends ABIRoot, TFuncName extends FunctionName<T>> =
|
|
76
|
+
Extract<MoveFunction<T>, { name: TFuncName }>;
|
|
77
|
+
|
|
78
|
+
export type MoveViewFunction<T extends ABIRoot> = Extract<Functions<T>[number], { is_view: true }>;
|
|
79
|
+
export type ViewFunctionName<T extends ABIRoot> = MoveViewFunction<T>['name'];
|
|
80
|
+
export type MoveEntryFunction<T extends ABIRoot> = Extract<Functions<T>[number], { is_entry: true }>;
|
|
81
|
+
export type EntryFunctionName<T extends ABIRoot> = MoveEntryFunction<T>['name'];
|
|
82
|
+
|
|
83
|
+
// TODO: Figure out how to return the correct array type
|
|
84
|
+
type ConvertParams<T extends readonly string[]> = {
|
|
85
|
+
[P in keyof T]: T[P] extends AllTypes ? ConvertArgsType<T[P]> : Struct<T[P]>;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export type ConvertEntryParams<T extends readonly string[]> = ConvertParams<OmitSigner<T>>;
|
|
89
|
+
|
|
90
|
+
// TODO: Figure out how to return the correct array type
|
|
91
|
+
export type ConvertReturns<T extends readonly string[]> = {
|
|
92
|
+
[P in keyof T]: T[P] extends AllTypes ? ConvertReturnType<T[P]> : Struct<T[P]>;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export type ExtractReturnType<
|
|
96
|
+
T extends ABIRoot,
|
|
97
|
+
TFuncName extends FunctionName<T>> =
|
|
98
|
+
ConvertReturns<ExtractRawReturnType<T, TFuncName>>;
|
|
99
|
+
|
|
100
|
+
export type ExtractRawReturnType<
|
|
101
|
+
T extends ABIRoot,
|
|
102
|
+
TFuncName extends FunctionName<T>> =
|
|
103
|
+
ExtractFunction<T, TFuncName>['return'];
|
|
104
|
+
|
|
105
|
+
export type ExtractParamsType<
|
|
106
|
+
T extends ABIRoot,
|
|
107
|
+
TFuncName extends FunctionName<T>> =
|
|
108
|
+
ConvertParams<ExtractRawParamsType<T, TFuncName>>;
|
|
109
|
+
|
|
110
|
+
export type ExtractParamsTypeOmitSigner<
|
|
111
|
+
T extends ABIRoot,
|
|
112
|
+
TFuncName extends FunctionName<T>> =
|
|
113
|
+
ConvertParams<OmitSigner<ExtractRawParamsType<T, TFuncName>>>;
|
|
114
|
+
|
|
115
|
+
export type ExtractRawParamsType<
|
|
116
|
+
T extends ABIRoot,
|
|
117
|
+
TFuncName extends FunctionName<T>> =
|
|
118
|
+
ExtractFunction<T, TFuncName>['params'];
|
|
119
|
+
|
|
120
|
+
export type ExtractGenericParamsType<
|
|
121
|
+
T extends ABIRoot,
|
|
122
|
+
TFuncName extends FunctionName<T>> =
|
|
123
|
+
ConvertTypeParams<ExtractRawGenericParamsType<T, TFuncName>>;
|
|
124
|
+
|
|
125
|
+
export type ExtractRawGenericParamsType<
|
|
126
|
+
T extends ABIRoot,
|
|
127
|
+
TFuncName extends FunctionName<T>> =
|
|
128
|
+
ExtractFunction<T, TFuncName>['generic_type_params'];
|
|
129
|
+
|
|
130
|
+
// TODO: Figure out how to return the correct array type
|
|
131
|
+
export type ConvertTypeParams<T extends readonly any[]> = {
|
|
132
|
+
[P in keyof T]: string;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export type ViewRequestPayload<T extends ABIRoot, TFuncName extends ViewFunctionName<T>> = {
|
|
136
|
+
function: TFuncName,
|
|
137
|
+
arguments: ExtractParamsType<T, TFuncName>,
|
|
138
|
+
type_arguments: ExtractGenericParamsType<T, TFuncName>
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Remove all `signer` and `&signer` from argument list because the Move VM injects those arguments. Clients do not
|
|
142
|
+
// need to care about those args. `signer` and `&signer` are required be in the front of the argument list.
|
|
143
|
+
type OmitSigner<T extends readonly string[]> = T extends readonly ['&signer' | 'signer', ...infer Rest]
|
|
144
|
+
? Rest
|
|
145
|
+
: T;
|
|
146
|
+
|
|
147
|
+
export type EntryRequestPayload<
|
|
148
|
+
T extends ABIRoot,
|
|
149
|
+
TFuncName extends EntryFunctionName<T>> = {
|
|
150
|
+
function: TFuncName,
|
|
151
|
+
arguments: ExtractParamsTypeOmitSigner<T, TFuncName>,
|
|
152
|
+
type_arguments: ExtractGenericParamsType<T, TFuncName>
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export type TransactionResponse = {
|
|
156
|
+
hash: string;
|
|
157
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ABIRoot } from "./abi";
|
|
2
|
+
import { EntryFunctionName, ExtractGenericParamsType, ExtractParamsTypeOmitSigner, TransactionResponse } from "./common";
|
|
3
|
+
|
|
4
|
+
export type ABIWalletClient<T extends ABIRoot> = {
|
|
5
|
+
[TFuncName in EntryFunctionName<T>]:
|
|
6
|
+
(payload: {
|
|
7
|
+
type_arguments: ExtractGenericParamsType<T, TFuncName>,
|
|
8
|
+
arguments: ExtractParamsTypeOmitSigner<T, TFuncName>,
|
|
9
|
+
}) => Promise<TransactionResponse>
|
|
10
|
+
};
|