@haneullabs/payment-kit 0.1.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/README.md +123 -0
- package/dist/cjs/calls.d.ts +71 -0
- package/dist/cjs/calls.js +207 -0
- package/dist/cjs/calls.js.map +7 -0
- package/dist/cjs/client.d.ts +36 -0
- package/dist/cjs/client.js +123 -0
- package/dist/cjs/client.js.map +7 -0
- package/dist/cjs/constants.d.ts +11 -0
- package/dist/cjs/constants.js +40 -0
- package/dist/cjs/constants.js.map +7 -0
- package/dist/cjs/contracts/payment_kit/config.d.ts +14 -0
- package/dist/cjs/contracts/payment_kit/config.js +50 -0
- package/dist/cjs/contracts/payment_kit/config.js.map +7 -0
- package/dist/cjs/contracts/payment_kit/deps/std/type_name.d.ts +14 -0
- package/dist/cjs/contracts/payment_kit/deps/std/type_name.js +42 -0
- package/dist/cjs/contracts/payment_kit/deps/std/type_name.js.map +7 -0
- package/dist/cjs/contracts/payment_kit/deps/sui/object.d.ts +5 -0
- package/dist/cjs/contracts/payment_kit/deps/sui/object.js +33 -0
- package/dist/cjs/contracts/payment_kit/deps/sui/object.js.map +7 -0
- package/dist/cjs/contracts/payment_kit/deps/sui/vec_map.d.ts +27 -0
- package/dist/cjs/contracts/payment_kit/deps/sui/vec_map.js +45 -0
- package/dist/cjs/contracts/payment_kit/deps/sui/vec_map.js.map +7 -0
- package/dist/cjs/contracts/payment_kit/payment_kit.d.ts +233 -0
- package/dist/cjs/contracts/payment_kit/payment_kit.js +252 -0
- package/dist/cjs/contracts/payment_kit/payment_kit.js.map +7 -0
- package/dist/cjs/contracts/utils/index.d.ts +12 -0
- package/dist/cjs/contracts/utils/index.js +151 -0
- package/dist/cjs/contracts/utils/index.js.map +7 -0
- package/dist/cjs/error.d.ts +4 -0
- package/dist/cjs/error.js +29 -0
- package/dist/cjs/error.js.map +7 -0
- package/dist/cjs/index.d.ts +5 -0
- package/dist/cjs/index.js +35 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/package.json +5 -0
- package/dist/cjs/transactions.d.ts +73 -0
- package/dist/cjs/transactions.js +131 -0
- package/dist/cjs/transactions.js.map +7 -0
- package/dist/cjs/types.d.ts +62 -0
- package/dist/cjs/types.js +17 -0
- package/dist/cjs/types.js.map +7 -0
- package/dist/cjs/uri.d.ts +27 -0
- package/dist/cjs/uri.js +131 -0
- package/dist/cjs/uri.js.map +7 -0
- package/dist/cjs/utils.d.ts +1 -0
- package/dist/cjs/utils.js +34 -0
- package/dist/cjs/utils.js.map +7 -0
- package/dist/esm/calls.d.ts +71 -0
- package/dist/esm/calls.js +196 -0
- package/dist/esm/calls.js.map +7 -0
- package/dist/esm/client.d.ts +36 -0
- package/dist/esm/client.js +106 -0
- package/dist/esm/client.js.map +7 -0
- package/dist/esm/constants.d.ts +11 -0
- package/dist/esm/constants.js +20 -0
- package/dist/esm/constants.js.map +7 -0
- package/dist/esm/contracts/payment_kit/config.d.ts +14 -0
- package/dist/esm/contracts/payment_kit/config.js +20 -0
- package/dist/esm/contracts/payment_kit/config.js.map +7 -0
- package/dist/esm/contracts/payment_kit/deps/std/type_name.d.ts +14 -0
- package/dist/esm/contracts/payment_kit/deps/std/type_name.js +22 -0
- package/dist/esm/contracts/payment_kit/deps/std/type_name.js.map +7 -0
- package/dist/esm/contracts/payment_kit/deps/sui/object.d.ts +5 -0
- package/dist/esm/contracts/payment_kit/deps/sui/object.js +13 -0
- package/dist/esm/contracts/payment_kit/deps/sui/object.js.map +7 -0
- package/dist/esm/contracts/payment_kit/deps/sui/vec_map.d.ts +27 -0
- package/dist/esm/contracts/payment_kit/deps/sui/vec_map.js +25 -0
- package/dist/esm/contracts/payment_kit/deps/sui/vec_map.js.map +7 -0
- package/dist/esm/contracts/payment_kit/payment_kit.d.ts +233 -0
- package/dist/esm/contracts/payment_kit/payment_kit.js +222 -0
- package/dist/esm/contracts/payment_kit/payment_kit.js.map +7 -0
- package/dist/esm/contracts/utils/index.d.ts +12 -0
- package/dist/esm/contracts/utils/index.js +131 -0
- package/dist/esm/contracts/utils/index.js.map +7 -0
- package/dist/esm/error.d.ts +4 -0
- package/dist/esm/error.js +9 -0
- package/dist/esm/error.js.map +7 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.js +15 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/package.json +5 -0
- package/dist/esm/transactions.d.ts +73 -0
- package/dist/esm/transactions.js +111 -0
- package/dist/esm/transactions.js.map +7 -0
- package/dist/esm/types.d.ts +62 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/types.js.map +7 -0
- package/dist/esm/uri.d.ts +27 -0
- package/dist/esm/uri.js +111 -0
- package/dist/esm/uri.js.map +7 -0
- package/dist/esm/utils.d.ts +1 -0
- package/dist/esm/utils.js +14 -0
- package/dist/esm/utils.js.map +7 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +49 -0
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { MoveStruct, MoveEnum, MoveTuple } from '../utils/index.js';
|
|
2
|
+
import type { RawTransactionArgument } from '../utils/index.js';
|
|
3
|
+
import type { Transaction } from '@haneullabs/haneul/transactions';
|
|
4
|
+
export declare const Namespace: MoveStruct<{
|
|
5
|
+
id: MoveStruct<{
|
|
6
|
+
id: import("@haneullabs/haneul/bcs").BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
7
|
+
}, "0x2::object::UID">;
|
|
8
|
+
}, "@haneullabs/payment-kit::payment_kit::Namespace">;
|
|
9
|
+
export declare const PaymentRegistry: MoveStruct<{
|
|
10
|
+
id: MoveStruct<{
|
|
11
|
+
id: import("@haneullabs/haneul/bcs").BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
12
|
+
}, "0x2::object::UID">;
|
|
13
|
+
cap_id: import("@haneullabs/haneul/bcs").BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
14
|
+
config: MoveStruct<{
|
|
15
|
+
contents: import("@haneullabs/haneul/bcs").BcsType<{
|
|
16
|
+
key: string;
|
|
17
|
+
value: import("@haneullabs/bcs").EnumOutputShapeWithKeys<{
|
|
18
|
+
U64: string;
|
|
19
|
+
Address: string;
|
|
20
|
+
String: string;
|
|
21
|
+
AsciiString: string;
|
|
22
|
+
Bool: boolean;
|
|
23
|
+
Bytes: number[];
|
|
24
|
+
Type: {
|
|
25
|
+
name: string;
|
|
26
|
+
};
|
|
27
|
+
}, "String" | "U64" | "Address" | "AsciiString" | "Bool" | "Bytes" | "Type">;
|
|
28
|
+
}[], Iterable<{
|
|
29
|
+
key: string;
|
|
30
|
+
value: import("@haneullabs/bcs").EnumInputShape<{
|
|
31
|
+
U64: string | number | bigint;
|
|
32
|
+
Address: string | Uint8Array<ArrayBufferLike>;
|
|
33
|
+
String: string;
|
|
34
|
+
AsciiString: string;
|
|
35
|
+
Bool: boolean;
|
|
36
|
+
Bytes: Iterable<number> & {
|
|
37
|
+
length: number;
|
|
38
|
+
};
|
|
39
|
+
Type: {
|
|
40
|
+
name: string;
|
|
41
|
+
};
|
|
42
|
+
}>;
|
|
43
|
+
}> & {
|
|
44
|
+
length: number;
|
|
45
|
+
}, string>;
|
|
46
|
+
}, "0x2::vec_map::VecMap<string, @haneullabs/payment-kit::config::Value>">;
|
|
47
|
+
version: import("@haneullabs/haneul/bcs").BcsType<number, number, "u16">;
|
|
48
|
+
}, "@haneullabs/payment-kit::payment_kit::PaymentRegistry">;
|
|
49
|
+
export declare const RegistryAdminCap: MoveStruct<{
|
|
50
|
+
id: MoveStruct<{
|
|
51
|
+
id: import("@haneullabs/haneul/bcs").BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
52
|
+
}, "0x2::object::UID">;
|
|
53
|
+
registry_id: import("@haneullabs/haneul/bcs").BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
54
|
+
}, "@haneullabs/payment-kit::payment_kit::RegistryAdminCap">;
|
|
55
|
+
/**
|
|
56
|
+
* Enum representing the type of payment: Ephemeral (one-time) or Registry (tracked
|
|
57
|
+
* in a registry).
|
|
58
|
+
*/
|
|
59
|
+
export declare const PaymentType: MoveEnum<{
|
|
60
|
+
Ephemeral: null;
|
|
61
|
+
Registry: import("@haneullabs/haneul/bcs").BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
62
|
+
}, "@haneullabs/payment-kit::payment_kit::PaymentType">;
|
|
63
|
+
export declare const PaymentReceipt: MoveStruct<{
|
|
64
|
+
payment_type: MoveEnum<{
|
|
65
|
+
Ephemeral: null;
|
|
66
|
+
Registry: import("@haneullabs/haneul/bcs").BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
67
|
+
}, "@haneullabs/payment-kit::payment_kit::PaymentType">;
|
|
68
|
+
nonce: import("@haneullabs/haneul/bcs").BcsType<string, string, "string">;
|
|
69
|
+
payment_amount: import("@haneullabs/haneul/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
70
|
+
receiver: import("@haneullabs/haneul/bcs").BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
71
|
+
coin_type: import("@haneullabs/haneul/bcs").BcsType<string, string, "string">;
|
|
72
|
+
timestamp_ms: import("@haneullabs/haneul/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
73
|
+
}, "@haneullabs/payment-kit::payment_kit::PaymentReceipt">;
|
|
74
|
+
export declare const PaymentKey: MoveStruct<{
|
|
75
|
+
nonce: import("@haneullabs/haneul/bcs").BcsType<string, string, "string">;
|
|
76
|
+
payment_amount: import("@haneullabs/haneul/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
77
|
+
receiver: import("@haneullabs/haneul/bcs").BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
78
|
+
}, "@haneullabs/payment-kit::payment_kit::PaymentKey">;
|
|
79
|
+
export declare const PaymentRecord: MoveStruct<{
|
|
80
|
+
epoch_at_time_of_record: import("@haneullabs/haneul/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
81
|
+
}, "@haneullabs/payment-kit::payment_kit::PaymentRecord">;
|
|
82
|
+
export declare const BalanceKey: MoveTuple<import("@haneullabs/haneul/bcs").BcsType<boolean, boolean, "bool">[], "@haneullabs/payment-kit::payment_kit::BalanceKey">;
|
|
83
|
+
export interface CreateRegistryArguments {
|
|
84
|
+
namespace: RawTransactionArgument<string>;
|
|
85
|
+
name: RawTransactionArgument<string>;
|
|
86
|
+
}
|
|
87
|
+
export interface CreateRegistryOptions {
|
|
88
|
+
package?: string;
|
|
89
|
+
arguments: CreateRegistryArguments | [namespace: RawTransactionArgument<string>, name: RawTransactionArgument<string>];
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Creates a new payment registry with a supplied label. Label is used to derive
|
|
93
|
+
* the registry's ID.
|
|
94
|
+
*/
|
|
95
|
+
export declare function createRegistry(options: CreateRegistryOptions): (tx: Transaction) => import("@haneullabs/haneul/transactions").TransactionResult;
|
|
96
|
+
export interface ProcessEphemeralPaymentArguments {
|
|
97
|
+
nonce: RawTransactionArgument<string>;
|
|
98
|
+
paymentAmount: RawTransactionArgument<number | bigint>;
|
|
99
|
+
coin: RawTransactionArgument<string>;
|
|
100
|
+
receiver: RawTransactionArgument<string>;
|
|
101
|
+
}
|
|
102
|
+
export interface ProcessEphemeralPaymentOptions {
|
|
103
|
+
package?: string;
|
|
104
|
+
arguments: ProcessEphemeralPaymentArguments | [
|
|
105
|
+
nonce: RawTransactionArgument<string>,
|
|
106
|
+
paymentAmount: RawTransactionArgument<number | bigint>,
|
|
107
|
+
coin: RawTransactionArgument<string>,
|
|
108
|
+
receiver: RawTransactionArgument<string>
|
|
109
|
+
];
|
|
110
|
+
typeArguments: [string];
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Processes a payment (without the use of a Registry), emitting a payment receipt
|
|
114
|
+
* event.
|
|
115
|
+
*/
|
|
116
|
+
export declare function processEphemeralPayment(options: ProcessEphemeralPaymentOptions): (tx: Transaction) => import("@haneullabs/haneul/transactions").TransactionResult;
|
|
117
|
+
export interface ProcessRegistryPaymentArguments {
|
|
118
|
+
registry: RawTransactionArgument<string>;
|
|
119
|
+
nonce: RawTransactionArgument<string>;
|
|
120
|
+
paymentAmount: RawTransactionArgument<number | bigint>;
|
|
121
|
+
coin: RawTransactionArgument<string>;
|
|
122
|
+
receiver: RawTransactionArgument<string | null>;
|
|
123
|
+
}
|
|
124
|
+
export interface ProcessRegistryPaymentOptions {
|
|
125
|
+
package?: string;
|
|
126
|
+
arguments: ProcessRegistryPaymentArguments | [
|
|
127
|
+
registry: RawTransactionArgument<string>,
|
|
128
|
+
nonce: RawTransactionArgument<string>,
|
|
129
|
+
paymentAmount: RawTransactionArgument<number | bigint>,
|
|
130
|
+
coin: RawTransactionArgument<string>,
|
|
131
|
+
receiver: RawTransactionArgument<string | null>
|
|
132
|
+
];
|
|
133
|
+
typeArguments: [string];
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Processes a payment via a payment registry, writing a receipt to the registry
|
|
137
|
+
* and protecting from double spending for the same key.
|
|
138
|
+
*/
|
|
139
|
+
export declare function processRegistryPayment(options: ProcessRegistryPaymentOptions): (tx: Transaction) => import("@haneullabs/haneul/transactions").TransactionResult;
|
|
140
|
+
export interface WithdrawFromRegistryArguments {
|
|
141
|
+
registry: RawTransactionArgument<string>;
|
|
142
|
+
cap: RawTransactionArgument<string>;
|
|
143
|
+
}
|
|
144
|
+
export interface WithdrawFromRegistryOptions {
|
|
145
|
+
package?: string;
|
|
146
|
+
arguments: WithdrawFromRegistryArguments | [registry: RawTransactionArgument<string>, cap: RawTransactionArgument<string>];
|
|
147
|
+
typeArguments: [string];
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* If the registry is configured to manage funds, withdraw all funds of the
|
|
151
|
+
* specified coin from the registry.
|
|
152
|
+
*/
|
|
153
|
+
export declare function withdrawFromRegistry(options: WithdrawFromRegistryOptions): (tx: Transaction) => import("@haneullabs/haneul/transactions").TransactionResult;
|
|
154
|
+
export interface DeletePaymentRecordArguments {
|
|
155
|
+
registry: RawTransactionArgument<string>;
|
|
156
|
+
paymentKey: RawTransactionArgument<string>;
|
|
157
|
+
}
|
|
158
|
+
export interface DeletePaymentRecordOptions {
|
|
159
|
+
package?: string;
|
|
160
|
+
arguments: DeletePaymentRecordArguments | [registry: RawTransactionArgument<string>, paymentKey: RawTransactionArgument<string>];
|
|
161
|
+
typeArguments: [string];
|
|
162
|
+
}
|
|
163
|
+
/** Removes an expired Payment Record from the Registry. */
|
|
164
|
+
export declare function deletePaymentRecord(options: DeletePaymentRecordOptions): (tx: Transaction) => import("@haneullabs/haneul/transactions").TransactionResult;
|
|
165
|
+
export interface CreatePaymentKeyArguments {
|
|
166
|
+
nonce: RawTransactionArgument<string>;
|
|
167
|
+
paymentAmount: RawTransactionArgument<number | bigint>;
|
|
168
|
+
receiver: RawTransactionArgument<string>;
|
|
169
|
+
}
|
|
170
|
+
export interface CreatePaymentKeyOptions {
|
|
171
|
+
package?: string;
|
|
172
|
+
arguments: CreatePaymentKeyArguments | [
|
|
173
|
+
nonce: RawTransactionArgument<string>,
|
|
174
|
+
paymentAmount: RawTransactionArgument<number | bigint>,
|
|
175
|
+
receiver: RawTransactionArgument<string>
|
|
176
|
+
];
|
|
177
|
+
typeArguments: [string];
|
|
178
|
+
}
|
|
179
|
+
/** Creates a PaymentKey from payment parameters. */
|
|
180
|
+
export declare function createPaymentKey(options: CreatePaymentKeyOptions): (tx: Transaction) => import("@haneullabs/haneul/transactions").TransactionResult;
|
|
181
|
+
export interface SetConfigEpochExpirationDurationArguments {
|
|
182
|
+
registry: RawTransactionArgument<string>;
|
|
183
|
+
cap: RawTransactionArgument<string>;
|
|
184
|
+
epochExpirationDuration: RawTransactionArgument<number | bigint>;
|
|
185
|
+
}
|
|
186
|
+
export interface SetConfigEpochExpirationDurationOptions {
|
|
187
|
+
package?: string;
|
|
188
|
+
arguments: SetConfigEpochExpirationDurationArguments | [
|
|
189
|
+
registry: RawTransactionArgument<string>,
|
|
190
|
+
cap: RawTransactionArgument<string>,
|
|
191
|
+
epochExpirationDuration: RawTransactionArgument<number | bigint>
|
|
192
|
+
];
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Sets the epoch expiration duration configuration for the registry. If set,
|
|
196
|
+
* payment records will expire after the specified number of epochs. If not set,
|
|
197
|
+
* payment records will expire 30 epochs after their creation.
|
|
198
|
+
*/
|
|
199
|
+
export declare function setConfigEpochExpirationDuration(options: SetConfigEpochExpirationDurationOptions): (tx: Transaction) => import("@haneullabs/haneul/transactions").TransactionResult;
|
|
200
|
+
export interface SetConfigRegistryManagedFundsArguments {
|
|
201
|
+
registry: RawTransactionArgument<string>;
|
|
202
|
+
cap: RawTransactionArgument<string>;
|
|
203
|
+
registryManagedFunds: RawTransactionArgument<boolean>;
|
|
204
|
+
}
|
|
205
|
+
export interface SetConfigRegistryManagedFundsOptions {
|
|
206
|
+
package?: string;
|
|
207
|
+
arguments: SetConfigRegistryManagedFundsArguments | [
|
|
208
|
+
registry: RawTransactionArgument<string>,
|
|
209
|
+
cap: RawTransactionArgument<string>,
|
|
210
|
+
registryManagedFunds: RawTransactionArgument<boolean>
|
|
211
|
+
];
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Sets whether the registry should manage funds itself. If true, payments
|
|
215
|
+
* processed via the registry will be collected into the registry's balance. If
|
|
216
|
+
* false, payments will be transferred directly to the specified receiver.
|
|
217
|
+
*/
|
|
218
|
+
export declare function setConfigRegistryManagedFunds(options: SetConfigRegistryManagedFundsOptions): (tx: Transaction) => import("@haneullabs/haneul/transactions").TransactionResult;
|
|
219
|
+
export interface ShareArguments {
|
|
220
|
+
registry: RawTransactionArgument<string>;
|
|
221
|
+
}
|
|
222
|
+
export interface ShareOptions {
|
|
223
|
+
package?: string;
|
|
224
|
+
arguments: ShareArguments | [registry: RawTransactionArgument<string>];
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Enforce that a registry will always be shared.
|
|
228
|
+
*
|
|
229
|
+
* # Parameters
|
|
230
|
+
*
|
|
231
|
+
* - `registry` - The PaymentRegistry to share
|
|
232
|
+
*/
|
|
233
|
+
export declare function share(options: ShareOptions): (tx: Transaction) => import("@haneullabs/haneul/transactions").TransactionResult;
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { MoveStruct, MoveEnum, MoveTuple, normalizeMoveArguments } from "../utils/index.js";
|
|
2
|
+
import { bcs } from "@haneullabs/haneul/bcs";
|
|
3
|
+
import * as object from "./deps/sui/object.js";
|
|
4
|
+
import * as vec_map from "./deps/sui/vec_map.js";
|
|
5
|
+
import * as config from "./config.js";
|
|
6
|
+
const $moduleName = "@haneullabs/payment-kit::payment_kit";
|
|
7
|
+
const Namespace = new MoveStruct({
|
|
8
|
+
name: `${$moduleName}::Namespace`,
|
|
9
|
+
fields: {
|
|
10
|
+
id: object.UID
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
const PaymentRegistry = new MoveStruct({
|
|
14
|
+
name: `${$moduleName}::PaymentRegistry`,
|
|
15
|
+
fields: {
|
|
16
|
+
id: object.UID,
|
|
17
|
+
cap_id: bcs.Address,
|
|
18
|
+
config: vec_map.VecMap(bcs.string(), config.Value),
|
|
19
|
+
version: bcs.u16()
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const RegistryAdminCap = new MoveStruct({
|
|
23
|
+
name: `${$moduleName}::RegistryAdminCap`,
|
|
24
|
+
fields: {
|
|
25
|
+
id: object.UID,
|
|
26
|
+
registry_id: bcs.Address
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
const PaymentType = new MoveEnum({
|
|
30
|
+
name: `${$moduleName}::PaymentType`,
|
|
31
|
+
fields: {
|
|
32
|
+
Ephemeral: null,
|
|
33
|
+
Registry: bcs.Address
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
const PaymentReceipt = new MoveStruct({
|
|
37
|
+
name: `${$moduleName}::PaymentReceipt`,
|
|
38
|
+
fields: {
|
|
39
|
+
payment_type: PaymentType,
|
|
40
|
+
nonce: bcs.string(),
|
|
41
|
+
payment_amount: bcs.u64(),
|
|
42
|
+
receiver: bcs.Address,
|
|
43
|
+
coin_type: bcs.string(),
|
|
44
|
+
timestamp_ms: bcs.u64()
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
const PaymentKey = new MoveStruct({
|
|
48
|
+
name: `${$moduleName}::PaymentKey`,
|
|
49
|
+
fields: {
|
|
50
|
+
nonce: bcs.string(),
|
|
51
|
+
payment_amount: bcs.u64(),
|
|
52
|
+
receiver: bcs.Address
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
const PaymentRecord = new MoveStruct({
|
|
56
|
+
name: `${$moduleName}::PaymentRecord`,
|
|
57
|
+
fields: {
|
|
58
|
+
epoch_at_time_of_record: bcs.u64()
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
const BalanceKey = new MoveTuple({
|
|
62
|
+
name: `${$moduleName}::BalanceKey`,
|
|
63
|
+
fields: [bcs.bool()]
|
|
64
|
+
});
|
|
65
|
+
function createRegistry(options) {
|
|
66
|
+
const packageAddress = options.package ?? "@haneullabs/payment-kit";
|
|
67
|
+
const argumentsTypes = [
|
|
68
|
+
`${packageAddress}::payment_kit::Namespace`,
|
|
69
|
+
"0x0000000000000000000000000000000000000000000000000000000000000001::ascii::String"
|
|
70
|
+
];
|
|
71
|
+
const parameterNames = ["namespace", "name"];
|
|
72
|
+
return (tx) => tx.moveCall({
|
|
73
|
+
package: packageAddress,
|
|
74
|
+
module: "payment_kit",
|
|
75
|
+
function: "create_registry",
|
|
76
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames)
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
function processEphemeralPayment(options) {
|
|
80
|
+
const packageAddress = options.package ?? "@haneullabs/payment-kit";
|
|
81
|
+
const argumentsTypes = [
|
|
82
|
+
"0x0000000000000000000000000000000000000000000000000000000000000001::ascii::String",
|
|
83
|
+
"u64",
|
|
84
|
+
`0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${options.typeArguments[0]}>`,
|
|
85
|
+
"address",
|
|
86
|
+
"0x0000000000000000000000000000000000000000000000000000000000000002::clock::Clock"
|
|
87
|
+
];
|
|
88
|
+
const parameterNames = ["nonce", "paymentAmount", "coin", "receiver"];
|
|
89
|
+
return (tx) => tx.moveCall({
|
|
90
|
+
package: packageAddress,
|
|
91
|
+
module: "payment_kit",
|
|
92
|
+
function: "process_ephemeral_payment",
|
|
93
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
94
|
+
typeArguments: options.typeArguments
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
function processRegistryPayment(options) {
|
|
98
|
+
const packageAddress = options.package ?? "@haneullabs/payment-kit";
|
|
99
|
+
const argumentsTypes = [
|
|
100
|
+
`${packageAddress}::payment_kit::PaymentRegistry`,
|
|
101
|
+
"0x0000000000000000000000000000000000000000000000000000000000000001::ascii::String",
|
|
102
|
+
"u64",
|
|
103
|
+
`0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${options.typeArguments[0]}>`,
|
|
104
|
+
"0x0000000000000000000000000000000000000000000000000000000000000001::option::Option<address>",
|
|
105
|
+
"0x0000000000000000000000000000000000000000000000000000000000000002::clock::Clock"
|
|
106
|
+
];
|
|
107
|
+
const parameterNames = ["registry", "nonce", "paymentAmount", "coin", "receiver"];
|
|
108
|
+
return (tx) => tx.moveCall({
|
|
109
|
+
package: packageAddress,
|
|
110
|
+
module: "payment_kit",
|
|
111
|
+
function: "process_registry_payment",
|
|
112
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
113
|
+
typeArguments: options.typeArguments
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
function withdrawFromRegistry(options) {
|
|
117
|
+
const packageAddress = options.package ?? "@haneullabs/payment-kit";
|
|
118
|
+
const argumentsTypes = [
|
|
119
|
+
`${packageAddress}::payment_kit::PaymentRegistry`,
|
|
120
|
+
`${packageAddress}::payment_kit::RegistryAdminCap`
|
|
121
|
+
];
|
|
122
|
+
const parameterNames = ["registry", "cap"];
|
|
123
|
+
return (tx) => tx.moveCall({
|
|
124
|
+
package: packageAddress,
|
|
125
|
+
module: "payment_kit",
|
|
126
|
+
function: "withdraw_from_registry",
|
|
127
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
128
|
+
typeArguments: options.typeArguments
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
function deletePaymentRecord(options) {
|
|
132
|
+
const packageAddress = options.package ?? "@haneullabs/payment-kit";
|
|
133
|
+
const argumentsTypes = [
|
|
134
|
+
`${packageAddress}::payment_kit::PaymentRegistry`,
|
|
135
|
+
`${packageAddress}::payment_kit::PaymentKey<${options.typeArguments[0]}>`
|
|
136
|
+
];
|
|
137
|
+
const parameterNames = ["registry", "paymentKey"];
|
|
138
|
+
return (tx) => tx.moveCall({
|
|
139
|
+
package: packageAddress,
|
|
140
|
+
module: "payment_kit",
|
|
141
|
+
function: "delete_payment_record",
|
|
142
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
143
|
+
typeArguments: options.typeArguments
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
function createPaymentKey(options) {
|
|
147
|
+
const packageAddress = options.package ?? "@haneullabs/payment-kit";
|
|
148
|
+
const argumentsTypes = [
|
|
149
|
+
"0x0000000000000000000000000000000000000000000000000000000000000001::ascii::String",
|
|
150
|
+
"u64",
|
|
151
|
+
"address"
|
|
152
|
+
];
|
|
153
|
+
const parameterNames = ["nonce", "paymentAmount", "receiver"];
|
|
154
|
+
return (tx) => tx.moveCall({
|
|
155
|
+
package: packageAddress,
|
|
156
|
+
module: "payment_kit",
|
|
157
|
+
function: "create_payment_key",
|
|
158
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
159
|
+
typeArguments: options.typeArguments
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
function setConfigEpochExpirationDuration(options) {
|
|
163
|
+
const packageAddress = options.package ?? "@haneullabs/payment-kit";
|
|
164
|
+
const argumentsTypes = [
|
|
165
|
+
`${packageAddress}::payment_kit::PaymentRegistry`,
|
|
166
|
+
`${packageAddress}::payment_kit::RegistryAdminCap`,
|
|
167
|
+
"u64"
|
|
168
|
+
];
|
|
169
|
+
const parameterNames = ["registry", "cap", "epochExpirationDuration"];
|
|
170
|
+
return (tx) => tx.moveCall({
|
|
171
|
+
package: packageAddress,
|
|
172
|
+
module: "payment_kit",
|
|
173
|
+
function: "set_config_epoch_expiration_duration",
|
|
174
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames)
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
function setConfigRegistryManagedFunds(options) {
|
|
178
|
+
const packageAddress = options.package ?? "@haneullabs/payment-kit";
|
|
179
|
+
const argumentsTypes = [
|
|
180
|
+
`${packageAddress}::payment_kit::PaymentRegistry`,
|
|
181
|
+
`${packageAddress}::payment_kit::RegistryAdminCap`,
|
|
182
|
+
"bool"
|
|
183
|
+
];
|
|
184
|
+
const parameterNames = ["registry", "cap", "registryManagedFunds"];
|
|
185
|
+
return (tx) => tx.moveCall({
|
|
186
|
+
package: packageAddress,
|
|
187
|
+
module: "payment_kit",
|
|
188
|
+
function: "set_config_registry_managed_funds",
|
|
189
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames)
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
function share(options) {
|
|
193
|
+
const packageAddress = options.package ?? "@haneullabs/payment-kit";
|
|
194
|
+
const argumentsTypes = [`${packageAddress}::payment_kit::PaymentRegistry`];
|
|
195
|
+
const parameterNames = ["registry"];
|
|
196
|
+
return (tx) => tx.moveCall({
|
|
197
|
+
package: packageAddress,
|
|
198
|
+
module: "payment_kit",
|
|
199
|
+
function: "share",
|
|
200
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames)
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
export {
|
|
204
|
+
BalanceKey,
|
|
205
|
+
Namespace,
|
|
206
|
+
PaymentKey,
|
|
207
|
+
PaymentReceipt,
|
|
208
|
+
PaymentRecord,
|
|
209
|
+
PaymentRegistry,
|
|
210
|
+
PaymentType,
|
|
211
|
+
RegistryAdminCap,
|
|
212
|
+
createPaymentKey,
|
|
213
|
+
createRegistry,
|
|
214
|
+
deletePaymentRecord,
|
|
215
|
+
processEphemeralPayment,
|
|
216
|
+
processRegistryPayment,
|
|
217
|
+
setConfigEpochExpirationDuration,
|
|
218
|
+
setConfigRegistryManagedFunds,
|
|
219
|
+
share,
|
|
220
|
+
withdrawFromRegistry
|
|
221
|
+
};
|
|
222
|
+
//# sourceMappingURL=payment_kit.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/contracts/payment_kit/payment_kit.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport { MoveStruct, MoveEnum, MoveTuple, normalizeMoveArguments } from '../utils/index.js';\nimport type { RawTransactionArgument } from '../utils/index.js';\nimport { bcs } from '@haneullabs/haneul/bcs';\nimport type { Transaction } from '@haneullabs/haneul/transactions';\nimport * as object from './deps/sui/object.js';\nimport * as vec_map from './deps/sui/vec_map.js';\nimport * as config from './config.js';\nconst $moduleName = '@haneullabs/payment-kit::payment_kit';\nexport const Namespace = new MoveStruct({\n\tname: `${$moduleName}::Namespace`,\n\tfields: {\n\t\tid: object.UID,\n\t},\n});\nexport const PaymentRegistry = new MoveStruct({\n\tname: `${$moduleName}::PaymentRegistry`,\n\tfields: {\n\t\tid: object.UID,\n\t\tcap_id: bcs.Address,\n\t\tconfig: vec_map.VecMap(bcs.string(), config.Value),\n\t\tversion: bcs.u16(),\n\t},\n});\nexport const RegistryAdminCap = new MoveStruct({\n\tname: `${$moduleName}::RegistryAdminCap`,\n\tfields: {\n\t\tid: object.UID,\n\t\tregistry_id: bcs.Address,\n\t},\n});\n/**\n * Enum representing the type of payment: Ephemeral (one-time) or Registry (tracked\n * in a registry).\n */\nexport const PaymentType = new MoveEnum({\n\tname: `${$moduleName}::PaymentType`,\n\tfields: {\n\t\tEphemeral: null,\n\t\tRegistry: bcs.Address,\n\t},\n});\nexport const PaymentReceipt = new MoveStruct({\n\tname: `${$moduleName}::PaymentReceipt`,\n\tfields: {\n\t\tpayment_type: PaymentType,\n\t\tnonce: bcs.string(),\n\t\tpayment_amount: bcs.u64(),\n\t\treceiver: bcs.Address,\n\t\tcoin_type: bcs.string(),\n\t\ttimestamp_ms: bcs.u64(),\n\t},\n});\nexport const PaymentKey = new MoveStruct({\n\tname: `${$moduleName}::PaymentKey`,\n\tfields: {\n\t\tnonce: bcs.string(),\n\t\tpayment_amount: bcs.u64(),\n\t\treceiver: bcs.Address,\n\t},\n});\nexport const PaymentRecord = new MoveStruct({\n\tname: `${$moduleName}::PaymentRecord`,\n\tfields: {\n\t\tepoch_at_time_of_record: bcs.u64(),\n\t},\n});\nexport const BalanceKey = new MoveTuple({\n\tname: `${$moduleName}::BalanceKey`,\n\tfields: [bcs.bool()],\n});\nexport interface CreateRegistryArguments {\n\tnamespace: RawTransactionArgument<string>;\n\tname: RawTransactionArgument<string>;\n}\nexport interface CreateRegistryOptions {\n\tpackage?: string;\n\targuments:\n\t\t| CreateRegistryArguments\n\t\t| [namespace: RawTransactionArgument<string>, name: RawTransactionArgument<string>];\n}\n/**\n * Creates a new payment registry with a supplied label. Label is used to derive\n * the registry's ID.\n */\nexport function createRegistry(options: CreateRegistryOptions) {\n\tconst packageAddress = options.package ?? '@haneullabs/payment-kit';\n\tconst argumentsTypes = [\n\t\t`${packageAddress}::payment_kit::Namespace`,\n\t\t'0x0000000000000000000000000000000000000000000000000000000000000001::ascii::String',\n\t] satisfies string[];\n\tconst parameterNames = ['namespace', 'name'];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'payment_kit',\n\t\t\tfunction: 'create_registry',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),\n\t\t});\n}\nexport interface ProcessEphemeralPaymentArguments {\n\tnonce: RawTransactionArgument<string>;\n\tpaymentAmount: RawTransactionArgument<number | bigint>;\n\tcoin: RawTransactionArgument<string>;\n\treceiver: RawTransactionArgument<string>;\n}\nexport interface ProcessEphemeralPaymentOptions {\n\tpackage?: string;\n\targuments:\n\t\t| ProcessEphemeralPaymentArguments\n\t\t| [\n\t\t\t\tnonce: RawTransactionArgument<string>,\n\t\t\t\tpaymentAmount: RawTransactionArgument<number | bigint>,\n\t\t\t\tcoin: RawTransactionArgument<string>,\n\t\t\t\treceiver: RawTransactionArgument<string>,\n\t\t ];\n\ttypeArguments: [string];\n}\n/**\n * Processes a payment (without the use of a Registry), emitting a payment receipt\n * event.\n */\nexport function processEphemeralPayment(options: ProcessEphemeralPaymentOptions) {\n\tconst packageAddress = options.package ?? '@haneullabs/payment-kit';\n\tconst argumentsTypes = [\n\t\t'0x0000000000000000000000000000000000000000000000000000000000000001::ascii::String',\n\t\t'u64',\n\t\t`0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${options.typeArguments[0]}>`,\n\t\t'address',\n\t\t'0x0000000000000000000000000000000000000000000000000000000000000002::clock::Clock',\n\t] satisfies string[];\n\tconst parameterNames = ['nonce', 'paymentAmount', 'coin', 'receiver'];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'payment_kit',\n\t\t\tfunction: 'process_ephemeral_payment',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),\n\t\t\ttypeArguments: options.typeArguments,\n\t\t});\n}\nexport interface ProcessRegistryPaymentArguments {\n\tregistry: RawTransactionArgument<string>;\n\tnonce: RawTransactionArgument<string>;\n\tpaymentAmount: RawTransactionArgument<number | bigint>;\n\tcoin: RawTransactionArgument<string>;\n\treceiver: RawTransactionArgument<string | null>;\n}\nexport interface ProcessRegistryPaymentOptions {\n\tpackage?: string;\n\targuments:\n\t\t| ProcessRegistryPaymentArguments\n\t\t| [\n\t\t\t\tregistry: RawTransactionArgument<string>,\n\t\t\t\tnonce: RawTransactionArgument<string>,\n\t\t\t\tpaymentAmount: RawTransactionArgument<number | bigint>,\n\t\t\t\tcoin: RawTransactionArgument<string>,\n\t\t\t\treceiver: RawTransactionArgument<string | null>,\n\t\t ];\n\ttypeArguments: [string];\n}\n/**\n * Processes a payment via a payment registry, writing a receipt to the registry\n * and protecting from double spending for the same key.\n */\nexport function processRegistryPayment(options: ProcessRegistryPaymentOptions) {\n\tconst packageAddress = options.package ?? '@haneullabs/payment-kit';\n\tconst argumentsTypes = [\n\t\t`${packageAddress}::payment_kit::PaymentRegistry`,\n\t\t'0x0000000000000000000000000000000000000000000000000000000000000001::ascii::String',\n\t\t'u64',\n\t\t`0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<${options.typeArguments[0]}>`,\n\t\t'0x0000000000000000000000000000000000000000000000000000000000000001::option::Option<address>',\n\t\t'0x0000000000000000000000000000000000000000000000000000000000000002::clock::Clock',\n\t] satisfies string[];\n\tconst parameterNames = ['registry', 'nonce', 'paymentAmount', 'coin', 'receiver'];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'payment_kit',\n\t\t\tfunction: 'process_registry_payment',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),\n\t\t\ttypeArguments: options.typeArguments,\n\t\t});\n}\nexport interface WithdrawFromRegistryArguments {\n\tregistry: RawTransactionArgument<string>;\n\tcap: RawTransactionArgument<string>;\n}\nexport interface WithdrawFromRegistryOptions {\n\tpackage?: string;\n\targuments:\n\t\t| WithdrawFromRegistryArguments\n\t\t| [registry: RawTransactionArgument<string>, cap: RawTransactionArgument<string>];\n\ttypeArguments: [string];\n}\n/**\n * If the registry is configured to manage funds, withdraw all funds of the\n * specified coin from the registry.\n */\nexport function withdrawFromRegistry(options: WithdrawFromRegistryOptions) {\n\tconst packageAddress = options.package ?? '@haneullabs/payment-kit';\n\tconst argumentsTypes = [\n\t\t`${packageAddress}::payment_kit::PaymentRegistry`,\n\t\t`${packageAddress}::payment_kit::RegistryAdminCap`,\n\t] satisfies string[];\n\tconst parameterNames = ['registry', 'cap'];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'payment_kit',\n\t\t\tfunction: 'withdraw_from_registry',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),\n\t\t\ttypeArguments: options.typeArguments,\n\t\t});\n}\nexport interface DeletePaymentRecordArguments {\n\tregistry: RawTransactionArgument<string>;\n\tpaymentKey: RawTransactionArgument<string>;\n}\nexport interface DeletePaymentRecordOptions {\n\tpackage?: string;\n\targuments:\n\t\t| DeletePaymentRecordArguments\n\t\t| [registry: RawTransactionArgument<string>, paymentKey: RawTransactionArgument<string>];\n\ttypeArguments: [string];\n}\n/** Removes an expired Payment Record from the Registry. */\nexport function deletePaymentRecord(options: DeletePaymentRecordOptions) {\n\tconst packageAddress = options.package ?? '@haneullabs/payment-kit';\n\tconst argumentsTypes = [\n\t\t`${packageAddress}::payment_kit::PaymentRegistry`,\n\t\t`${packageAddress}::payment_kit::PaymentKey<${options.typeArguments[0]}>`,\n\t] satisfies string[];\n\tconst parameterNames = ['registry', 'paymentKey'];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'payment_kit',\n\t\t\tfunction: 'delete_payment_record',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),\n\t\t\ttypeArguments: options.typeArguments,\n\t\t});\n}\nexport interface CreatePaymentKeyArguments {\n\tnonce: RawTransactionArgument<string>;\n\tpaymentAmount: RawTransactionArgument<number | bigint>;\n\treceiver: RawTransactionArgument<string>;\n}\nexport interface CreatePaymentKeyOptions {\n\tpackage?: string;\n\targuments:\n\t\t| CreatePaymentKeyArguments\n\t\t| [\n\t\t\t\tnonce: RawTransactionArgument<string>,\n\t\t\t\tpaymentAmount: RawTransactionArgument<number | bigint>,\n\t\t\t\treceiver: RawTransactionArgument<string>,\n\t\t ];\n\ttypeArguments: [string];\n}\n/** Creates a PaymentKey from payment parameters. */\nexport function createPaymentKey(options: CreatePaymentKeyOptions) {\n\tconst packageAddress = options.package ?? '@haneullabs/payment-kit';\n\tconst argumentsTypes = [\n\t\t'0x0000000000000000000000000000000000000000000000000000000000000001::ascii::String',\n\t\t'u64',\n\t\t'address',\n\t] satisfies string[];\n\tconst parameterNames = ['nonce', 'paymentAmount', 'receiver'];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'payment_kit',\n\t\t\tfunction: 'create_payment_key',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),\n\t\t\ttypeArguments: options.typeArguments,\n\t\t});\n}\nexport interface SetConfigEpochExpirationDurationArguments {\n\tregistry: RawTransactionArgument<string>;\n\tcap: RawTransactionArgument<string>;\n\tepochExpirationDuration: RawTransactionArgument<number | bigint>;\n}\nexport interface SetConfigEpochExpirationDurationOptions {\n\tpackage?: string;\n\targuments:\n\t\t| SetConfigEpochExpirationDurationArguments\n\t\t| [\n\t\t\t\tregistry: RawTransactionArgument<string>,\n\t\t\t\tcap: RawTransactionArgument<string>,\n\t\t\t\tepochExpirationDuration: RawTransactionArgument<number | bigint>,\n\t\t ];\n}\n/**\n * Sets the epoch expiration duration configuration for the registry. If set,\n * payment records will expire after the specified number of epochs. If not set,\n * payment records will expire 30 epochs after their creation.\n */\nexport function setConfigEpochExpirationDuration(options: SetConfigEpochExpirationDurationOptions) {\n\tconst packageAddress = options.package ?? '@haneullabs/payment-kit';\n\tconst argumentsTypes = [\n\t\t`${packageAddress}::payment_kit::PaymentRegistry`,\n\t\t`${packageAddress}::payment_kit::RegistryAdminCap`,\n\t\t'u64',\n\t] satisfies string[];\n\tconst parameterNames = ['registry', 'cap', 'epochExpirationDuration'];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'payment_kit',\n\t\t\tfunction: 'set_config_epoch_expiration_duration',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),\n\t\t});\n}\nexport interface SetConfigRegistryManagedFundsArguments {\n\tregistry: RawTransactionArgument<string>;\n\tcap: RawTransactionArgument<string>;\n\tregistryManagedFunds: RawTransactionArgument<boolean>;\n}\nexport interface SetConfigRegistryManagedFundsOptions {\n\tpackage?: string;\n\targuments:\n\t\t| SetConfigRegistryManagedFundsArguments\n\t\t| [\n\t\t\t\tregistry: RawTransactionArgument<string>,\n\t\t\t\tcap: RawTransactionArgument<string>,\n\t\t\t\tregistryManagedFunds: RawTransactionArgument<boolean>,\n\t\t ];\n}\n/**\n * Sets whether the registry should manage funds itself. If true, payments\n * processed via the registry will be collected into the registry's balance. If\n * false, payments will be transferred directly to the specified receiver.\n */\nexport function setConfigRegistryManagedFunds(options: SetConfigRegistryManagedFundsOptions) {\n\tconst packageAddress = options.package ?? '@haneullabs/payment-kit';\n\tconst argumentsTypes = [\n\t\t`${packageAddress}::payment_kit::PaymentRegistry`,\n\t\t`${packageAddress}::payment_kit::RegistryAdminCap`,\n\t\t'bool',\n\t] satisfies string[];\n\tconst parameterNames = ['registry', 'cap', 'registryManagedFunds'];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'payment_kit',\n\t\t\tfunction: 'set_config_registry_managed_funds',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),\n\t\t});\n}\nexport interface ShareArguments {\n\tregistry: RawTransactionArgument<string>;\n}\nexport interface ShareOptions {\n\tpackage?: string;\n\targuments: ShareArguments | [registry: RawTransactionArgument<string>];\n}\n/**\n * Enforce that a registry will always be shared.\n *\n * # Parameters\n *\n * - `registry` - The PaymentRegistry to share\n */\nexport function share(options: ShareOptions) {\n\tconst packageAddress = options.package ?? '@haneullabs/payment-kit';\n\tconst argumentsTypes = [`${packageAddress}::payment_kit::PaymentRegistry`] satisfies string[];\n\tconst parameterNames = ['registry'];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'payment_kit',\n\t\t\tfunction: 'share',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),\n\t\t});\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,YAAY,UAAU,WAAW,8BAA8B;AAExE,SAAS,WAAW;AAEpB,YAAY,YAAY;AACxB,YAAY,aAAa;AACzB,YAAY,YAAY;AACxB,MAAM,cAAc;AACb,MAAM,YAAY,IAAI,WAAW;AAAA,EACvC,MAAM,GAAG,WAAW;AAAA,EACpB,QAAQ;AAAA,IACP,IAAI,OAAO;AAAA,EACZ;AACD,CAAC;AACM,MAAM,kBAAkB,IAAI,WAAW;AAAA,EAC7C,MAAM,GAAG,WAAW;AAAA,EACpB,QAAQ;AAAA,IACP,IAAI,OAAO;AAAA,IACX,QAAQ,IAAI;AAAA,IACZ,QAAQ,QAAQ,OAAO,IAAI,OAAO,GAAG,OAAO,KAAK;AAAA,IACjD,SAAS,IAAI,IAAI;AAAA,EAClB;AACD,CAAC;AACM,MAAM,mBAAmB,IAAI,WAAW;AAAA,EAC9C,MAAM,GAAG,WAAW;AAAA,EACpB,QAAQ;AAAA,IACP,IAAI,OA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,IACtB,GAAG,cAAc;AAAA,IACjB,GAAG,cAAc;AAAA,IACjB;AAAA,EACD;AACA,QAAM,iBAAiB,CAAC,YAAY,OAAO,sBAAsB;AACjE,SAAO,CAAC,OACP,GAAG,SAAS;AAAA,IACX,SAAS;AAAA,IACT,QAAQ;AAAA,IACR,UAAU;AAAA,IACV,WAAW,uBAAuB,QAAQ,WAAW,gBAAgB,cAAc;AAAA,EACpF,CAAC;AACH;AAeO,SAAS,MAAM,SAAuB;AAC5C,QAAM,iBAAiB,QAAQ,WAAW;AAC1C,QAAM,iBAAiB,CAAC,GAAG,cAAc,gCAAgC;AACzE,QAAM,iBAAiB,CAAC,UAAU;AAClC,SAAO,CAAC,OACP,GAAG,SAAS;AAAA,IACX,SAAS;AAAA,IACT,QAAQ;AAAA,IACR,UAAU;AAAA,IACV,WAAW,uBAAuB,QAAQ,WAAW,gBAAgB,cAAc;AAAA,EACpF,CAAC;AACH;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { BcsType, TypeTag } from '@haneullabs/haneul/bcs';
|
|
2
|
+
import { BcsStruct, BcsEnum, BcsTuple } from '@haneullabs/haneul/bcs';
|
|
3
|
+
import type { TransactionArgument } from '@haneullabs/haneul/transactions';
|
|
4
|
+
export type RawTransactionArgument<T> = T | TransactionArgument;
|
|
5
|
+
export declare function getPureBcsSchema(typeTag: string | TypeTag): BcsType<any> | null;
|
|
6
|
+
export declare function normalizeMoveArguments(args: unknown[] | object, argTypes: string[], parameterNames?: string[]): TransactionArgument[];
|
|
7
|
+
export declare class MoveStruct<T extends Record<string, BcsType<any>>, const Name extends string = string> extends BcsStruct<T, Name> {
|
|
8
|
+
}
|
|
9
|
+
export declare class MoveEnum<T extends Record<string, BcsType<any> | null>, const Name extends string> extends BcsEnum<T, Name> {
|
|
10
|
+
}
|
|
11
|
+
export declare class MoveTuple<T extends readonly BcsType<any>[], const Name extends string> extends BcsTuple<T, Name> {
|
|
12
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { bcs, TypeTagSerializer, BcsStruct, BcsEnum, BcsTuple } from "@haneullabs/haneul/bcs";
|
|
2
|
+
import { normalizeHaneulAddress } from "@haneullabs/haneul/utils";
|
|
3
|
+
import { isArgument } from "@haneullabs/haneul/transactions";
|
|
4
|
+
const MOVE_STDLIB_ADDRESS = normalizeHaneulAddress("0x1");
|
|
5
|
+
const HANEUL_FRAMEWORK_ADDRESS = normalizeHaneulAddress("0x2");
|
|
6
|
+
const HANEUL_SYSTEM_ADDRESS = normalizeHaneulAddress("0x3");
|
|
7
|
+
function getPureBcsSchema(typeTag) {
|
|
8
|
+
const parsedTag = typeof typeTag === "string" ? TypeTagSerializer.parseFromStr(typeTag) : typeTag;
|
|
9
|
+
if ("u8" in parsedTag) {
|
|
10
|
+
return bcs.U8;
|
|
11
|
+
} else if ("u16" in parsedTag) {
|
|
12
|
+
return bcs.U16;
|
|
13
|
+
} else if ("u32" in parsedTag) {
|
|
14
|
+
return bcs.U32;
|
|
15
|
+
} else if ("u64" in parsedTag) {
|
|
16
|
+
return bcs.U64;
|
|
17
|
+
} else if ("u128" in parsedTag) {
|
|
18
|
+
return bcs.U128;
|
|
19
|
+
} else if ("u256" in parsedTag) {
|
|
20
|
+
return bcs.U256;
|
|
21
|
+
} else if ("address" in parsedTag) {
|
|
22
|
+
return bcs.Address;
|
|
23
|
+
} else if ("bool" in parsedTag) {
|
|
24
|
+
return bcs.Bool;
|
|
25
|
+
} else if ("vector" in parsedTag) {
|
|
26
|
+
const type = getPureBcsSchema(parsedTag.vector);
|
|
27
|
+
return type ? bcs.vector(type) : null;
|
|
28
|
+
} else if ("struct" in parsedTag) {
|
|
29
|
+
const structTag = parsedTag.struct;
|
|
30
|
+
const pkg = normalizeHaneulAddress(parsedTag.struct.address);
|
|
31
|
+
if (pkg === MOVE_STDLIB_ADDRESS) {
|
|
32
|
+
if ((structTag.module === "ascii" || structTag.module === "string") && structTag.name === "String") {
|
|
33
|
+
return bcs.String;
|
|
34
|
+
}
|
|
35
|
+
if (structTag.module === "option" && structTag.name === "Option") {
|
|
36
|
+
const type = getPureBcsSchema(structTag.typeParams[0]);
|
|
37
|
+
return type ? bcs.option(type) : null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (pkg === HANEUL_FRAMEWORK_ADDRESS && structTag.module === "Object" && structTag.name === "ID") {
|
|
41
|
+
return bcs.Address;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
function normalizeMoveArguments(args, argTypes, parameterNames) {
|
|
47
|
+
const argLen = Array.isArray(args) ? args.length : Object.keys(args).length;
|
|
48
|
+
if (parameterNames && argLen !== parameterNames.length) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
`Invalid number of arguments, expected ${parameterNames.length}, got ${argLen}`
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
const normalizedArgs = [];
|
|
54
|
+
let index = 0;
|
|
55
|
+
for (const [i, argType] of argTypes.entries()) {
|
|
56
|
+
if (argType === `${HANEUL_FRAMEWORK_ADDRESS}::deny_list::DenyList`) {
|
|
57
|
+
normalizedArgs.push((tx) => tx.object.denyList());
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (argType === `${HANEUL_FRAMEWORK_ADDRESS}::random::Random`) {
|
|
61
|
+
normalizedArgs.push((tx) => tx.object.random());
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (argType === `${HANEUL_FRAMEWORK_ADDRESS}::clock::Clock`) {
|
|
65
|
+
normalizedArgs.push((tx) => tx.object.clock());
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (argType === `${HANEUL_SYSTEM_ADDRESS}::haneul_system::HaneulSystemState`) {
|
|
69
|
+
normalizedArgs.push((tx) => tx.object.system());
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
let arg;
|
|
73
|
+
if (Array.isArray(args)) {
|
|
74
|
+
if (index >= args.length) {
|
|
75
|
+
throw new Error(
|
|
76
|
+
`Invalid number of arguments, expected at least ${index + 1}, got ${args.length}`
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
arg = args[index];
|
|
80
|
+
} else {
|
|
81
|
+
if (!parameterNames) {
|
|
82
|
+
throw new Error(`Expected arguments to be passed as an array`);
|
|
83
|
+
}
|
|
84
|
+
const name = parameterNames[index];
|
|
85
|
+
arg = args[name];
|
|
86
|
+
if (arg == null) {
|
|
87
|
+
throw new Error(`Parameter ${name} is required`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
index += 1;
|
|
91
|
+
if (typeof arg === "function" || isArgument(arg)) {
|
|
92
|
+
normalizedArgs.push(arg);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const type = argTypes[i];
|
|
96
|
+
const bcsType = getPureBcsSchema(type);
|
|
97
|
+
if (bcsType) {
|
|
98
|
+
const bytes = bcsType.serialize(arg);
|
|
99
|
+
normalizedArgs.push((tx) => tx.pure(bytes));
|
|
100
|
+
continue;
|
|
101
|
+
} else if (typeof arg === "string") {
|
|
102
|
+
normalizedArgs.push((tx) => tx.object(arg));
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
throw new Error(`Invalid argument ${stringify(arg)} for type ${type}`);
|
|
106
|
+
}
|
|
107
|
+
return normalizedArgs;
|
|
108
|
+
}
|
|
109
|
+
class MoveStruct extends BcsStruct {
|
|
110
|
+
}
|
|
111
|
+
class MoveEnum extends BcsEnum {
|
|
112
|
+
}
|
|
113
|
+
class MoveTuple extends BcsTuple {
|
|
114
|
+
}
|
|
115
|
+
function stringify(val) {
|
|
116
|
+
if (typeof val === "object") {
|
|
117
|
+
return JSON.stringify(val, (val2) => val2);
|
|
118
|
+
}
|
|
119
|
+
if (typeof val === "bigint") {
|
|
120
|
+
return val.toString();
|
|
121
|
+
}
|
|
122
|
+
return val;
|
|
123
|
+
}
|
|
124
|
+
export {
|
|
125
|
+
MoveEnum,
|
|
126
|
+
MoveStruct,
|
|
127
|
+
MoveTuple,
|
|
128
|
+
getPureBcsSchema,
|
|
129
|
+
normalizeMoveArguments
|
|
130
|
+
};
|
|
131
|
+
//# sourceMappingURL=index.js.map
|