@atomiqlabs/chain-starknet 8.1.10 → 8.1.11

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/dist/index.d.ts CHANGED
@@ -2,6 +2,8 @@ export { StarknetBtcStoredHeader } from "./starknet/btcrelay/headers/StarknetBtc
2
2
  export { StarknetBtcHeader } from "./starknet/btcrelay/headers/StarknetBtcHeader";
3
3
  export * from "./starknet/btcrelay/StarknetBtcRelay";
4
4
  export * from "./starknet/chain/modules/StarknetFees";
5
+ export { StarknetTx, SignedStarknetTx } from "./starknet/chain/modules/StarknetTransactions";
6
+ export { StarknetAction } from "./starknet/chain/StarknetAction";
5
7
  export * from "./starknet/chain/StarknetChainInterface";
6
8
  export * from "./starknet/events/StarknetChainEventsBrowser";
7
9
  export * from "./starknet/provider/RpcProviderWithRetries";
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.StarknetSwapData = exports.StarknetSpvVaultData = exports.StarknetBtcHeader = exports.StarknetBtcStoredHeader = void 0;
17
+ exports.StarknetSwapData = exports.StarknetSpvVaultData = exports.StarknetAction = exports.StarknetBtcHeader = exports.StarknetBtcStoredHeader = void 0;
18
18
  const WebSocket = require("ws");
19
19
  if (global.window == null)
20
20
  global.WebSocket = WebSocket;
