@ocap/state 1.28.9 → 1.29.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/esm/_virtual/rolldown_runtime.mjs +18 -0
- package/esm/contexts/state.d.mts +15 -0
- package/esm/contexts/state.mjs +17 -0
- package/esm/index.d.mts +20 -0
- package/esm/index.mjs +47 -0
- package/esm/states/account.d.mts +18 -0
- package/esm/states/account.mjs +91 -0
- package/esm/states/asset.d.mts +14 -0
- package/esm/states/asset.mjs +80 -0
- package/esm/states/blacklist.d.mts +36 -0
- package/esm/states/blacklist.mjs +71 -0
- package/esm/states/chain.d.mts +30 -0
- package/esm/states/chain.mjs +52 -0
- package/esm/states/delegation.d.mts +11 -0
- package/esm/states/delegation.mjs +42 -0
- package/esm/states/evidence.d.mts +12 -0
- package/esm/states/evidence.mjs +35 -0
- package/esm/states/factory.d.mts +12 -0
- package/esm/states/factory.mjs +76 -0
- package/esm/states/rollup-block.d.mts +13 -0
- package/esm/states/rollup-block.mjs +75 -0
- package/esm/states/rollup.d.mts +18 -0
- package/esm/states/rollup.mjs +215 -0
- package/esm/states/stake.d.mts +13 -0
- package/esm/states/stake.mjs +89 -0
- package/esm/states/token-factory.d.mts +13 -0
- package/esm/states/token-factory.mjs +76 -0
- package/esm/states/token.d.mts +14 -0
- package/esm/states/token.mjs +109 -0
- package/esm/states/tx.d.mts +233 -0
- package/esm/states/tx.mjs +867 -0
- package/esm/util.d.mts +6 -0
- package/esm/util.mjs +18 -0
- package/lib/_virtual/rolldown_runtime.cjs +43 -0
- package/lib/contexts/state.cjs +19 -0
- package/lib/contexts/state.d.cts +15 -0
- package/lib/index.cjs +121 -0
- package/lib/index.d.cts +20 -0
- package/lib/states/account.cjs +106 -0
- package/lib/states/account.d.cts +18 -0
- package/lib/states/asset.cjs +91 -0
- package/lib/states/asset.d.cts +14 -0
- package/lib/states/blacklist.cjs +74 -0
- package/lib/states/blacklist.d.cts +36 -0
- package/lib/states/chain.cjs +62 -0
- package/lib/states/chain.d.cts +30 -0
- package/lib/states/delegation.cjs +50 -0
- package/lib/states/delegation.d.cts +11 -0
- package/lib/states/evidence.cjs +44 -0
- package/lib/states/evidence.d.cts +12 -0
- package/lib/states/factory.cjs +85 -0
- package/lib/states/factory.d.cts +12 -0
- package/lib/states/rollup-block.cjs +85 -0
- package/lib/states/rollup-block.d.cts +13 -0
- package/lib/states/rollup.cjs +230 -0
- package/lib/states/rollup.d.cts +18 -0
- package/lib/states/stake.cjs +99 -0
- package/lib/states/stake.d.cts +13 -0
- package/lib/states/token-factory.cjs +86 -0
- package/lib/states/token-factory.d.cts +13 -0
- package/lib/states/token.cjs +121 -0
- package/lib/states/token.d.cts +14 -0
- package/lib/states/tx.cjs +889 -0
- package/lib/states/tx.d.cts +233 -0
- package/lib/util.cjs +19 -0
- package/lib/util.d.cts +6 -0
- package/package.json +46 -14
- package/lib/contexts/state.js +0 -19
- package/lib/index.js +0 -63
- package/lib/states/account.js +0 -95
- package/lib/states/asset.js +0 -91
- package/lib/states/blacklist.js +0 -103
- package/lib/states/chain.js +0 -49
- package/lib/states/delegation.js +0 -46
- package/lib/states/evidence.js +0 -35
- package/lib/states/factory.js +0 -92
- package/lib/states/rollup-block.js +0 -84
- package/lib/states/rollup.js +0 -297
- package/lib/states/stake.js +0 -83
- package/lib/states/token-factory.js +0 -74
- package/lib/states/token.js +0 -124
- package/lib/states/tx.js +0 -896
- package/lib/util.js +0 -28
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { __exportAll } from "../_virtual/rolldown_runtime.mjs";
|
|
2
|
+
import { create as create$1 } from "../contexts/state.mjs";
|
|
3
|
+
import { toChecksumAddress } from "@arcblock/did/lib/type";
|
|
4
|
+
import { BN, toAddress } from "@ocap/util";
|
|
5
|
+
import pick from "lodash/pick.js";
|
|
6
|
+
import { Joi, schemas } from "@arcblock/validator";
|
|
7
|
+
import cloneDeep from "lodash/cloneDeep.js";
|
|
8
|
+
|
|
9
|
+
//#region src/states/token.ts
|
|
10
|
+
var token_exports = /* @__PURE__ */ __exportAll({
|
|
11
|
+
create: () => create,
|
|
12
|
+
metadataSchema: () => metadataSchema,
|
|
13
|
+
stateSchema: () => stateSchema,
|
|
14
|
+
update: () => update,
|
|
15
|
+
validate: () => validate
|
|
16
|
+
});
|
|
17
|
+
const isTest = process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test" || process.env.CI;
|
|
18
|
+
const metadataSchema = Joi.object({
|
|
19
|
+
communityUrl: Joi.string().uri({
|
|
20
|
+
scheme: ["https"],
|
|
21
|
+
allowRelative: false
|
|
22
|
+
}).max(256).optional().allow(null, ""),
|
|
23
|
+
issuer: Joi.string().max(64).required()
|
|
24
|
+
}).options({
|
|
25
|
+
stripUnknown: true,
|
|
26
|
+
noDefaults: false
|
|
27
|
+
});
|
|
28
|
+
const stateSchema = Joi.object({
|
|
29
|
+
address: Joi.DID().prefix().role("ROLE_TOKEN").required(),
|
|
30
|
+
name: Joi.string().min(1).max(32).required(),
|
|
31
|
+
description: Joi.string().min(16).max(128).required(),
|
|
32
|
+
symbol: Joi.string().min(2).max(6).uppercase().required(),
|
|
33
|
+
unit: Joi.string().min(1).max(6).lowercase().required(),
|
|
34
|
+
decimal: Joi.number().min(2).max(18).required(),
|
|
35
|
+
icon: Joi.string().optional().allow(null, ""),
|
|
36
|
+
totalSupply: Joi.BN().min(0).required(),
|
|
37
|
+
initialSupply: Joi.BN().min(0).required(),
|
|
38
|
+
maxTotalSupply: Joi.alternatives().try(Joi.BN().greater(0), Joi.string().valid("")).optional().allow(null),
|
|
39
|
+
foreignToken: schemas.foreignToken.optional().allow(null),
|
|
40
|
+
issuer: Joi.DID().prefix().optional().allow(null, ""),
|
|
41
|
+
website: Joi.string().uri({
|
|
42
|
+
scheme: isTest ? ["http", "https"] : ["https"],
|
|
43
|
+
allowRelative: false
|
|
44
|
+
}).max(256).optional().allow(null, ""),
|
|
45
|
+
metadata: Joi.object({
|
|
46
|
+
type: Joi.string().valid("json").required(),
|
|
47
|
+
value: metadataSchema.optional()
|
|
48
|
+
}).optional().allow(null),
|
|
49
|
+
tokenFactoryAddress: Joi.DID().prefix().role("ROLE_TOKEN_FACTORY").optional().allow(null, ""),
|
|
50
|
+
spenders: Joi.array().items(Joi.DID().prefix()).max(30).optional().allow(null),
|
|
51
|
+
minters: Joi.array().items(Joi.DID().prefix()).max(30).optional().allow(null),
|
|
52
|
+
type: Joi.string().valid("Token", "CreditToken", "BondingCurveToken").optional().allow(null, ""),
|
|
53
|
+
context: schemas.context,
|
|
54
|
+
data: Joi.any().optional().allow(null)
|
|
55
|
+
}).options({
|
|
56
|
+
stripUnknown: true,
|
|
57
|
+
noDefaults: false
|
|
58
|
+
});
|
|
59
|
+
const create = (attrs, context) => {
|
|
60
|
+
const token = {
|
|
61
|
+
context: create$1(context),
|
|
62
|
+
...pick(attrs, [
|
|
63
|
+
"name",
|
|
64
|
+
"description",
|
|
65
|
+
"symbol",
|
|
66
|
+
"unit",
|
|
67
|
+
"decimal",
|
|
68
|
+
"icon",
|
|
69
|
+
"totalSupply",
|
|
70
|
+
"initialSupply",
|
|
71
|
+
"maxTotalSupply",
|
|
72
|
+
"address",
|
|
73
|
+
"foreignToken",
|
|
74
|
+
"data",
|
|
75
|
+
"issuer",
|
|
76
|
+
"website",
|
|
77
|
+
"metadata",
|
|
78
|
+
"tokenFactoryAddress",
|
|
79
|
+
"spenders",
|
|
80
|
+
"minters",
|
|
81
|
+
"type"
|
|
82
|
+
])
|
|
83
|
+
};
|
|
84
|
+
if (!token.data) token.data = null;
|
|
85
|
+
if (!token.metadata) token.metadata = null;
|
|
86
|
+
if (!token.foreignToken) token.foreignToken = null;
|
|
87
|
+
else token.foreignToken.contractAddress = toChecksumAddress(token.foreignToken.contractAddress);
|
|
88
|
+
token.address = toAddress(token.address);
|
|
89
|
+
return validate(token);
|
|
90
|
+
};
|
|
91
|
+
const update = (state, attrs) => validate({
|
|
92
|
+
...state,
|
|
93
|
+
...pick(attrs, [
|
|
94
|
+
"totalSupply",
|
|
95
|
+
"metadata",
|
|
96
|
+
"icon",
|
|
97
|
+
"website"
|
|
98
|
+
])
|
|
99
|
+
});
|
|
100
|
+
const validate = (state) => {
|
|
101
|
+
if (state.maxTotalSupply && new BN(state.maxTotalSupply).lt(new BN(state.totalSupply))) throw new Error("maxTotalSupply must be greater than or equal to totalSupply");
|
|
102
|
+
const data = cloneDeep(state);
|
|
103
|
+
const { value, error } = stateSchema.validate(data);
|
|
104
|
+
if (error) throw new Error(`Invalid token state: ${error.message}`);
|
|
105
|
+
return value;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
//#endregion
|
|
109
|
+
export { create, metadataSchema, stateSchema, token_exports, update, validate };
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
declare namespace tx_d_exports {
|
|
2
|
+
export { FORGE_TOKEN_HOLDER, ItxJson, Receipt, ReceiptChange, TokenInput, TxContext, TxData, TxInput, TxOutput, TxResult, attachPaidTxGas, create, eachReceipts, getTxReceipts, getTxReceiver, getTxSender, groupReceiptTokenChanges, mergeTxReceipts, update, verifyTxReceipts };
|
|
3
|
+
}
|
|
4
|
+
declare const FORGE_TOKEN_HOLDER = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
|
|
5
|
+
interface ReceiptChange {
|
|
6
|
+
target: string;
|
|
7
|
+
action: string;
|
|
8
|
+
value: string;
|
|
9
|
+
}
|
|
10
|
+
interface Receipt {
|
|
11
|
+
address: string;
|
|
12
|
+
changes: ReceiptChange[];
|
|
13
|
+
}
|
|
14
|
+
interface TokenInput {
|
|
15
|
+
address: string;
|
|
16
|
+
value: string;
|
|
17
|
+
}
|
|
18
|
+
interface TxInput {
|
|
19
|
+
owner: string;
|
|
20
|
+
tokens?: TokenInput[];
|
|
21
|
+
assets?: string[];
|
|
22
|
+
}
|
|
23
|
+
interface TxOutput {
|
|
24
|
+
owner: string;
|
|
25
|
+
tokens?: TokenInput[];
|
|
26
|
+
assets?: string[];
|
|
27
|
+
}
|
|
28
|
+
interface ItxJson {
|
|
29
|
+
_type?: string;
|
|
30
|
+
to?: string;
|
|
31
|
+
owner?: string;
|
|
32
|
+
address?: string;
|
|
33
|
+
receiver?: string;
|
|
34
|
+
value?: string;
|
|
35
|
+
tokens?: TokenInput[];
|
|
36
|
+
assets?: string[];
|
|
37
|
+
sender?: {
|
|
38
|
+
value?: string;
|
|
39
|
+
tokens?: TokenInput[];
|
|
40
|
+
assets?: string[];
|
|
41
|
+
};
|
|
42
|
+
inputs?: TxInput[];
|
|
43
|
+
outputs?: TxOutput[];
|
|
44
|
+
initialSupply?: string;
|
|
45
|
+
amount?: string;
|
|
46
|
+
issuer?: string;
|
|
47
|
+
withdraw_tx_hash?: string;
|
|
48
|
+
[key: string]: unknown;
|
|
49
|
+
}
|
|
50
|
+
interface TxData {
|
|
51
|
+
from: string;
|
|
52
|
+
delegator?: string;
|
|
53
|
+
itxJson: ItxJson;
|
|
54
|
+
chainId?: string;
|
|
55
|
+
nonce?: number;
|
|
56
|
+
serviceFee?: string;
|
|
57
|
+
pk?: Uint8Array;
|
|
58
|
+
signature?: Uint8Array;
|
|
59
|
+
signatures?: unknown[];
|
|
60
|
+
itx?: {
|
|
61
|
+
typeUrl: string;
|
|
62
|
+
value?: Uint8Array;
|
|
63
|
+
};
|
|
64
|
+
gasPaid?: string;
|
|
65
|
+
gasFee?: string;
|
|
66
|
+
}
|
|
67
|
+
interface TxContext {
|
|
68
|
+
txHash?: string;
|
|
69
|
+
txTime?: string;
|
|
70
|
+
tx?: TxData;
|
|
71
|
+
totalGas?: unknown;
|
|
72
|
+
itxExtras?: Record<string, unknown>;
|
|
73
|
+
extra?: {
|
|
74
|
+
txExtra?: unknown;
|
|
75
|
+
};
|
|
76
|
+
senderState?: {
|
|
77
|
+
address?: string;
|
|
78
|
+
tokens?: Record<string, string>;
|
|
79
|
+
};
|
|
80
|
+
receiverState?: {
|
|
81
|
+
address?: string;
|
|
82
|
+
};
|
|
83
|
+
fromState?: {
|
|
84
|
+
address?: string;
|
|
85
|
+
tokens?: Record<string, string>;
|
|
86
|
+
};
|
|
87
|
+
factoryState?: {
|
|
88
|
+
input?: {
|
|
89
|
+
value?: string;
|
|
90
|
+
tokens?: TokenInput[];
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
ownerAddress?: string;
|
|
94
|
+
config?: {
|
|
95
|
+
token?: {
|
|
96
|
+
address?: string;
|
|
97
|
+
decimal?: number;
|
|
98
|
+
};
|
|
99
|
+
vaults?: {
|
|
100
|
+
txGas?: string[];
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
time?: string;
|
|
104
|
+
receipts?: Receipt[];
|
|
105
|
+
gasPaid?: boolean;
|
|
106
|
+
outputs?: TxOutput[];
|
|
107
|
+
withdrawTx?: {
|
|
108
|
+
hash?: string;
|
|
109
|
+
tx?: TxData;
|
|
110
|
+
receipts?: Receipt[];
|
|
111
|
+
};
|
|
112
|
+
updatedAccounts?: Array<{
|
|
113
|
+
address?: string;
|
|
114
|
+
delta?: string;
|
|
115
|
+
token?: string;
|
|
116
|
+
action?: string;
|
|
117
|
+
}>;
|
|
118
|
+
inputChanges?: Array<{
|
|
119
|
+
address: string;
|
|
120
|
+
delta: string;
|
|
121
|
+
}>;
|
|
122
|
+
tokenFactoryState?: {
|
|
123
|
+
reserveAddress: string;
|
|
124
|
+
tokenAddress: string;
|
|
125
|
+
owner: string;
|
|
126
|
+
};
|
|
127
|
+
reserveFee?: string;
|
|
128
|
+
reserveAmount?: string;
|
|
129
|
+
[key: string]: unknown;
|
|
130
|
+
}
|
|
131
|
+
interface TxResult {
|
|
132
|
+
code: string;
|
|
133
|
+
hash?: string;
|
|
134
|
+
height: number;
|
|
135
|
+
index: number;
|
|
136
|
+
time?: string;
|
|
137
|
+
sender: string;
|
|
138
|
+
receiver: string;
|
|
139
|
+
type: string;
|
|
140
|
+
tx: {
|
|
141
|
+
chainId?: string;
|
|
142
|
+
delegator?: string;
|
|
143
|
+
from?: string;
|
|
144
|
+
nonce?: number;
|
|
145
|
+
serviceFee: string;
|
|
146
|
+
gasFee: string;
|
|
147
|
+
gasPaid?: string;
|
|
148
|
+
pk?: string;
|
|
149
|
+
signature?: string;
|
|
150
|
+
signatures?: unknown[];
|
|
151
|
+
itx?: {
|
|
152
|
+
__typename: string;
|
|
153
|
+
};
|
|
154
|
+
itxJson?: Record<string, unknown>;
|
|
155
|
+
extra?: unknown;
|
|
156
|
+
};
|
|
157
|
+
receipts?: Receipt[];
|
|
158
|
+
receiptsVerified?: boolean;
|
|
159
|
+
finalized?: boolean;
|
|
160
|
+
}
|
|
161
|
+
type EachReceiptsCallback = (address: string, change: ReceiptChange) => unknown;
|
|
162
|
+
declare function eachReceipts(receipts: Receipt[] | undefined, callback: EachReceiptsCallback): unknown[];
|
|
163
|
+
declare function groupReceiptTokenChanges(receipts: Receipt[] | undefined): Record<string, Record<string, string>>;
|
|
164
|
+
interface GetTxReceiverArgs {
|
|
165
|
+
tx?: TxData;
|
|
166
|
+
itx?: ItxJson;
|
|
167
|
+
typeUrl: string;
|
|
168
|
+
}
|
|
169
|
+
declare const getTxReceiver: ({
|
|
170
|
+
tx,
|
|
171
|
+
itx,
|
|
172
|
+
typeUrl
|
|
173
|
+
}: GetTxReceiverArgs) => string;
|
|
174
|
+
interface GetTxSenderArgs {
|
|
175
|
+
tx: TxData;
|
|
176
|
+
itx?: ItxJson;
|
|
177
|
+
typeUrl: string;
|
|
178
|
+
}
|
|
179
|
+
declare const getTxSender: ({
|
|
180
|
+
tx,
|
|
181
|
+
typeUrl
|
|
182
|
+
}: GetTxSenderArgs) => string;
|
|
183
|
+
declare const mergeTxReceipts: (receipts: Receipt[]) => Receipt[];
|
|
184
|
+
/**
|
|
185
|
+
* Verify transaction receipts
|
|
186
|
+
*/
|
|
187
|
+
declare const verifyTxReceipts: (receipts: Receipt[], typeUrl: string, ctx?: TxContext) => boolean;
|
|
188
|
+
interface GetTxReceiptsInput {
|
|
189
|
+
tx: TxData;
|
|
190
|
+
code: string;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Create transaction receipts, each receipt has following properties:
|
|
194
|
+
*
|
|
195
|
+
* - address: the entity did that changed
|
|
196
|
+
* - changes:
|
|
197
|
+
* - target: the target address that was changed, can be token address, asset address
|
|
198
|
+
* - action: why the target has changed, such as consume, burn and transfer
|
|
199
|
+
* - value: the amount that has changed
|
|
200
|
+
*/
|
|
201
|
+
declare const getTxReceipts: ({
|
|
202
|
+
tx,
|
|
203
|
+
code
|
|
204
|
+
}: GetTxReceiptsInput, ctx?: TxContext) => Receipt[];
|
|
205
|
+
interface CreateContext extends TxContext {
|
|
206
|
+
txHash: string;
|
|
207
|
+
txTime: string;
|
|
208
|
+
tx: {
|
|
209
|
+
chainId?: string;
|
|
210
|
+
delegator?: string;
|
|
211
|
+
from: string;
|
|
212
|
+
nonce?: number;
|
|
213
|
+
serviceFee?: string;
|
|
214
|
+
pk?: Uint8Array;
|
|
215
|
+
signature?: Uint8Array;
|
|
216
|
+
signatures?: unknown[];
|
|
217
|
+
itx: {
|
|
218
|
+
typeUrl: string;
|
|
219
|
+
value?: Uint8Array;
|
|
220
|
+
};
|
|
221
|
+
itxJson: ItxJson;
|
|
222
|
+
};
|
|
223
|
+
totalGas?: unknown;
|
|
224
|
+
itxExtras?: Record<string, unknown>;
|
|
225
|
+
extra?: {
|
|
226
|
+
txExtra?: unknown;
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
declare const create: (context: CreateContext, code?: string, verifyReceipts?: boolean) => TxResult;
|
|
230
|
+
declare const attachPaidTxGas: (tx: TxResult) => TxResult;
|
|
231
|
+
declare const update: (state: TxResult, updates: Partial<TxResult>) => TxResult;
|
|
232
|
+
//#endregion
|
|
233
|
+
export { FORGE_TOKEN_HOLDER, ItxJson, Receipt, ReceiptChange, TokenInput, TxContext, TxData, TxInput, TxOutput, TxResult, attachPaidTxGas, create, eachReceipts, getTxReceipts, getTxReceiver, getTxSender, groupReceiptTokenChanges, mergeTxReceipts, tx_d_exports, update, verifyTxReceipts };
|