catapultar 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.
Files changed (67) hide show
  1. package/LICENSE +165 -0
  2. package/README.md +161 -0
  3. package/dist/abi/CATValidator.d.ts +174 -0
  4. package/dist/abi/CATValidator.d.ts.map +1 -0
  5. package/dist/abi/CATValidator.js +225 -0
  6. package/dist/abi/CATValidator.js.map +1 -0
  7. package/dist/abi/catapultarFactoryV0.0.1.d.ts +2 -0
  8. package/dist/abi/catapultarFactoryV0.0.1.d.ts.map +1 -0
  9. package/dist/abi/catapultarFactoryV0.0.1.js +1 -0
  10. package/dist/abi/catapultarFactoryV0.0.1.js.map +1 -0
  11. package/dist/abi/catapultarFactoryV0.1.0.d.ts +175 -0
  12. package/dist/abi/catapultarFactoryV0.1.0.d.ts.map +1 -0
  13. package/dist/abi/catapultarFactoryV0.1.0.js +229 -0
  14. package/dist/abi/catapultarFactoryV0.1.0.js.map +1 -0
  15. package/dist/abi/catapultarV0.0.1.d.ts +2 -0
  16. package/dist/abi/catapultarV0.0.1.d.ts.map +1 -0
  17. package/dist/abi/catapultarV0.0.1.js +1 -0
  18. package/dist/abi/catapultarV0.0.1.js.map +1 -0
  19. package/dist/abi/catapultarV0.1.0.d.ts +409 -0
  20. package/dist/abi/catapultarV0.1.0.d.ts.map +1 -0
  21. package/dist/abi/catapultarV0.1.0.js +528 -0
  22. package/dist/abi/catapultarV0.1.0.js.map +1 -0
  23. package/dist/abi/mockerc20.d.ts +342 -0
  24. package/dist/abi/mockerc20.d.ts.map +1 -0
  25. package/dist/abi/mockerc20.js +443 -0
  26. package/dist/abi/mockerc20.js.map +1 -0
  27. package/dist/catapultar/account.d.ts +86 -0
  28. package/dist/catapultar/account.d.ts.map +1 -0
  29. package/dist/catapultar/account.js +408 -0
  30. package/dist/catapultar/account.js.map +1 -0
  31. package/dist/catapultar/catapultar.d.ts +143 -0
  32. package/dist/catapultar/catapultar.d.ts.map +1 -0
  33. package/dist/catapultar/catapultar.js +200 -0
  34. package/dist/catapultar/catapultar.js.map +1 -0
  35. package/dist/config.d.ts +14 -0
  36. package/dist/config.d.ts.map +1 -0
  37. package/dist/config.js +24 -0
  38. package/dist/config.js.map +1 -0
  39. package/dist/index.d.ts +7 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +6 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/transaction/constrainedtransaction.d.ts +57 -0
  44. package/dist/transaction/constrainedtransaction.d.ts.map +1 -0
  45. package/dist/transaction/constrainedtransaction.js +191 -0
  46. package/dist/transaction/constrainedtransaction.js.map +1 -0
  47. package/dist/transaction/transaction.d.ts +88 -0
  48. package/dist/transaction/transaction.d.ts.map +1 -0
  49. package/dist/transaction/transaction.js +185 -0
  50. package/dist/transaction/transaction.js.map +1 -0
  51. package/dist/types/types.d.ts +144 -0
  52. package/dist/types/types.d.ts.map +1 -0
  53. package/dist/types/types.js +53 -0
  54. package/dist/types/types.js.map +1 -0
  55. package/dist/utils/helpers.d.ts +31 -0
  56. package/dist/utils/helpers.d.ts.map +1 -0
  57. package/dist/utils/helpers.js +65 -0
  58. package/dist/utils/helpers.js.map +1 -0
  59. package/dist/utils/signature.d.ts +3 -0
  60. package/dist/utils/signature.d.ts.map +1 -0
  61. package/dist/utils/signature.js +10 -0
  62. package/dist/utils/signature.js.map +1 -0
  63. package/dist/utils/viem.d.ts +3 -0
  64. package/dist/utils/viem.d.ts.map +1 -0
  65. package/dist/utils/viem.js +10 -0
  66. package/dist/utils/viem.js.map +1 -0
  67. package/package.json +63 -0