@@ -24,6 +24,8 @@ var StarknetBtcHeader_1 = require("./starknet/btcrelay/headers/StarknetBtcHeader
24
24
  Object.defineProperty(exports, "StarknetBtcHeader", { enumerable: true, get: function () { return StarknetBtcHeader_1.StarknetBtcHeader; } });
25
25
  __exportStar(require("./starknet/btcrelay/StarknetBtcRelay"), exports);
26
26
  __exportStar(require("./starknet/chain/modules/StarknetFees"), exports);
27
+ var StarknetAction_1 = require("./starknet/chain/StarknetAction");
28
+ Object.defineProperty(exports, "StarknetAction", { enumerable: true, get: function () { return StarknetAction_1.StarknetAction; } });
27
29
  __exportStar(require("./starknet/chain/StarknetChainInterface"), exports);
28
30
  __exportStar(require("./starknet/events/StarknetChainEventsBrowser"), exports);
29
31
  __exportStar(require("./starknet/provider/RpcProviderWithRetries"), exports);
@@ -2,18 +2,62 @@ import { Call } from "starknet";
2
2
  import { StarknetChainInterface } from "./StarknetChainInterface";
3
3
  import { StarknetTx } from "./modules/StarknetTransactions";
4
4
  import { StarknetGas } from "./modules/StarknetFees";
5
+ /**
6
+ * An action which contains multiple underlying contract calls (invokes), tracks their total gas limits
7
+ * and allows creating a transaction, which will execute all the contract calls
8
+ *
9
+ * @category Chain Interface
10
+ */
5
11
  export declare class StarknetAction {
12
+ /**
13
+ * Total gas limit of all the contract calls
14
+ */
6
15
  gas: StarknetGas;
16
+ /**
17
+ * Address of the signer for this transaction
18
+ */
7
19
  readonly mainSigner: string;
8
20
  private readonly root;
9
21
  private readonly instructions;
10
22
  private feeRate?;
11
23
  constructor(mainSigner: string, root: StarknetChainInterface, instructions?: Call[] | Call, gasLimit?: StarknetGas, feeRate?: string);
12
24
  private estimateFeeRate;
25
+ /**
26
+ * Adds a single invoke call to the action along with the gas limits
27
+ *
28
+ * @param instruction Instruction to add to the action
29
+ * @param gasLimit Gas limit required for the instruction
30
+ */
13
31
  addIx(instruction: Call, gasLimit?: StarknetGas): void;
32
+ /**
33
+ * Adds contract calls from another starknet action to this action, while also adding its gas limits
34
+ *
35
+ * @param action Calls from this action are added to current action
36
+ */
14
37
  add(action: StarknetAction): this;
38
+ /**
39
+ * Adds contract calls from another starknet action to this action, while also adding its gas limits. Adds
40
+ * the contract calls at a given index provided (by default at the end of existing calls)
41
+ *
42
+ * @param action Calls from this action are added to current action
43
+ * @param index Index at which to add the calls (by defaults added at the end)
44
+ */
15
45
  addAction(action: StarknetAction, index?: number): this;
46
+ /**
47
+ * Creates an unsigned starknet transaction out of this action, which executes all the underlying contract calls
48
+ *
49
+ * @param feeRate Fee rate to use for the transaction
50
+ */
16
51
  tx(feeRate?: string): Promise<StarknetTx>;
52
+ /**
53
+ * Adds the generated transaction to an already existing array of transaction
54
+ *
55
+ * @param txs Transaction executing this action will be added to this transactions array
56
+ * @param feeRate Fee rate to use for this transaction
57
+ */
17
58
  addToTxs(txs: StarknetTx[], feeRate?: string): Promise<void>;
59
+ /**
60
+ * Number of individual contract calls in this action
61
+ */
18
62
  ixsLength(): number;
19
63
  }
@@ -2,6 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StarknetAction = void 0;
4
4
  const StarknetFees_1 = require("./modules/StarknetFees");
5
+ /**
6
+ * An action which contains multiple underlying contract calls (invokes), tracks their total gas limits
7
+ * and allows creating a transaction, which will execute all the contract calls
8
+ *
9
+ * @category Chain Interface
10
+ */
5
11
  class StarknetAction {
6
12
  constructor(mainSigner, root, instructions = [], gasLimit, feeRate) {
7
13
  this.mainSigner = mainSigner;
@@ -17,14 +23,32 @@ class StarknetAction {
17
23
  estimateFeeRate() {
18
24
  return this.root.Fees.getFeeRate();
19
25
  }
26
+ /**
27
+ * Adds a single invoke call to the action along with the gas limits
28
+ *
29
+ * @param instruction Instruction to add to the action
30
+ * @param gasLimit Gas limit required for the instruction
31
+ */
20
32
  addIx(instruction, gasLimit) {
21
33
  this.instructions.push(instruction);
22
34
  if (gasLimit != null)
23
35
  this.gas = (0, StarknetFees_1.starknetGasAdd)(this.gas, gasLimit);
24
36
  }
37
+ /**
38
+ * Adds contract calls from another starknet action to this action, while also adding its gas limits
39
+ *
40
+ * @param action Calls from this action are added to current action
41
+ */
25
42
  add(action) {
26
43
  return this.addAction(action);
27
44
  }
45
+ /**
46
+ * Adds contract calls from another starknet action to this action, while also adding its gas limits. Adds
47
+ * the contract calls at a given index provided (by default at the end of existing calls)
48
+ *
49
+ * @param action Calls from this action are added to current action
50
+ * @param index Index at which to add the calls (by defaults added at the end)
51
+ */
28
52
  addAction(action, index = this.instructions.length) {
29
53
  if (action.mainSigner !== this.mainSigner)
30
54
  throw new Error("Actions need to have the same signer!");
@@ -45,6 +69,11 @@ class StarknetAction {
45
69
  this.feeRate = action.feeRate;
46
70
  return this;
47
71
  }
72
+ /**
73
+ * Creates an unsigned starknet transaction out of this action, which executes all the underlying contract calls
74
+ *
75
+ * @param feeRate Fee rate to use for the transaction
76
+ */
48
77
  async tx(feeRate) {
49
78
  if (feeRate == null)
50
79
  feeRate = this.feeRate;
@@ -64,9 +93,18 @@ class StarknetAction {
64
93
  }
65
94
  };
66
95
  }
96
+ /**
97
+ * Adds the generated transaction to an already existing array of transaction
98
+ *
99
+ * @param txs Transaction executing this action will be added to this transactions array
100
+ * @param feeRate Fee rate to use for this transaction
101
+ */
67
102
  async addToTxs(txs, feeRate) {
68
103
  txs.push(await this.tx(feeRate));
69
104
  }
105
+ /**
106
+ * Number of individual contract calls in this action
107
+ */
70
108
  ixsLength() {
71
109
  return this.instructions.length;
72
110
  }
@@ -19,7 +19,19 @@ export type StarknetTxDeployAccount = StarknetTxBase & {
19
19
  signed?: DeployAccountContractTransaction;
20
20
  };
21
21
  export declare function isStarknetTxDeployAccount(obj: any): obj is StarknetTxDeployAccount;
22
+ /**
23
+ * Unsigned starknet transaction, either an invoke transaction calling contracts or account deploy transaction
24
+ *
25
+ * @category Chain Interface
26
+ */
22
27
  export type StarknetTx = StarknetTxInvoke | StarknetTxDeployAccount;
28
+ /**
29
+ * Signed starknet transaction, either an invoke transaction calling contracts or account deploy transaction.
30
+ *
31
+ * @remarks Uses the same type as the unsinged tx for Starknet!
32
+ *
33
+ * @category Chain Interface
34
+ */
23
35
  export type SignedStarknetTx = StarknetTx;
24
36
  export type StarknetTraceCall = {
25
37
  calldata: string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atomiqlabs/chain-starknet",
3
- "version": "8.1.10",
3
+ "version": "8.1.11",
4
4
  "description": "Starknet specific base implementation",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
package/src/index.ts CHANGED
@@ -6,6 +6,8 @@ export {StarknetBtcHeader} from "./starknet/btcrelay/headers/StarknetBtcHeader";
6
6
  export * from "./starknet/btcrelay/StarknetBtcRelay";
7
7
 
8
8
  export * from "./starknet/chain/modules/StarknetFees";
9
+ export {StarknetTx, SignedStarknetTx} from "./starknet/chain/modules/StarknetTransactions";
10
+ export {StarknetAction} from "./starknet/chain/StarknetAction";
9
11
  export * from "./starknet/chain/StarknetChainInterface";
10
12
 
11
13
  export * from "./starknet/events/StarknetChainEventsBrowser";
@@ -3,9 +3,21 @@ import {StarknetChainInterface} from "./StarknetChainInterface";
3
3
  import {StarknetTx} from "./modules/StarknetTransactions";
4
4
  import {StarknetGas, starknetGasAdd} from "./modules/StarknetFees";
5
5
 
6
+ /**
7
+ * An action which contains multiple underlying contract calls (invokes), tracks their total gas limits
8
+ * and allows creating a transaction, which will execute all the contract calls
9
+ *
10
+ * @category Chain Interface
11
+ */
6
12
  export class StarknetAction {
7
13
 
14
+ /**
15
+ * Total gas limit of all the contract calls
16
+ */
8
17
  gas: StarknetGas;
18
+ /**
19
+ * Address of the signer for this transaction
20
+ */
9
21
  readonly mainSigner: string;
10
22
 
11
23
  private readonly root: StarknetChainInterface;
@@ -34,15 +46,33 @@ export class StarknetAction {
34
46
  return this.root.Fees.getFeeRate();
35
47
  }
36
48
 
49
+ /**
50
+ * Adds a single invoke call to the action along with the gas limits
51
+ *
52
+ * @param instruction Instruction to add to the action
53
+ * @param gasLimit Gas limit required for the instruction
54
+ */
37
55
  public addIx(instruction: Call, gasLimit?: StarknetGas) {
38
56
  this.instructions.push(instruction);
39
57
  if(gasLimit!=null) this.gas = starknetGasAdd(this.gas, gasLimit);
40
58
  }
41
59
 
60
+ /**
61
+ * Adds contract calls from another starknet action to this action, while also adding its gas limits
62
+ *
63
+ * @param action Calls from this action are added to current action
64
+ */
42
65
  public add(action: StarknetAction): this {
43
66
  return this.addAction(action);
44
67
  }
45
68
 
69
+ /**
70
+ * Adds contract calls from another starknet action to this action, while also adding its gas limits. Adds
71
+ * the contract calls at a given index provided (by default at the end of existing calls)
72
+ *
73
+ * @param action Calls from this action are added to current action
74
+ * @param index Index at which to add the calls (by defaults added at the end)
75
+ */
46
76
  public addAction(action: StarknetAction, index: number = this.instructions.length): this {
47
77
  if(action.mainSigner!==this.mainSigner) throw new Error("Actions need to have the same signer!");
48
78
  if(this.gas.l1Gas==null && action.gas.l1Gas!=null) this.gas.l1Gas = action.gas.l1Gas;
@@ -56,6 +86,11 @@ export class StarknetAction {
56
86
  return this;
57
87
  }
58
88
 
89
+ /**
90
+ * Creates an unsigned starknet transaction out of this action, which executes all the underlying contract calls
91
+ *
92
+ * @param feeRate Fee rate to use for the transaction
93
+ */
59
94
  public async tx(feeRate?: string): Promise<StarknetTx> {
60
95
  if(feeRate==null) feeRate = this.feeRate;
61
96
  if(feeRate==null) feeRate = await this.estimateFeeRate();
@@ -75,10 +110,19 @@ export class StarknetAction {
75
110
  };
76
111
  }
77
112
 
113
+ /**
114
+ * Adds the generated transaction to an already existing array of transaction
115
+ *
116
+ * @param txs Transaction executing this action will be added to this transactions array
117
+ * @param feeRate Fee rate to use for this transaction
118
+ */
78
119
  public async addToTxs(txs: StarknetTx[], feeRate?: string): Promise<void> {
79
120
  txs.push(await this.tx(feeRate));
80
121
  }
81
122
 
123
+ /**
124
+ * Number of individual contract calls in this action
125
+ */
82
126
  public ixsLength(): number {
83
127
  return this.instructions.length;
84
128
  }
@@ -62,7 +62,20 @@ export function isStarknetTxDeployAccount(obj: any): obj is StarknetTxDeployAcco
62
62
  (obj.signed==null || typeof(obj.signed)==="object");
63
63
  }
64
64
 
65
+ /**
66
+ * Unsigned starknet transaction, either an invoke transaction calling contracts or account deploy transaction
67
+ *
68
+ * @category Chain Interface
69
+ */
65
70
  export type StarknetTx = StarknetTxInvoke | StarknetTxDeployAccount;
71
+
72
+ /**
73
+ * Signed starknet transaction, either an invoke transaction calling contracts or account deploy transaction.
74
+ *
75
+ * @remarks Uses the same type as the unsinged tx for Starknet!
76
+ *
77
+ * @category Chain Interface
78
+ */
66
79
  export type SignedStarknetTx = StarknetTx;
67
80
 
68
81
  export type StarknetTraceCall = {