@sparkdreamnft/sparkdreamjs 0.0.39 → 0.0.41

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.
@@ -1,4 +1,5 @@
1
1
  import { MsgUpdateParams, MsgUpdateOperationalParams, MsgCreateSession, MsgRevokeSession } from "./tx";
2
+ import { Coin } from "../../../cosmos/base/v1beta1/coin";
2
3
  export declare const AminoConverter: {
3
4
  "/sparkdream.session.v1.MsgUpdateParams": {
4
5
  aminoType: string;
@@ -25,4 +26,68 @@ export declare const AminoConverter: {
25
26
  toAmino(message: any): any;
26
27
  fromAmino(object: any): any;
27
28
  };
29
+ "/sparkdream.session.v1.MsgCreateGrant": {
30
+ aminoType: string;
31
+ toAmino(message: any): any;
32
+ fromAmino(object: any): any;
33
+ };
34
+ "/sparkdream.session.v1.MsgClaimRecurringPull": {
35
+ toAmino: (m: any) => {
36
+ [x: string]: any;
37
+ grant_id: string;
38
+ };
39
+ fromAmino: (o: any) => {
40
+ [x: string]: any;
41
+ grantId: bigint;
42
+ };
43
+ aminoType: string;
44
+ };
45
+ "/sparkdream.session.v1.MsgPullAllowance": {
46
+ aminoType: string;
47
+ toAmino: (m: any) => {
48
+ grantee: any;
49
+ grant_id: string;
50
+ recipient: any;
51
+ amount: import("../../../cosmos/base/v1beta1/coin").CoinAmino;
52
+ };
53
+ fromAmino: (o: any) => {
54
+ grantee: any;
55
+ grantId: bigint;
56
+ recipient: any;
57
+ amount: Coin;
58
+ };
59
+ };
60
+ "/sparkdream.session.v1.MsgRetryScheduledOneshot": {
61
+ toAmino: (m: any) => {
62
+ [x: string]: any;
63
+ grant_id: string;
64
+ };
65
+ fromAmino: (o: any) => {
66
+ [x: string]: any;
67
+ grantId: bigint;
68
+ };
69
+ aminoType: string;
70
+ };
71
+ "/sparkdream.session.v1.MsgRevokeGrant": {
72
+ toAmino: (m: any) => {
73
+ [x: string]: any;
74
+ grant_id: string;
75
+ };
76
+ fromAmino: (o: any) => {
77
+ [x: string]: any;
78
+ grantId: bigint;
79
+ };
80
+ aminoType: string;
81
+ };
82
+ "/sparkdream.session.v1.MsgDeclineGrant": {
83
+ toAmino: (m: any) => {
84
+ [x: string]: any;
85
+ grant_id: string;
86
+ };
87
+ fromAmino: (o: any) => {
88
+ [x: string]: any;
89
+ grantId: bigint;
90
+ };
91
+ aminoType: string;
92
+ };
28
93
  };
@@ -3,8 +3,33 @@
3
3
  // HAND-WRITTEN OVERRIDE — overlaid by scripts/codegen.ts after telescope.
4
4
  // See ../../commons/v1/tx.amino.ts for rationale.
5
5
  //
6
- // MsgExecSession has `repeated google.protobuf.Any msgs = 3` (note the
7
- // shorter field name `msgs`, not `messages`). Same recursive-Any problem.
6
+ // Because this file replaces the generated one wholesale, EVERY Msg in
7
+ // session/v1/tx.proto must have an entry here — a message added to the proto
8
+ // but not to this map ships in the registry with no amino converter, and
9
+ // Keplr/Ledger (amino-json) signing of it fails.
10
+ //
11
+ // Three shapes telescope gets wrong for this module:
12
+ //
13
+ // 1. MsgExecSession / OneshotExec carry google.protobuf.Any, which needs the
14
+ // recursive conversion in ../../../nested-amino.
15
+ // 2. MsgCreateGrant.payload and ScheduledOneshotPayload.action are oneofs
16
+ // with (amino.oneof_name). cosmossdk.io/x/tx/signing/aminojson renders a
17
+ // set oneof member as
18
+ //
19
+ // "<CamelCase oneof name>": {"type": "<oneof_name>", "value": {"<field>": {...}}}
20
+ //
21
+ // e.g. "Payload": {"type": "sparkdream/session/RecurringPullPayload",
22
+ // "value": {"recurring_pull": {...}}}
23
+ //
24
+ // while telescope emits the bare member ("recurring_pull": {...}).
25
+ // 3. Repeated fields must be omitted when empty (omitempty), never `[]`.
26
+ //
27
+ // cosmjs rebuilds the TxBody from fromAmino(signed msgs), so each fromAmino
28
+ // below must exactly invert its toAmino.
29
+ //
30
+ // 64-bit ints are coerced here rather than trusting callers to pass BigInt:
31
+ // cosmjs hands toAmino the caller's raw value (no fromPartial), and a Number
32
+ // 0 would otherwise sign a key the chain omits.
8
33
  Object.defineProperty(exports, "__esModule", { value: true });
9
34
  exports.AminoConverter = void 0;
10
35
  const tx_1 = require("./tx");
@@ -12,6 +37,123 @@ const coin_1 = require("../../../cosmos/base/v1beta1/coin");
12
37
  const timestamp_1 = require("../../../google/protobuf/timestamp");
13
38
  const helpers_1 = require("../../../helpers");
14
39
  const nested_amino_1 = require("../../../nested-amino");
40
+ const str = (v) => (v === "" || v === undefined || v === null ? undefined : v);
41
+ const int64 = (v) => {
42
+ if (v === undefined || v === null || v === "")
43
+ return undefined;
44
+ const b = BigInt(v);
45
+ return b === BigInt(0) ? undefined : b.toString();
46
+ };
47
+ const bool = (v) => (v ? true : undefined);
48
+ const list = (v) => ((v?.length ?? 0) > 0 ? v.map((e) => e) : undefined);
49
+ const coin = (v) => (v ? coin_1.Coin.toAmino(coin_1.Coin.fromPartial(v)) : undefined);
50
+ const time = (v) => (v ? timestamp_1.Timestamp.toAmino((0, helpers_1.toTimestamp)(v)) : undefined);
51
+ const toBig = (v) => (v === undefined || v === null ? BigInt(0) : BigInt(v));
52
+ const fromCoin = (v) => (v ? coin_1.Coin.fromAmino(v) : undefined);
53
+ const fromTime = (v) => (v ? (0, helpers_1.fromTimestamp)(timestamp_1.Timestamp.fromAmino(v)) : undefined);
54
+ // ── Payloads ────────────────────────────────────────────────────────────
55
+ const sessionKeyToAmino = (p) => ({
56
+ allowed_msg_types: list(p.allowedMsgTypes),
57
+ spend_limit: coin(p.spendLimit),
58
+ spent: coin(p.spent),
59
+ max_exec_count: int64(p.maxExecCount),
60
+ exec_count: int64(p.execCount),
61
+ last_used_at: time(p.lastUsedAt),
62
+ allow_self_revoke: bool(p.allowSelfRevoke),
63
+ });
64
+ const sessionKeyFromAmino = (o) => ({
65
+ allowedMsgTypes: o.allowed_msg_types ?? [],
66
+ spendLimit: fromCoin(o.spend_limit),
67
+ spent: fromCoin(o.spent),
68
+ maxExecCount: toBig(o.max_exec_count),
69
+ execCount: toBig(o.exec_count),
70
+ lastUsedAt: fromTime(o.last_used_at),
71
+ allowSelfRevoke: o.allow_self_revoke ?? false,
72
+ });
73
+ const recurringPullToAmino = (p) => ({
74
+ amount_per_period: coin(p.amountPerPeriod),
75
+ period_seconds: int64(p.periodSeconds),
76
+ start_time: int64(p.startTime),
77
+ last_claim_advance: int64(p.lastClaimAdvance),
78
+ claims_made: int64(p.claimsMade),
79
+ max_per_epoch: str(p.maxPerEpoch),
80
+ });
81
+ const recurringPullFromAmino = (o) => ({
82
+ amountPerPeriod: fromCoin(o.amount_per_period),
83
+ periodSeconds: toBig(o.period_seconds),
84
+ startTime: toBig(o.start_time),
85
+ lastClaimAdvance: toBig(o.last_claim_advance),
86
+ claimsMade: toBig(o.claims_made),
87
+ maxPerEpoch: o.max_per_epoch ?? "",
88
+ });
89
+ const spendingAllowanceToAmino = (p) => ({
90
+ max_per_period: coin(p.maxPerPeriod),
91
+ period_seconds: int64(p.periodSeconds),
92
+ current_period_start: int64(p.currentPeriodStart),
93
+ spent_in_current_period: coin(p.spentInCurrentPeriod),
94
+ allowed_recipients: list(p.allowedRecipients),
95
+ denom: str(p.denom),
96
+ });
97
+ const spendingAllowanceFromAmino = (o) => ({
98
+ maxPerPeriod: fromCoin(o.max_per_period),
99
+ periodSeconds: toBig(o.period_seconds),
100
+ currentPeriodStart: toBig(o.current_period_start),
101
+ spentInCurrentPeriod: fromCoin(o.spent_in_current_period),
102
+ allowedRecipients: o.allowed_recipients ?? [],
103
+ denom: o.denom ?? "",
104
+ });
105
+ const scheduledOneshotToAmino = (p) => {
106
+ let action = undefined;
107
+ if (p.transfer) {
108
+ action = {
109
+ type: "sparkdream/session/OneshotTransfer",
110
+ value: { transfer: { recipient: str(p.transfer.recipient), amount: coin(p.transfer.amount) } },
111
+ };
112
+ }
113
+ else if (p.exec) {
114
+ action = {
115
+ type: "sparkdream/session/OneshotExec",
116
+ value: {
117
+ exec: {
118
+ msg: p.exec.msg ? (0, nested_amino_1.anyToAmino)(p.exec.msg) : undefined,
119
+ gas_limit: int64(p.exec.gasLimit),
120
+ },
121
+ },
122
+ };
123
+ }
124
+ return {
125
+ // aminojson writes `null` for an unset oneof rather than omitting it.
126
+ Action: action ?? null,
127
+ fire_at: int64(p.fireAt),
128
+ fire_error: str(p.fireError),
129
+ };
130
+ };
131
+ const scheduledOneshotFromAmino = (o) => {
132
+ const v = o.Action?.value ?? {};
133
+ return {
134
+ transfer: v.transfer
135
+ ? { recipient: v.transfer.recipient ?? "", amount: fromCoin(v.transfer.amount) }
136
+ : undefined,
137
+ exec: v.exec
138
+ ? { msg: v.exec.msg ? (0, nested_amino_1.aminoToAny)(v.exec.msg) : undefined, gasLimit: toBig(v.exec.gas_limit) }
139
+ : undefined,
140
+ fireAt: toBig(o.fire_at),
141
+ fireError: o.fire_error ?? "",
142
+ };
143
+ };
144
+ const PAYLOADS = [
145
+ ["sessionKey", "session_key", "sparkdream/session/SessionKeyPayload", sessionKeyToAmino, sessionKeyFromAmino],
146
+ ["recurringPull", "recurring_pull", "sparkdream/session/RecurringPullPayload", recurringPullToAmino, recurringPullFromAmino],
147
+ ["spendingAllowance", "spending_allowance", "sparkdream/session/SpendingAllowancePayload", spendingAllowanceToAmino, spendingAllowanceFromAmino],
148
+ ["scheduledOneshot", "scheduled_oneshot", "sparkdream/session/ScheduledOneshotPayload", scheduledOneshotToAmino, scheduledOneshotFromAmino],
149
+ ];
150
+ // ── Messages ────────────────────────────────────────────────────────────
151
+ // {<signer>, grant_id} messages; each signer field name is a single word, so
152
+ // the proto and amino spellings coincide.
153
+ const grantIdMsg = (signer) => ({
154
+ toAmino: (m) => ({ [signer]: str(m[signer]), grant_id: int64(m.grantId) }),
155
+ fromAmino: (o) => ({ [signer]: o[signer] ?? "", grantId: toBig(o.grant_id) }),
156
+ });
15
157
  exports.AminoConverter = {
16
158
  "/sparkdream.session.v1.MsgUpdateParams": {
17
159
  aminoType: "sparkdream/x/session/MsgUpdateParams",
@@ -67,4 +209,64 @@ exports.AminoConverter = {
67
209
  };
68
210
  },
69
211
  },
212
+ "/sparkdream.session.v1.MsgCreateGrant": {
213
+ aminoType: "sparkdream/x/session/MsgCreateGrant",
214
+ toAmino(message) {
215
+ const set = PAYLOADS.find(([key]) => message[key]);
216
+ return {
217
+ granter: str(message.granter),
218
+ grantee: str(message.grantee),
219
+ expires_at: time(message.expiresAt),
220
+ note: str(message.note),
221
+ Payload: set
222
+ ? { type: set[2], value: { [set[1]]: set[3](message[set[0]]) } }
223
+ : null,
224
+ };
225
+ },
226
+ fromAmino(object) {
227
+ const out = {
228
+ granter: object.granter ?? "",
229
+ grantee: object.grantee ?? "",
230
+ expiresAt: fromTime(object.expires_at),
231
+ note: object.note ?? "",
232
+ };
233
+ const inner = object.Payload?.value ?? {};
234
+ for (const [key, field, , , fromAmino] of PAYLOADS) {
235
+ if (inner[field])
236
+ out[key] = fromAmino(inner[field]);
237
+ }
238
+ return out;
239
+ },
240
+ },
241
+ "/sparkdream.session.v1.MsgClaimRecurringPull": {
242
+ aminoType: "sparkdream/x/session/MsgClaimRecurringPull",
243
+ ...grantIdMsg("grantee"),
244
+ },
245
+ "/sparkdream.session.v1.MsgPullAllowance": {
246
+ aminoType: "sparkdream/x/session/MsgPullAllowance",
247
+ toAmino: (m) => ({
248
+ grantee: str(m.grantee),
249
+ grant_id: int64(m.grantId),
250
+ recipient: str(m.recipient),
251
+ amount: coin(m.amount),
252
+ }),
253
+ fromAmino: (o) => ({
254
+ grantee: o.grantee ?? "",
255
+ grantId: toBig(o.grant_id),
256
+ recipient: o.recipient ?? "",
257
+ amount: fromCoin(o.amount),
258
+ }),
259
+ },
260
+ "/sparkdream.session.v1.MsgRetryScheduledOneshot": {
261
+ aminoType: "sparkdream/x/session/MsgRetryScheduledOneshot",
262
+ ...grantIdMsg("caller"),
263
+ },
264
+ "/sparkdream.session.v1.MsgRevokeGrant": {
265
+ aminoType: "sparkdream/x/session/MsgRevokeGrant",
266
+ ...grantIdMsg("granter"),
267
+ },
268
+ "/sparkdream.session.v1.MsgDeclineGrant": {
269
+ aminoType: "sparkdream/x/session/MsgDeclineGrant",
270
+ ...grantIdMsg("grantee"),
271
+ },
70
272
  };