@@ -0,0 +1,200 @@
1
+ import { hashTypedData } from "viem";
2
+ import { random } from "../utils/helpers.js";
3
+ import { AccountPublicKeyType, CallsTyped, ExecutionMode, } from "../types/types.js";
4
+ import { CatapultarAccount } from "./account.js";
5
+ import { BaseTransaction } from "../transaction/transaction.js";
6
+ /**
7
+ * A Catapultar transaction wrapper. Is intended to be used to convert a list of calls into a single Catapultar batch.
8
+ * @dev The class is intended to be used through modifiers, meaning each property should be set iteratively on the object:
9
+ * const tx = new CatapultarTx(options).setMode(ExecutionMode.RaiseRevert).setNonce(12n).addCalls(...[]).sign(() => ...).asParameters();
10
+ * To batch batches, multiple sub CatapultarTx can be created and then converted into calls like:
11
+ * calls.push(new CatapultarTx(options).addCalls(...[]).asCall());
12
+ * new CatapultarTx(options).addCalls(...calls).sign(() => ...).asParameters();
13
+ */
14
+ export class CatapultarTx extends BaseTransaction {
15
+ /**
16
+ * Create a new Catapultar transaction batch.
17
+ */
18
+ constructor(options) {
19
+ super(options);
20
+ // TODO: If given an object, assign object instead of recreating account.
21
+ this.account = new CatapultarAccount(options.account);
22
+ }
23
+ // --- Export the transaction for saving --- //
24
+ /**
25
+ * @returns Constructor parameters for a new (identical) CatapultarTx
26
+ */
27
+ export() {
28
+ return {
29
+ account: {
30
+ address: this.account.address,
31
+ chainId: this.account.chainId,
32
+ pubkey: this.account.pubkey,
33
+ name: this.account.name,
34
+ version: this.account.version,
35
+ },
36
+ mode: this.mode,
37
+ nonce: this.nonce,
38
+ signature: this.signature,
39
+ calls: this.calls,
40
+ };
41
+ }
42
+ /**
43
+ * Sets a signature along with its type. If non-ecdsa signatures are being set, this provides additional aids with encoding
44
+ */
45
+ setSignature(signature) {
46
+ this.signature = this.account.parseSignature(signature);
47
+ }
48
+ /**
49
+ * Sign the transaction using a Ethers compatible signer function.
50
+ * @dev The callback function will be called with a typeset compatible with ether.Signer._signTypedData.
51
+ * An alternative way to sign this function is to set it manually as .signature.
52
+ */
53
+ async sign(callback, options) {
54
+ const signerData = this.getSignerData(options);
55
+ this.signature = this.account.parseSignature(await callback(signerData));
56
+ return this;
57
+ }
58
+ // --- Validation --- //
59
+ async hasValidSignature(options) {
60
+ const { noSignatureIsValid = false } = options ?? {};
61
+ if (this.signature === undefined)
62
+ return noSignatureIsValid;
63
+ return this.account.isSignatureValid({
64
+ signature: this.signature,
65
+ hash: this.getTypeHashDigest({ ignoreNoCalls: true }),
66
+ });
67
+ }
68
+ async validateSignature(options) {
69
+ if (!(await this.hasValidSignature(options)))
70
+ throw new Error(`Invalid Signer`);
71
+ return this;
72
+ }
73
+ async validateUsingProvider() {
74
+ await this.account.validateNonce({ nonce: this.nonce });
75
+ await this.account.validateOwner();
76
+ return this;
77
+ }
78
+ // --- Order Creation --- //
79
+ /**
80
+ * Returns an Ethers compatible typed dict.
81
+ * @param options.ignoreNoCalls Do not throw an error if no calls have been configured. Default: false
82
+ */
83
+ getSignerData(options) {
84
+ const { ignoreNoCalls = false } = options ?? {};
85
+ if (this.nonce === 0n)
86
+ throw new Error(`Nonce 0 is not allowed. It cannot be differentiated from an invalid nonce.`);
87
+ if (!this.nonce)
88
+ throw new Error("Nonce has not been set");
89
+ if (!this.mode || !this.hasValidMode())
90
+ throw new Error("Mode has not been set");
91
+ if (!ignoreNoCalls && this.calls.length === 0)
92
+ throw new Error("Calls have not been set");
93
+ return {
94
+ domain: this.account.getDomainSeparator({
95
+ chain: !this.hasMultichainMode(),
96
+ }),
97
+ types: CallsTyped,
98
+ primaryType: "Calls",
99
+ message: {
100
+ nonce: this.nonce,
101
+ mode: this.mode,
102
+ calls: this.calls,
103
+ },
104
+ };
105
+ }
106
+ getTypeHashDigest(options) {
107
+ const signerData = this.getSignerData(options);
108
+ return hashTypedData(signerData);
109
+ }
110
+ /**
111
+ * Returns the signature as a on-chain compatible signature with an indicator byte.
112
+ * For ECDSA / Smart contracts returns as is.
113
+ * For P256, pads to 65. Then adds 00.
114
+ *
115
+ * @param Signature If provided, will act on the provided signature instead.
116
+ */
117
+ asCompatibleSignature(signature) {
118
+ const sig = signature ?? this.signature;
119
+ if (!sig)
120
+ throw new Error("A signature has to be provided");
121
+ if (this.account.accountPublicKeyType ===
122
+ AccountPublicKeyType.ECDSAOrSmartContract)
123
+ return sig;
124
+ if (this.account.accountPublicKeyType === AccountPublicKeyType.P256 ||
125
+ this.account.accountPublicKeyType === AccountPublicKeyType.WebAuthnP256) {
126
+ // If length >= 66, return as is.
127
+ if (sig.replace("0x", "").length >= 66 * 2)
128
+ return sig;
129
+ // Pad end to 65. Then add 00.
130
+ return `0x${sig.replace("0x", "").padEnd(65 * 2, "0")}00`;
131
+ }
132
+ throw new Error(`Unknown key scheme ${this.account.accountPublicKeyType}`);
133
+ }
134
+ // --- Convert the transaction object into actionable items --- //
135
+ /**
136
+ * @return As a call for further scheduling or manual transaction signing. If used for manual transaction.
137
+ */
138
+ async asCall() {
139
+ // TODO: validation
140
+ return {
141
+ ...(await this.asCallData()),
142
+ to: this.account.address,
143
+ };
144
+ }
145
+ }
146
+ /**
147
+ * This defines a meta transaction composed of several smaller transactions.
148
+ * Intended usecase: Wrapping multiple transactions (that can later be retried) into a single batch.
149
+ */
150
+ export class MetaCatapultarTx {
151
+ constructor(options) {
152
+ this.calls = [];
153
+ // TODO: If given an object, assign object instead of recreating account.
154
+ this.account = new CatapultarAccount(options.account);
155
+ // Random bytes with rightmost byte empty.
156
+ const randomNonce = BigInt(random(31)) << 8n;
157
+ const { mode, nonce, outerNonce = randomNonce, innerNonce = randomNonce + 1n, } = options;
158
+ // Transaction Definition
159
+ this.mode = mode;
160
+ this.nonce = nonce;
161
+ this.outerNonce = outerNonce;
162
+ this.innerNonce = innerNonce;
163
+ }
164
+ setMode(mode) {
165
+ this.mode = mode;
166
+ return this;
167
+ }
168
+ addCalls(...calls) {
169
+ for (const call of calls) {
170
+ this.calls.push(call);
171
+ }
172
+ return this;
173
+ }
174
+ checkNonces() {
175
+ const nonces = this.calls.map((tx) => tx.nonce).filter((n) => !!n);
176
+ if ([...new Set(nonces)].length != nonces.length)
177
+ throw new Error(`Duplicate nonces were found: ${nonces}`);
178
+ return this;
179
+ }
180
+ getCallsAsTxs() {
181
+ return this.calls.map((c, i) => {
182
+ return new CatapultarTx({
183
+ account: this.account,
184
+ })
185
+ .setMode(c.mode ? c.mode : ExecutionMode.RaiseRevert)
186
+ .setNonce(c.nonce ? c.nonce : this.innerNonce + BigInt(i))
187
+ .addCall(...c.calls);
188
+ });
189
+ }
190
+ async asCatapultarTx() {
191
+ this.checkNonces();
192
+ return new CatapultarTx({
193
+ account: this.account,
194
+ })
195
+ .setNonce(this.outerNonce)
196
+ .setMode(this.mode ?? ExecutionMode.SkipRevert)
197
+ .addCall(...(await Promise.all(this.getCallsAsTxs().map((c) => c.asCall()))));
198
+ }
199
+ }
200
+ //# sourceMappingURL=catapultar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catapultar.js","sourceRoot":"","sources":["../../src/catapultar/catapultar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EACL,oBAAoB,EACpB,UAAU,EACV,aAAa,GAKd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D;;;;;;;GAOG;AACH,MAAM,OAAO,YAIX,SAAQ,eAAe;IAGvB;;OAEG;IACH,YAAY,OASX;QACC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,yEAAyE;QACzE,IAAI,CAAC,OAAO,GAAG,IAAI,iBAAiB,CAClC,OAAO,CAAC,OAAgD,CACzD,CAAC;IACJ,CAAC;IAED,+CAA+C;IAE/C;;OAEG;IACH,MAAM;QACJ,OAAO;YACL,OAAO,EAAE;gBACP,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO;gBAC7B,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO;gBAC7B,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM;gBAC3B,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI;gBACvB,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO;aAC9B;YACD,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,KAAK,EAAE,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,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,WAAW,CAAC;iBACpD,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;iBACzD,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;QACzB,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,cAAc;QAClB,IAAI,CAAC,WAAW,EAAE,CAAC;QACnB,OAAO,IAAI,YAAY,CAAC;YACtB,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC;aACC,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC;aACzB,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,aAAa,CAAC,UAAU,CAAC;aAC9C,OAAO,CACN,GAAG,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CACpE,CAAC;IACN,CAAC;CACF"}
@@ -0,0 +1,14 @@
1
+ import type { Factory, MaybeFactory } from "./types/types.js";
2
+ export declare const factories: {
3
+ readonly "0.1.0": "0x92cEf6f87b4350C9ebA3D73A97b251b41D4AA348";
4
+ };
5
+ export declare const templates: {
6
+ readonly "0.1.0": "0xD57dEeEaBb0d4Dd2c8421DB036aC2225E54Cd9cC";
7
+ };
8
+ export declare const PUBLIC_DEFAULT_ANVIL_ACCOUNT_0 = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80";
9
+ export declare const cat_validator = "0x35C83412d576d624e9aDCa9d5D06559305C097e8";
10
+ export declare const token1 = "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0";
11
+ export declare const token2 = "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9";
12
+ export declare const token3 = "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9";
13
+ export declare function _factory(opt: MaybeFactory): Factory;
14
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE3D,eAAO,MAAM,SAAS;;CAEZ,CAAC;AACX,eAAO,MAAM,SAAS;;CAEZ,CAAC;AAEX,eAAO,MAAM,8BAA8B,uEAC2B,CAAC;AAEvE,eAAO,MAAM,aAAa,+CAA+C,CAAC;AAE1E,eAAO,MAAM,MAAM,+CAA+C,CAAC;AACnE,eAAO,MAAM,MAAM,+CAA+C,CAAC;AACnE,eAAO,MAAM,MAAM,+CAA+C,CAAC;AAEnE,wBAAgB,QAAQ,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAUnD"}
package/dist/config.js ADDED
@@ -0,0 +1,24 @@
1
+ export const factories = {
2
+ "0.1.0": "0x92cEf6f87b4350C9ebA3D73A97b251b41D4AA348",
3
+ };
4
+ export const templates = {
5
+ "0.1.0": "0xD57dEeEaBb0d4Dd2c8421DB036aC2225E54Cd9cC",
6
+ };
7
+ export const PUBLIC_DEFAULT_ANVIL_ACCOUNT_0 = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80";
8
+ export const cat_validator = "0x35C83412d576d624e9aDCa9d5D06559305C097e8";
9
+ export const token1 = "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0";
10
+ export const token2 = "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9";
11
+ export const token3 = "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9";
12
+ export function _factory(opt) {
13
+ // Ensure that if one key is set, both are set.
14
+ if ("factory" in opt || "template" in opt) {
15
+ if ("factory" in opt && "template" in opt)
16
+ return opt;
17
+ throw new Error("Factory and template incorrectly set.");
18
+ }
19
+ return {
20
+ factory: factories["0.1.0"],
21
+ template: templates["0.1.0"],
22
+ };
23
+ }
24
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,OAAO,EAAE,4CAA4C;CAC7C,CAAC;AACX,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,OAAO,EAAE,4CAA4C;CAC7C,CAAC;AAEX,MAAM,CAAC,MAAM,8BAA8B,GACzC,oEAAoE,CAAC;AAEvE,MAAM,CAAC,MAAM,aAAa,GAAG,4CAA4C,CAAC;AAE1E,MAAM,CAAC,MAAM,MAAM,GAAG,4CAA4C,CAAC;AACnE,MAAM,CAAC,MAAM,MAAM,GAAG,4CAA4C,CAAC;AACnE,MAAM,CAAC,MAAM,MAAM,GAAG,4CAA4C,CAAC;AAEnE,MAAM,UAAU,QAAQ,CAAC,GAAiB;IACxC,+CAA+C;IAC/C,IAAI,SAAS,IAAI,GAAG,IAAI,UAAU,IAAI,GAAG,EAAE,CAAC;QAC1C,IAAI,SAAS,IAAI,GAAG,IAAI,UAAU,IAAI,GAAG;YAAE,OAAO,GAAc,CAAC;QACjE,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAC3D,CAAC;IACD,OAAO;QACL,OAAO,EAAE,SAAS,CAAC,OAAO,CAAC;QAC3B,QAAQ,EAAE,SAAS,CAAC,OAAO,CAAC;KAC7B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ export { CatapultarAccount } from "./catapultar/account.js";
2
+ export { CatapultarTx, MetaCatapultarTx } from "./catapultar/catapultar.js";
3
+ export { ConstrainedAssetTransaction } from "./transaction/constrainedtransaction.js";
4
+ export { BaseTransaction } from "./transaction/transaction.js";
5
+ export { ExecutionMode, AccountPublicKeyType } from "./types/types.js";
6
+ export type { AccountPublicVar, Call, Calls, Allowance, Outcome, WebAuthnSignature, } from "./types/types.js";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAEpE,YAAY,EACV,gBAAgB,EAChB,IAAI,EACJ,KAAK,EACL,SAAS,EACT,OAAO,EACP,iBAAiB,GAClB,MAAM,eAAe,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export { CatapultarAccount } from "./catapultar/account.js";
2
+ export { CatapultarTx, MetaCatapultarTx } from "./catapultar/catapultar.js";
3
+ export { ConstrainedAssetTransaction } from "./transaction/constrainedtransaction.js";
4
+ export { BaseTransaction } from "./transaction/transaction.js";
5
+ export { ExecutionMode, AccountPublicKeyType } from "./types/types.js";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,57 @@
1
+ import { type Allowance, type Call, type Outcome } from "../types/types.js";
2
+ import { BaseTransaction } from "./transaction.js";
3
+ /**
4
+ * Helper class for deploying a Catapultar account with an embedded Constrained Asset Transaction
5
+ */
6
+ export declare class ConstrainedAssetTransaction {
7
+ allowances: Allowance[];
8
+ outcomes: Outcome[];
9
+ executor: `0x${string}`;
10
+ chainId: number;
11
+ constraintNonce: bigint;
12
+ constructor(opt: {
13
+ executor: `0x${string}`;
14
+ chainId: number;
15
+ });
16
+ addAllowances(...allowances: Allowance[]): void;
17
+ /**
18
+ * Add token outcomes to an asset constraint.
19
+ * To add the smart account as the recipient (address unknown at this stage), set address(0).
20
+ */
21
+ addOutcomes(...outcomes: Outcome[]): void;
22
+ perpetual(state: boolean): void;
23
+ /**
24
+ * Export the constrainted transaction as a BaseTransaction which can be converted to an account.
25
+ * @param opt.addApprove Whether to approve the tokens on the validator. Default True.
26
+ * @param opt.refund If provided, refund allowances to this contract. Default none.
27
+ * @param opt.validator Validator for transaction. Default library validator.
28
+ * @param opt.executor The constrainted transaction can only be executed by this account. Default this.executor.
29
+ * @returns BaseTransaction with calls embedded for a constrainted validator.
30
+ */
31
+ asCatapultarAllowanceTransaction(opt?: {
32
+ addApprove?: boolean;
33
+ refund?: `0x${string}`;
34
+ validator?: `0x${string}`;
35
+ executor?: `0x${string}`;
36
+ }): BaseTransaction;
37
+ /**
38
+ * The call for execution the validation on the account.
39
+ */
40
+ asExecuteCall(opt: {
41
+ address: `0x${string}`;
42
+ } & {
43
+ executionTarget: `0x${string}`;
44
+ executionPayload: `0x${string}`;
45
+ spends: bigint[];
46
+ } & {
47
+ refund?: `0x${string}`;
48
+ validator?: `0x${string}`;
49
+ }): Call;
50
+ asRefundCall(opt: {
51
+ address: `0x${string}`;
52
+ } & {
53
+ refund: `0x${string}`;
54
+ validator?: `0x${string}`;
55
+ }): Call;
56
+ }
57
+ //# sourceMappingURL=constrainedtransaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constrainedtransaction.d.ts","sourceRoot":"","s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IAAI;IAqCP,YAAY,CACV,GAAG,EAAE;QAAE,OAAO,EAAE,KAAK,MAAM,EAAE,CAAA;KAAE,GAAG;QAChC,MAAM,EAAE,KAAK,MAAM,EAAE,CAAC;QACtB,SAAS,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC;KAC3B;CAkCJ"}
@@ -0,0 +1,191 @@
1
+ import { encodeFunctionData, erc20Abi, hashTypedData, zeroAddress } from "viem";
2
+ import { DigestApproval, ExecutionConstraintTyped, ExecutionMode, } from "../types/types.js";
3
+ import { BaseTransaction } from "./transaction.js";
4
+ import CATAPULTAR_V0_1_0_ABI from "../abi/catapultarV0.1.0.js";
5
+ import { CAT_VALIDATOR_ABI } from "../abi/CATValidator.js";
6
+ import { cat_validator } from "../config.js";
7
+ /**
8
+ * Helper class for deploying a Catapultar account with an embedded Constrained Asset Transaction
9
+ */
10
+ export class ConstrainedAssetTransaction {
11
+ constructor(opt) {
12
+ this.allowances = [];
13
+ this.outcomes = [];
14
+ this.constraintNonce = 1n;
15
+ const { executor, chainId } = opt;
16
+ this.executor = executor;
17
+ this.chainId = chainId;
18
+ }
19
+ addAllowances(...allowances) {
20
+ this.allowances = [...this.allowances, ...allowances];
21
+ }
22
+ /**
23
+ * Add token outcomes to an asset constraint.
24
+ * To add the smart account as the recipient (address unknown at this stage), set address(0).
25
+ */
26
+ addOutcomes(...outcomes) {
27
+ this.outcomes = [...this.outcomes, ...outcomes];
28
+ }
29
+ perpetual(state) {
30
+ this.constraintNonce = state
31
+ ? 0n
32
+ : this.constraintNonce !== 0n
33
+ ? this.constraintNonce
34
+ : 1n;
35
+ }
36
+ /**
37
+ * Export the constrainted transaction as a BaseTransaction which can be converted to an account.
38
+ * @param opt.addApprove Whether to approve the tokens on the validator. Default True.
39
+ * @param opt.refund If provided, refund allowances to this contract. Default none.
40
+ * @param opt.validator Validator for transaction. Default library validator.
41
+ * @param opt.executor The constrainted transaction can only be executed by this account. Default this.executor.
42
+ * @returns BaseTransaction with calls embedded for a constrainted validator.
43
+ */
44
+ asCatapultarAllowanceTransaction(opt) {
45
+ const { addApprove = true, refund, validator = cat_validator, executor = this.executor, } = opt ?? {};
46
+ const calls = [];
47
+ if (addApprove) {
48
+ // Allow the validator to pull funds. To actually pull funds, the validator requires a signature.
49
+ for (const allowance of this.allowances) {
50
+ calls.push({
51
+ to: allowance.token,
52
+ data: encodeFunctionData({
53
+ abi: erc20Abi,
54
+ functionName: "approve",
55
+ args: [validator, allowance.amount],
56
+ }),
57
+ value: 0n,
58
+ });
59
+ }
60
+ }
61
+ // Set the signature that allows the validator to pull funds.
62
+ const executionConstraint = {
63
+ allowances: this.allowances,
64
+ outcomes: this.outcomes,
65
+ executor: executor,
66
+ nonce: this.constraintNonce,
67
+ };
68
+ const typehash = hashTypedData({
69
+ types: ExecutionConstraintTyped,
70
+ primaryType: "ExecutionConstraint",
71
+ message: executionConstraint,
72
+ domain: {
73
+ chainId: this.chainId,
74
+ name: "CAT Validator",
75
+ version: "1",
76
+ verifyingContract: validator,
77
+ },
78
+ });
79
+ calls.push({
80
+ to: zeroAddress,
81
+ value: 0n,
82
+ data: encodeFunctionData({
83
+ abi: CATAPULTAR_V0_1_0_ABI,
84
+ functionName: "setSignature",
85
+ args: [typehash, DigestApproval.Signature],
86
+ }),
87
+ });
88
+ // If a refund target has been provided, then we add a 1:1 refund.
89
+ if (refund) {
90
+ const refundOutcomes = this.allowances.map((allowance) => ({
91
+ destination: refund,
92
+ amount: allowance.amount,
93
+ token: allowance.token,
94
+ }));
95
+ const refundExecutionConstraint = {
96
+ allowances: this.allowances,
97
+ outcomes: refundOutcomes,
98
+ executor: executor,
99
+ nonce: this.constraintNonce,
100
+ };
101
+ const typehash = hashTypedData({
102
+ types: ExecutionConstraintTyped,
103
+ primaryType: "ExecutionConstraint",
104
+ message: refundExecutionConstraint,
105
+ domain: {
106
+ chainId: this.chainId,
107
+ name: "CAT Validator",
108
+ version: "1",
109
+ verifyingContract: validator,
110
+ },
111
+ });
112
+ calls.push({
113
+ to: zeroAddress,
114
+ value: 0n,
115
+ data: encodeFunctionData({
116
+ abi: CATAPULTAR_V0_1_0_ABI,
117
+ functionName: "setSignature",
118
+ args: [typehash, DigestApproval.Signature],
119
+ }),
120
+ });
121
+ }
122
+ const tx = new BaseTransaction();
123
+ tx.addCall(...calls);
124
+ tx.setMode(ExecutionMode.RaiseRevert);
125
+ tx.setNonce(1n);
126
+ return tx;
127
+ }
128
+ /**
129
+ * The call for execution the validation on the account.
130
+ */
131
+ asExecuteCall(opt) {
132
+ const { validator = cat_validator, executionTarget, executionPayload, } = opt;
133
+ if (opt.spends.length !== this.allowances.length)
134
+ throw new Error(`Spends and allowances not same length: Allowances: ${this.allowances.length}, Spends: ${opt.spends.length}`);
135
+ const allowanceSpends = this.allowances.map((a, i) => ({
136
+ token: a.token,
137
+ allocated: a.amount,
138
+ spend: opt.spends[i],
139
+ }));
140
+ const executeCall = {
141
+ to: validator,
142
+ data: encodeFunctionData({
143
+ abi: CAT_VALIDATOR_ABI,
144
+ functionName: "entry",
145
+ args: [
146
+ executionTarget,
147
+ executionPayload,
148
+ opt.address,
149
+ this.constraintNonce,
150
+ allowanceSpends,
151
+ this.outcomes,
152
+ "0x",
153
+ ],
154
+ }),
155
+ value: 0n,
156
+ };
157
+ return executeCall;
158
+ }
159
+ asRefundCall(opt) {
160
+ const { validator = cat_validator } = opt;
161
+ const allowanceSpends = this.allowances.map((a) => ({
162
+ token: a.token,
163
+ allocated: a.amount,
164
+ spend: a.amount,
165
+ }));
166
+ const refundOutcomes = this.allowances.map((a) => ({
167
+ token: a.token,
168
+ amount: a.amount,
169
+ destination: opt.refund,
170
+ }));
171
+ const executeCall = {
172
+ to: validator,
173
+ data: encodeFunctionData({
174
+ abi: CAT_VALIDATOR_ABI,
175
+ functionName: "entry",
176
+ args: [
177
+ opt.refund,
178
+ "0x",
179
+ opt.address,
180
+ this.constraintNonce,
181
+ allowanceSpends,
182
+ refundOutcomes,
183
+ "0x",
184
+ ],
185
+ }),
186
+ value: 0n,
187
+ };
188
+ return executeCall;
189
+ }
190
+ }
191
+ //# sourceMappingURL=constrainedtransaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constrainedtransaction.js","sourceRoot":"","sources":["../../src/transaction/constrainedtransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAChF,OAAO,EACL,cAAc,EACd,wBAAwB,EACxB,aAAa,GAMd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,qBAAqB,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C;;GAEG;AACH,MAAM,OAAO,2BAA2B;IAStC,YAAY,GAAiD;QAR7D,eAAU,GAAgB,EAAE,CAAC;QAC7B,aAAQ,GAAc,EAAE,CAAC;QAKzB,oBAAe,GAAW,EAAE,CAAC;QAG3B,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,GAAG,CAAC;QAClC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,aAAa,CAAC,GAAG,UAAuB;QACtC,IAAI,CAAC,UAAU,GAAG,CAAC,GAAG,IAAI,CAAC,UAAU,EAAE,GAAG,UAAU,CAAC,CAAC;IACxD,CAAC;IAED;;;OAGG;IACH,WAAW,CAAC,GAAG,QAAmB;QAChC,IAAI,CAAC,QAAQ,GAAG,CAAC,GAAG,IAAI,CAAC,QAAQ,EAAE,GAAG,QAAQ,CAAC,CAAC;IAClD,CAAC;IAED,SAAS,CAAC,KAAc;QACtB,IAAI,CAAC,eAAe,GAAG,KAAK;YAC1B,CAAC,CAAC,EAAE;YACJ,CAAC,CA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AG,GAAG,CAAC;QAE1C,MAAM,eAAe,GAAqB,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACpE,KAAK,EAAE,CAAC,CAAC,KAAK;YACd,SAAS,EAAE,CAAC,CAAC,MAAM;YACnB,KAAK,EAAE,CAAC,CAAC,MAAM;SAChB,CAAC,CAAC,CAAC;QACJ,MAAM,cAAc,GAAc,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAC5D,KAAK,EAAE,CAAC,CAAC,KAAK;YACd,MAAM,EAAE,CAAC,CAAC,MAAM;YAChB,WAAW,EAAE,GAAG,CAAC,MAAM;SACxB,CAAC,CAAC,CAAC;QAEJ,MAAM,WAAW,GAAS;YACxB,EAAE,EAAE,SAAS;YACb,IAAI,EAAE,kBAAkB,CAAC;gBACvB,GAAG,EAAE,iBAAiB;gBACtB,YAAY,EAAE,OAAO;gBACrB,IAAI,EAAE;oBACJ,GAAG,CAAC,MAAM;oBACV,IAAI;oBACJ,GAAG,CAAC,OAAO;oBACX,IAAI,CAAC,eAAe;oBACpB,eAAe;oBACf,cAAc;oBACd,IAAI;iBACL;aACF,CAAC;YACF,KAAK,EAAE,EAAE;SACV,CAAC;QACF,OAAO,WAAW,CAAC;IACrB,CAAC;CACF"}
@@ -0,0 +1,88 @@
1
+ import { AccountPublicKeyType, ExecutionMode, type Call, type MaybeFactory, type Pubkey } from "../types/types.js";
2
+ export declare class BaseTransaction {
3
+ /** Transaction ExecutionMode, defines transaction behavior for call reverts. */
4
+ mode?: ExecutionMode;
5
+ /** Transaction nonce. Only 1 transaction can be executed for each nonce. */
6
+ nonce?: bigint;
7
+ /** List of calls the transaction contains. */
8
+ calls: Call[];
9
+ signature?: `0x${string}`;
10
+ constructor(opt?: {
11
+ mode?: ExecutionMode;
12
+ nonce?: bigint;
13
+ calls?: Call[];
14
+ signature?: `0x${string}`;
15
+ });
16
+ /**
17
+ * Set the transaction nonce for the Catapultar transaction. Only 1 transaction can ever be executed for each nonce.
18
+ */
19
+ setNonce(nonce: bigint): this;
20
+ /**
21
+ * Generates a random uint256 nonce and sets it.
22
+ */
23
+ setRandomNonce(): this;
24
+ /**
25
+ * Sets the Catapultar transaction mode.
26
+ */
27
+ setMode(mode: ExecutionMode): this;
28
+ /**
29
+ * Adds list of calls to the Catapultar transaction. The calls will be executed with the configured mode.
30
+ */
31
+ addCall(...calls: Call[]): this;
32
+ /**
33
+ * @returns Total value of all contained calls.
34
+ */
35
+ getTotalValue(): bigint;
36
+ hasValidMode(): boolean;
37
+ /**
38
+ * @returns Whether the a multichain execution mode is set.
39
+ */
40
+ hasMultichainMode(): boolean;
41
+ /**
42
+ * Returns the signature as a compact signature of 64 bytes instead of 65 bytes.
43
+ *
44
+ * @param Signature If provided, will act on the provided signature instead.
45
+ */
46
+ asCompactSignature(signature?: `0x${string}`): `0x${string}`;
47
+ /**
48
+ * @dev Opdata is nonce + signature packed.
49
+ * If no signature has been provided to the object, it will create the transaction without a signatures. This can be used to sub-batch the transaction.
50
+ */
51
+ getOpData(options?: {
52
+ compactSignature: boolean;
53
+ }): `0x${string}`;
54
+ getExecutionData(): `0x${string}`;
55
+ /** @return As parameters for an execute call. */
56
+ asParameters(): {
57
+ mode: ExecutionMode | undefined;
58
+ executionData: `0x${string}`;
59
+ metadata: {
60
+ value: bigint;
61
+ signature: `0x${string}` | undefined;
62
+ };
63
+ };
64
+ /**
65
+ * @return As a call for further scheduling or manual transaction signing. If used for manual transaction.
66
+ */
67
+ asCallData(): Omit<Call, "to">;
68
+ /** Return the calls as an approval diget. This can be used to "embed" the calls into an account */
69
+ asDigest(): `0x${string}`;
70
+ /** Generate an account with this action embedded. */
71
+ asAccount<AKT extends AccountPublicKeyType>(opt: {
72
+ salt: `0x${string}`;
73
+ } & Pubkey<AKT> & MaybeFactory): {
74
+ deployCall: {
75
+ to: `0x${string}`;
76
+ data: `0x${string}`;
77
+ value: bigint;
78
+ };
79
+ actionCall: {
80
+ to: `0x${string}`;
81
+ value: bigint;
82
+ data: `0x${string}`;
83
+ };
84
+ callDigest: `0x${string}`;
85
+ address: `0x${string}`;
86
+ };
87
+ }
88
+ //# sourceMappingURL=transaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../src/transaction/transaction.ts"],"names":[],"mappings":"AACA,OAAO,EACL,oBAAoB,EAEpB,aAAa,EACb,KAAK,IAAI,EACT,KAAK,YAAY,EACjB,KAAK,MAAM,EACZ,MAAM,gBAAgB,CAAC;AAQxB,qBAAa,eAAe;IAC1B,gFAAgF;IAChF,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,4EAA4E;IAC5E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8CAA8C;IAC9C,KAAK,EAAE,IAAI,EAAE,CAAC;IAEd,SAAS,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC;gBAEd,GAAG,CAAC,EAAE;QAChB,IAAI,CAAC,EAAE,aAAa,CAAC;QACrB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC;QACf,SAAS,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC;KAC3B;IAUD;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM;IAStB;;OAEG;IACH,cAAc;IAId;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,aAAa;IAK3B;;OAEG;IACH,OAAO,CAAC,GAAG,KAAK,EAAE,IAAI,EAAE;IASxB;;OAEG;IACH,aAAa,IAAI,MAAM;IAMvB,YAAY;IAKZ;;OAEG;IACH,iBAAiB,IAAI,OAAO;IAO5B;;;;OAIG;IACH,kBAAkB,CAAC,SAAS,CAAC,EAAE,KAAK,MAAM,EAAE,GAAG,KAAK,MAAM,EAAE;IAU5D;;;OAGG;IACH,SAAS,CAAC,OAAO,CAAC,EAAE;QAAE,gBAAgB,EAAE,OAAO,C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