@gardenfi/swap 0.0.2-beta.2 → 0.0.2-beta.4

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 (230) hide show
  1. package/dist/index104.cjs +1 -1
  2. package/dist/index104.js +4 -4
  3. package/dist/index106.cjs +1 -1
  4. package/dist/index106.js +3 -3
  5. package/dist/index107.cjs +1 -1
  6. package/dist/index107.js +3 -3
  7. package/dist/index116.cjs +1 -1
  8. package/dist/index116.js +1 -1
  9. package/dist/index117.cjs +1 -1
  10. package/dist/index117.js +1 -1
  11. package/dist/index12.cjs +1 -1
  12. package/dist/index12.js +12 -12
  13. package/dist/index120.cjs +1 -1
  14. package/dist/index120.js +2 -2
  15. package/dist/index121.cjs +1 -1
  16. package/dist/index121.js +7 -7
  17. package/dist/index132.cjs +1 -1
  18. package/dist/index132.js +1 -1
  19. package/dist/index133.cjs +1 -1
  20. package/dist/index133.js +1 -1
  21. package/dist/index134.cjs +1 -1
  22. package/dist/index134.js +1 -1
  23. package/dist/index135.cjs +1 -1
  24. package/dist/index135.js +1 -1
  25. package/dist/index138.cjs +1 -1
  26. package/dist/index138.js +2 -2
  27. package/dist/index161.cjs +1 -1
  28. package/dist/index161.js +2 -2
  29. package/dist/index167.cjs +1 -1
  30. package/dist/index167.js +1 -1
  31. package/dist/index168.cjs +1 -1
  32. package/dist/index168.js +2 -2
  33. package/dist/index169.cjs +1 -1
  34. package/dist/index169.js +2 -2
  35. package/dist/index170.cjs +1 -1
  36. package/dist/index170.js +2 -2
  37. package/dist/index171.cjs +1 -1
  38. package/dist/index171.js +2 -2
  39. package/dist/index172.cjs +1 -1
  40. package/dist/index172.js +2 -2
  41. package/dist/index272.cjs +1 -1
  42. package/dist/index272.js +9 -174
  43. package/dist/index273.cjs +1 -2
  44. package/dist/index273.js +30 -91
  45. package/dist/index274.cjs +1 -1
  46. package/dist/index274.js +2 -41
  47. package/dist/index275.cjs +1 -1
  48. package/dist/index275.js +47 -4
  49. package/dist/index276.cjs +1 -1
  50. package/dist/index276.js +11 -9
  51. package/dist/index277.cjs +1 -1
  52. package/dist/index277.js +174 -30
  53. package/dist/index278.cjs +2 -1
  54. package/dist/index278.js +92 -2
  55. package/dist/index279.cjs +1 -1
  56. package/dist/index279.js +38 -45
  57. package/dist/index280.cjs +1 -1
  58. package/dist/index280.js +4 -11
  59. package/dist/index281.cjs +1 -1
  60. package/dist/index281.js +3 -3
  61. package/dist/index283.cjs +1 -2
  62. package/dist/index283.js +42 -41
  63. package/dist/index284.cjs +1 -1
  64. package/dist/index284.js +321 -2
  65. package/dist/index285.cjs +1 -1
  66. package/dist/index285.js +605 -5
  67. package/dist/index286.cjs +1 -1
  68. package/dist/index286.js +109 -10
  69. package/dist/index287.cjs +1 -1
  70. package/dist/index287.js +167 -19
  71. package/dist/index288.cjs +1 -1
  72. package/dist/index288.js +301 -8
  73. package/dist/index289.cjs +1 -1
  74. package/dist/index289.js +93 -72
  75. package/dist/index290.cjs +1 -1
  76. package/dist/index290.js +54 -63
  77. package/dist/index291.cjs +1 -1
  78. package/dist/index291.js +51 -186
  79. package/dist/index292.cjs +1 -1
  80. package/dist/index292.js +42 -20
  81. package/dist/index293.cjs +1 -1
  82. package/dist/index293.js +14 -41
  83. package/dist/index294.cjs +1 -1
  84. package/dist/index294.js +315 -23
  85. package/dist/index295.cjs +1 -1
  86. package/dist/index295.js +57 -88
  87. package/dist/index296.cjs +1 -1
  88. package/dist/index296.js +19 -40
  89. package/dist/index297.cjs +1 -1
  90. package/dist/index297.js +28 -15
  91. package/dist/index298.cjs +1 -1
  92. package/dist/index298.js +3 -13
  93. package/dist/index299.cjs +7 -1
  94. package/dist/index299.js +237 -7
  95. package/dist/index300.cjs +1 -1
  96. package/dist/index300.js +48 -38
  97. package/dist/index301.cjs +1 -1
  98. package/dist/index301.js +211 -14
  99. package/dist/index302.cjs +1 -1
  100. package/dist/index302.js +77 -38
  101. package/dist/index303.cjs +1 -1
  102. package/dist/index303.js +25 -316
  103. package/dist/index304.cjs +1 -1
  104. package/dist/index304.js +73 -602
  105. package/dist/index305.cjs +2 -1
  106. package/dist/index305.js +41 -109
  107. package/dist/index306.cjs +1 -1
  108. package/dist/index306.js +2 -168
  109. package/dist/index307.cjs +1 -1
  110. package/dist/index307.js +5 -301
  111. package/dist/index308.cjs +1 -1
  112. package/dist/index308.js +10 -93
  113. package/dist/index309.cjs +1 -1
  114. package/dist/index309.js +18 -55
  115. package/dist/index310.cjs +1 -1
  116. package/dist/index310.js +8 -53
  117. package/dist/index311.cjs +1 -1
  118. package/dist/index311.js +72 -44
  119. package/dist/index312.cjs +1 -1
  120. package/dist/index312.js +64 -14
  121. package/dist/index313.cjs +1 -1
  122. package/dist/index313.js +184 -313
  123. package/dist/index314.cjs +1 -1
  124. package/dist/index314.js +19 -56
  125. package/dist/index315.cjs +1 -1
  126. package/dist/index315.js +42 -19
  127. package/dist/index316.cjs +1 -1
  128. package/dist/index316.js +23 -27
  129. package/dist/index317.cjs +1 -1
  130. package/dist/index317.js +90 -3
  131. package/dist/index318.cjs +1 -7
  132. package/dist/index318.js +33 -230
  133. package/dist/index319.cjs +1 -1
  134. package/dist/index319.js +17 -48
  135. package/dist/index320.cjs +1 -1
  136. package/dist/index320.js +11 -210
  137. package/dist/index321.cjs +1 -1
  138. package/dist/index321.js +7 -81
  139. package/dist/index322.cjs +1 -1
  140. package/dist/index322.js +36 -28
  141. package/dist/index323.cjs +1 -1
  142. package/dist/index323.js +15 -76
  143. package/dist/index326.cjs +1 -1
  144. package/dist/index326.js +1 -1
  145. package/dist/index327.cjs +1 -1
  146. package/dist/index327.js +1 -1
  147. package/dist/index333.cjs +1 -1
  148. package/dist/index333.js +2 -2
  149. package/dist/index334.cjs +1 -1
  150. package/dist/index334.js +2 -2
  151. package/dist/index340.cjs +1 -1
  152. package/dist/index340.js +1 -1
  153. package/dist/index341.cjs +1 -1
  154. package/dist/index341.js +1 -1
  155. package/dist/index343.cjs +1 -1
  156. package/dist/index343.js +1 -1
  157. package/dist/index346.cjs +1 -1
  158. package/dist/index346.js +1 -1
  159. package/dist/index347.cjs +1 -1
  160. package/dist/index347.js +1 -1
  161. package/dist/index348.cjs +1 -1
  162. package/dist/index348.js +3 -3
  163. package/dist/index349.cjs +1 -2
  164. package/dist/index349.js +4 -193
  165. package/dist/index350.cjs +2 -1
  166. package/dist/index350.js +168 -52
  167. package/dist/index351.cjs +1 -1
  168. package/dist/index351.js +65 -331
  169. package/dist/index352.cjs +1 -1
  170. package/dist/index352.js +332 -149
  171. package/dist/index353.cjs +1 -1
  172. package/dist/index353.js +161 -5
  173. package/dist/index354.cjs +1 -1
  174. package/dist/index354.js +5 -5
  175. package/dist/index357.cjs +1 -1
  176. package/dist/index357.js +8 -205
  177. package/dist/index359.cjs +1 -1
  178. package/dist/index359.js +205 -8
  179. package/dist/index360.cjs +1 -1
  180. package/dist/index360.js +94 -68
  181. package/dist/index361.cjs +1 -1
  182. package/dist/index361.js +28 -94
  183. package/dist/index362.cjs +1 -1
  184. package/dist/index362.js +147 -27
  185. package/dist/index363.cjs +1 -1
  186. package/dist/index363.js +324 -118
  187. package/dist/index364.cjs +1 -1
  188. package/dist/index364.js +72 -353
  189. package/dist/index365.cjs +1 -1
  190. package/dist/index365.js +29 -71
  191. package/dist/index366.cjs +1 -1
  192. package/dist/index366.js +5 -31
  193. package/dist/index367.cjs +1 -1
  194. package/dist/index367.js +275 -5
  195. package/dist/index368.cjs +1 -1
  196. package/dist/index368.js +171 -4
  197. package/dist/index369.cjs +1 -1
  198. package/dist/index369.js +10 -141
  199. package/dist/index370.cjs +1 -1
  200. package/dist/index370.js +105 -273
  201. package/dist/index371.cjs +1 -1
  202. package/dist/index371.js +10 -171
  203. package/dist/index372.cjs +1 -1
  204. package/dist/index372.js +69 -10
  205. package/dist/index373.cjs +1 -1
  206. package/dist/index373.js +3 -107
  207. package/dist/index374.cjs +1 -1
  208. package/dist/index374.js +140 -9
  209. package/dist/index375.cjs +1 -1
  210. package/dist/index375.js +4 -4
  211. package/dist/index376.cjs +1 -1
  212. package/dist/index376.js +2 -79
  213. package/dist/index377.cjs +1 -1
  214. package/dist/index377.js +79 -2
  215. package/dist/index379.cjs +1 -1
  216. package/dist/index379.js +1 -1
  217. package/dist/index380.cjs +1 -1
  218. package/dist/index380.js +1 -1
  219. package/dist/index381.cjs +1 -1
  220. package/dist/index381.js +2 -22
  221. package/dist/index382.cjs +1 -1
  222. package/dist/index382.js +22 -2
  223. package/dist/index385.cjs +1 -1
  224. package/dist/index385.js +2 -2
  225. package/dist/index77.cjs +1 -1
  226. package/dist/index77.js +13 -13
  227. package/dist/index99.cjs +1 -1
  228. package/dist/index99.js +1 -1
  229. package/dist/src/lib/store/swapStore.d.ts +1 -1
  230. package/package.json +5 -5
package/dist/index361.js CHANGED
@@ -1,97 +1,31 @@
1
- import { ulebDecode as r } from "./index362.js";
2
- class o {
3
- /**
4
- * @param {Uint8Array} data Data to use as a buffer.
5
- */
6
- constructor(t) {
7
- this.bytePosition = 0, this.dataView = new DataView(t.buffer, t.byteOffset, t.byteLength);
8
- }
9
- /**
10
- * Shift current cursor position by `bytes`.
11
- *
12
- * @param {Number} bytes Number of bytes to
13
- * @returns {this} Self for possible chaining.
14
- */
15
- shift(t) {
16
- return this.bytePosition += t, this;
17
- }
18
- /**
19
- * Read U8 value from the buffer and shift cursor by 1.
20
- * @returns
21
- */
22
- read8() {
23
- const t = this.dataView.getUint8(this.bytePosition);
24
- return this.shift(1), t;
25
- }
26
- /**
27
- * Read U16 value from the buffer and shift cursor by 2.
28
- * @returns
29
- */
30
- read16() {
31
- const t = this.dataView.getUint16(this.bytePosition, !0);
32
- return this.shift(2), t;
33
- }
34
- /**
35
- * Read U32 value from the buffer and shift cursor by 4.
36
- * @returns
37
- */
38
- read32() {
39
- const t = this.dataView.getUint32(this.bytePosition, !0);
40
- return this.shift(4), t;
41
- }
42
- /**
43
- * Read U64 value from the buffer and shift cursor by 8.
44
- * @returns
45
- */
46
- read64() {
47
- const t = this.read32(), e = this.read32().toString(16) + t.toString(16).padStart(8, "0");
48
- return BigInt("0x" + e).toString(10);
49
- }
50
- /**
51
- * Read U128 value from the buffer and shift cursor by 16.
52
- */
53
- read128() {
54
- const t = BigInt(this.read64()), e = BigInt(this.read64()).toString(16) + t.toString(16).padStart(16, "0");
55
- return BigInt("0x" + e).toString(10);
56
- }
57
- /**
58
- * Read U128 value from the buffer and shift cursor by 32.
59
- * @returns
60
- */
61
- read256() {
62
- const t = BigInt(this.read128()), e = BigInt(this.read128()).toString(16) + t.toString(16).padStart(32, "0");
63
- return BigInt("0x" + e).toString(10);
64
- }
65
- /**
66
- * Read `num` number of bytes from the buffer and shift cursor by `num`.
67
- * @param num Number of bytes to read.
68
- */
69
- readBytes(t) {
70
- const i = this.bytePosition + this.dataView.byteOffset, e = new Uint8Array(this.dataView.buffer, i, t);
71
- return this.shift(t), e;
72
- }
73
- /**
74
- * Read ULEB value - an integer of varying size. Used for enum indexes and
75
- * vector lengths.
76
- * @returns {Number} The ULEB value.
77
- */
78
- readULEB() {
79
- const t = this.bytePosition + this.dataView.byteOffset, i = new Uint8Array(this.dataView.buffer, t), { value: e, length: s } = r(i);
80
- return this.shift(s), e;
81
- }
82
- /**
83
- * Read a BCS vector: read a length and then apply function `cb` X times
84
- * where X is the length of the vector, defined as ULEB in BCS bytes.
85
- * @param cb Callback to process elements of vector.
86
- * @returns {Array<Any>} Array of the resulting values, returned by callback.
87
- */
88
- readVec(t) {
89
- const i = this.readULEB(), e = [];
90
- for (let s = 0; s < i; s++)
91
- e.push(t(this, s, i));
92
- return e;
93
- }
1
+ function l(t) {
2
+ let e = BigInt(t);
3
+ const n = [];
4
+ let r = 0;
5
+ if (e === 0n)
6
+ return [0];
7
+ for (; e > 0; )
8
+ n[r] = Number(e & 0x7fn), e >>= 7n, e > 0n && (n[r] |= 128), r += 1;
9
+ return n;
10
+ }
11
+ function u(t) {
12
+ let e = 0n, n = 0n, r = 0;
13
+ for (; ; ) {
14
+ if (r >= t.length)
15
+ throw new Error("ULEB decode error: buffer overflow");
16
+ const o = t[r];
17
+ if (r += 1, e += BigInt(o & 127) << n, !(o & 128))
18
+ break;
19
+ n += 7n;
20
+ }
21
+ if (e > BigInt(Number.MAX_SAFE_INTEGER))
22
+ throw new Error("ULEB decode error: value exceeds MAX_SAFE_INTEGER");
23
+ return {
24
+ value: Number(e),
25
+ length: r
26
+ };
94
27
  }
95
28
  export {
96
- o as BcsReader
29
+ u as ulebDecode,
30
+ l as ulebEncode
97
31
  };
package/dist/index362.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function l(n){let e=BigInt(n);const t=[];let r=0;if(e===0n)return[0];for(;e>0;)t[r]=Number(e&0x7fn),e>>=7n,e>0n&&(t[r]|=128),r+=1;return t}function u(n){let e=0n,t=0n,r=0;for(;;){if(r>=n.length)throw new Error("ULEB decode error: buffer overflow");const o=n[r];if(r+=1,e+=BigInt(o&127)<<t,!(o&128))break;t+=7n}if(e>BigInt(Number.MAX_SAFE_INTEGER))throw new Error("ULEB decode error: value exceeds MAX_SAFE_INTEGER");return{value:Number(e),length:r}}exports.ulebDecode=u;exports.ulebEncode=l;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("./index361.cjs"),o=require("./index297.cjs");class a{constructor({initialSize:t=1024,maxSize:i=1/0,allocateSize:e=1024}={}){this.bytePosition=0,this.size=t,this.maxSize=i,this.allocateSize=e,this.dataView=new DataView(new ArrayBuffer(t))}ensureSizeOrGrow(t){const i=this.bytePosition+t;if(i>this.size){const e=Math.min(this.maxSize,Math.max(this.size+i,this.size+this.allocateSize));if(i>e)throw new Error(`Attempting to serialize to BCS, but buffer does not have enough size. Allocated size: ${this.size}, Max size: ${this.maxSize}, Required size: ${i}`);this.size=e;const s=new ArrayBuffer(this.size);new Uint8Array(s).set(new Uint8Array(this.dataView.buffer)),this.dataView=new DataView(s)}}shift(t){return this.bytePosition+=t,this}write8(t){return this.ensureSizeOrGrow(1),this.dataView.setUint8(this.bytePosition,Number(t)),this.shift(1)}writeBytes(t){this.ensureSizeOrGrow(t.length);for(let i=0;i<t.length;i++)this.dataView.setUint8(this.bytePosition+i,t[i]);return this.shift(t.length)}write16(t){return this.ensureSizeOrGrow(2),this.dataView.setUint16(this.bytePosition,Number(t),!0),this.shift(2)}write32(t){return this.ensureSizeOrGrow(4),this.dataView.setUint32(this.bytePosition,Number(t),!0),this.shift(4)}write64(t){return n(BigInt(t),8).forEach(i=>this.write8(i)),this}write128(t){return n(BigInt(t),16).forEach(i=>this.write8(i)),this}write256(t){return n(BigInt(t),32).forEach(i=>this.write8(i)),this}writeULEB(t){return h.ulebEncode(t).forEach(i=>this.write8(i)),this}writeVec(t,i){return this.writeULEB(t.length),Array.from(t).forEach((e,s)=>i(this,e,s,t.length)),this}*[Symbol.iterator](){for(let t=0;t<this.bytePosition;t++)yield this.dataView.getUint8(t);return this.toBytes()}toBytes(){return new Uint8Array(this.dataView.buffer.slice(0,this.bytePosition))}toString(t){return o.encodeStr(this.toBytes(),t)}}function n(r,t){const i=new Uint8Array(t);let e=0;for(;r>0;)i[e]=Number(r%BigInt(256)),r=r/BigInt(256),e+=1;return i}exports.BcsWriter=a;
package/dist/index362.js CHANGED
@@ -1,31 +1,151 @@
1
- function l(t) {
2
- let e = BigInt(t);
3
- const n = [];
4
- let r = 0;
5
- if (e === 0n)
6
- return [0];
7
- for (; e > 0; )
8
- n[r] = Number(e & 0x7fn), e >>= 7n, e > 0n && (n[r] |= 128), r += 1;
9
- return n;
1
+ import { ulebEncode as n } from "./index361.js";
2
+ import { encodeStr as o } from "./index297.js";
3
+ class u {
4
+ constructor({
5
+ initialSize: t = 1024,
6
+ maxSize: i = 1 / 0,
7
+ allocateSize: e = 1024
8
+ } = {}) {
9
+ this.bytePosition = 0, this.size = t, this.maxSize = i, this.allocateSize = e, this.dataView = new DataView(new ArrayBuffer(t));
10
+ }
11
+ ensureSizeOrGrow(t) {
12
+ const i = this.bytePosition + t;
13
+ if (i > this.size) {
14
+ const e = Math.min(
15
+ this.maxSize,
16
+ Math.max(this.size + i, this.size + this.allocateSize)
17
+ );
18
+ if (i > e)
19
+ throw new Error(
20
+ `Attempting to serialize to BCS, but buffer does not have enough size. Allocated size: ${this.size}, Max size: ${this.maxSize}, Required size: ${i}`
21
+ );
22
+ this.size = e;
23
+ const s = new ArrayBuffer(this.size);
24
+ new Uint8Array(s).set(new Uint8Array(this.dataView.buffer)), this.dataView = new DataView(s);
25
+ }
26
+ }
27
+ /**
28
+ * Shift current cursor position by `bytes`.
29
+ *
30
+ * @param {Number} bytes Number of bytes to
31
+ * @returns {this} Self for possible chaining.
32
+ */
33
+ shift(t) {
34
+ return this.bytePosition += t, this;
35
+ }
36
+ /**
37
+ * Write a U8 value into a buffer and shift cursor position by 1.
38
+ * @param {Number} value Value to write.
39
+ * @returns {this}
40
+ */
41
+ write8(t) {
42
+ return this.ensureSizeOrGrow(1), this.dataView.setUint8(this.bytePosition, Number(t)), this.shift(1);
43
+ }
44
+ /**
45
+ * Write a U8 value into a buffer and shift cursor position by 1.
46
+ * @param {Number} value Value to write.
47
+ * @returns {this}
48
+ */
49
+ writeBytes(t) {
50
+ this.ensureSizeOrGrow(t.length);
51
+ for (let i = 0; i < t.length; i++)
52
+ this.dataView.setUint8(this.bytePosition + i, t[i]);
53
+ return this.shift(t.length);
54
+ }
55
+ /**
56
+ * Write a U16 value into a buffer and shift cursor position by 2.
57
+ * @param {Number} value Value to write.
58
+ * @returns {this}
59
+ */
60
+ write16(t) {
61
+ return this.ensureSizeOrGrow(2), this.dataView.setUint16(this.bytePosition, Number(t), !0), this.shift(2);
62
+ }
63
+ /**
64
+ * Write a U32 value into a buffer and shift cursor position by 4.
65
+ * @param {Number} value Value to write.
66
+ * @returns {this}
67
+ */
68
+ write32(t) {
69
+ return this.ensureSizeOrGrow(4), this.dataView.setUint32(this.bytePosition, Number(t), !0), this.shift(4);
70
+ }
71
+ /**
72
+ * Write a U64 value into a buffer and shift cursor position by 8.
73
+ * @param {bigint} value Value to write.
74
+ * @returns {this}
75
+ */
76
+ write64(t) {
77
+ return h(BigInt(t), 8).forEach((i) => this.write8(i)), this;
78
+ }
79
+ /**
80
+ * Write a U128 value into a buffer and shift cursor position by 16.
81
+ *
82
+ * @param {bigint} value Value to write.
83
+ * @returns {this}
84
+ */
85
+ write128(t) {
86
+ return h(BigInt(t), 16).forEach((i) => this.write8(i)), this;
87
+ }
88
+ /**
89
+ * Write a U256 value into a buffer and shift cursor position by 16.
90
+ *
91
+ * @param {bigint} value Value to write.
92
+ * @returns {this}
93
+ */
94
+ write256(t) {
95
+ return h(BigInt(t), 32).forEach((i) => this.write8(i)), this;
96
+ }
97
+ /**
98
+ * Write a ULEB value into a buffer and shift cursor position by number of bytes
99
+ * written.
100
+ * @param {Number} value Value to write.
101
+ * @returns {this}
102
+ */
103
+ writeULEB(t) {
104
+ return n(t).forEach((i) => this.write8(i)), this;
105
+ }
106
+ /**
107
+ * Write a vector into a buffer by first writing the vector length and then calling
108
+ * a callback on each passed value.
109
+ *
110
+ * @param {Array<Any>} vector Array of elements to write.
111
+ * @param {WriteVecCb} cb Callback to call on each element of the vector.
112
+ * @returns {this}
113
+ */
114
+ writeVec(t, i) {
115
+ return this.writeULEB(t.length), Array.from(t).forEach((e, s) => i(this, e, s, t.length)), this;
116
+ }
117
+ /**
118
+ * Adds support for iterations over the object.
119
+ * @returns {Uint8Array}
120
+ */
121
+ // oxlint-disable-next-line require-yields
122
+ *[Symbol.iterator]() {
123
+ for (let t = 0; t < this.bytePosition; t++)
124
+ yield this.dataView.getUint8(t);
125
+ return this.toBytes();
126
+ }
127
+ /**
128
+ * Get underlying buffer taking only value bytes (in case initial buffer size was bigger).
129
+ * @returns {Uint8Array} Resulting bcs.
130
+ */
131
+ toBytes() {
132
+ return new Uint8Array(this.dataView.buffer.slice(0, this.bytePosition));
133
+ }
134
+ /**
135
+ * Represent data as 'hex' or 'base64'
136
+ * @param encoding Encoding to use: 'base64' or 'hex'
137
+ */
138
+ toString(t) {
139
+ return o(this.toBytes(), t);
140
+ }
10
141
  }
11
- function u(t) {
12
- let e = 0n, n = 0n, r = 0;
13
- for (; ; ) {
14
- if (r >= t.length)
15
- throw new Error("ULEB decode error: buffer overflow");
16
- const o = t[r];
17
- if (r += 1, e += BigInt(o & 127) << n, !(o & 128))
18
- break;
19
- n += 7n;
20
- }
21
- if (e > BigInt(Number.MAX_SAFE_INTEGER))
22
- throw new Error("ULEB decode error: value exceeds MAX_SAFE_INTEGER");
23
- return {
24
- value: Number(e),
25
- length: r
26
- };
142
+ function h(r, t) {
143
+ const i = new Uint8Array(t);
144
+ let e = 0;
145
+ for (; r > 0; )
146
+ i[e] = Number(r % BigInt(256)), r = r / BigInt(256), e += 1;
147
+ return i;
27
148
  }
28
149
  export {
29
- u as ulebDecode,
30
- l as ulebEncode
150
+ u as BcsWriter
31
151
  };
package/dist/index363.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("./index362.cjs"),o=require("./index316.cjs");class a{constructor({initialSize:t=1024,maxSize:i=1/0,allocateSize:e=1024}={}){this.bytePosition=0,this.size=t,this.maxSize=i,this.allocateSize=e,this.dataView=new DataView(new ArrayBuffer(t))}ensureSizeOrGrow(t){const i=this.bytePosition+t;if(i>this.size){const e=Math.min(this.maxSize,Math.max(this.size+i,this.size+this.allocateSize));if(i>e)throw new Error(`Attempting to serialize to BCS, but buffer does not have enough size. Allocated size: ${this.size}, Max size: ${this.maxSize}, Required size: ${i}`);this.size=e;const s=new ArrayBuffer(this.size);new Uint8Array(s).set(new Uint8Array(this.dataView.buffer)),this.dataView=new DataView(s)}}shift(t){return this.bytePosition+=t,this}write8(t){return this.ensureSizeOrGrow(1),this.dataView.setUint8(this.bytePosition,Number(t)),this.shift(1)}writeBytes(t){this.ensureSizeOrGrow(t.length);for(let i=0;i<t.length;i++)this.dataView.setUint8(this.bytePosition+i,t[i]);return this.shift(t.length)}write16(t){return this.ensureSizeOrGrow(2),this.dataView.setUint16(this.bytePosition,Number(t),!0),this.shift(2)}write32(t){return this.ensureSizeOrGrow(4),this.dataView.setUint32(this.bytePosition,Number(t),!0),this.shift(4)}write64(t){return n(BigInt(t),8).forEach(i=>this.write8(i)),this}write128(t){return n(BigInt(t),16).forEach(i=>this.write8(i)),this}write256(t){return n(BigInt(t),32).forEach(i=>this.write8(i)),this}writeULEB(t){return h.ulebEncode(t).forEach(i=>this.write8(i)),this}writeVec(t,i){return this.writeULEB(t.length),Array.from(t).forEach((e,s)=>i(this,e,s,t.length)),this}*[Symbol.iterator](){for(let t=0;t<this.bytePosition;t++)yield this.dataView.getUint8(t);return this.toBytes()}toBytes(){return new Uint8Array(this.dataView.buffer.slice(0,this.bytePosition))}toString(t){return o.encodeStr(this.toBytes(),t)}}function n(r,t){const i=new Uint8Array(t);let e=0;for(;r>0;)i[e]=Number(r%BigInt(256)),r=r/BigInt(256),e+=1;return i}exports.BcsWriter=a;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("./index284.cjs"),m=require("./index361.cjs");function y(e,r,a){return new d.BcsType({read:t=>{const n=new Array(e);for(let u=0;u<e;u++)n[u]=r.read(t);return n},write:(t,n)=>{for(const u of t)r.write(u,n)},...a,name:(a==null?void 0:a.name)??`${r.name}[${e}]`,validate:t=>{var n;if((n=a==null?void 0:a.validate)==null||n.call(a,t),!t||typeof t!="object"||!("length"in t))throw new TypeError(`Expected array, found ${typeof t}`);if(t.length!==e)throw new TypeError(`Expected array of length ${e}, found ${t.length}`)}})}function w(e){return c.enum(`Option<${e.name}>`,{None:null,Some:e}).transform({input:r=>r==null?{None:!0}:{Some:r},output:r=>r.$kind==="Some"?r.Some:null})}function f(e,r){return new d.BcsType({read:a=>{const t=a.readULEB(),n=new Array(t);for(let u=0;u<t;u++)n[u]=e.read(a);return n},write:(a,t)=>{t.writeULEB(a.length);for(const n of a)e.write(n,t)},...r,name:(r==null?void 0:r.name)??`vector<${e.name}>`,validate:a=>{var t;if((t=r==null?void 0:r.validate)==null||t.call(r,a),!a||typeof a!="object"||!("length"in a))throw new TypeError(`Expected array, found ${typeof a}`)}})}function l(e,r){return c.vector(c.tuple([e,r])).transform({name:`Map<${e.name}, ${r.name}>`,input:a=>[...a.entries()],output:a=>{const t=new Map;for(const[n,u]of a)t.set(n,u);return t}})}const c={u8(e){return d.uIntBcsType({readMethod:"read8",writeMethod:"write8",size:1,maxValue:2**8-1,...e,name:(e==null?void 0:e.name)??"u8"})},u16(e){return d.uIntBcsType({readMethod:"read16",writeMethod:"write16",size:2,maxValue:2**16-1,...e,name:(e==null?void 0:e.name)??"u16"})},u32(e){return d.uIntBcsType({readMethod:"read32",writeMethod:"write32",size:4,maxValue:2**32-1,...e,name:(e==null?void 0:e.name)??"u32"})},u64(e){return d.bigUIntBcsType({readMethod:"read64",writeMethod:"write64",size:8,maxValue:2n**64n-1n,...e,name:(e==null?void 0:e.name)??"u64"})},u128(e){return d.bigUIntBcsType({readMethod:"read128",writeMethod:"write128",size:16,maxValue:2n**128n-1n,...e,name:(e==null?void 0:e.name)??"u128"})},u256(e){return d.bigUIntBcsType({readMethod:"read256",writeMethod:"write256",size:32,maxValue:2n**256n-1n,...e,name:(e==null?void 0:e.name)??"u256"})},bool(e){return d.fixedSizeBcsType({size:1,read:r=>r.read8()===1,write:(r,a)=>a.write8(r?1:0),...e,name:(e==null?void 0:e.name)??"bool",validate:r=>{var a;if((a=e==null?void 0:e.validate)==null||a.call(e,r),typeof r!="boolean")throw new TypeError(`Expected boolean, found ${typeof r}`)}})},uleb128(e){return d.dynamicSizeBcsType({read:r=>r.readULEB(),serialize:r=>Uint8Array.from(m.ulebEncode(r)),...e,name:(e==null?void 0:e.name)??"uleb128"})},bytes(e,r){return d.fixedSizeBcsType({size:e,read:a=>a.readBytes(e),write:(a,t)=>{t.writeBytes(new Uint8Array(a))},...r,name:(r==null?void 0:r.name)??`bytes[${e}]`,validate:a=>{var t;if((t=r==null?void 0:r.validate)==null||t.call(r,a),!a||typeof a!="object"||!("length"in a))throw new TypeError(`Expected array, found ${typeof a}`);if(a.length!==e)throw new TypeError(`Expected array of length ${e}, found ${a.length}`)}})},byteVector(e){return new d.BcsType({read:r=>{const a=r.readULEB();return r.readBytes(a)},write:(r,a)=>{const t=new Uint8Array(r);a.writeULEB(t.length),a.writeBytes(t)},...e,name:(e==null?void 0:e.name)??"vector<u8>",serializedSize:r=>{const a="length"in r?r.length:null;return a==null?null:m.ulebEncode(a).length+a},validate:r=>{var a;if((a=e==null?void 0:e.validate)==null||a.call(e,r),!r||typeof r!="object"||!("length"in r))throw new TypeError(`Expected array, found ${typeof r}`)}})},string(e){return d.stringLikeBcsType({toBytes:r=>new TextEncoder().encode(r),fromBytes:r=>new TextDecoder().decode(r),...e,name:(e==null?void 0:e.name)??"string"})},fixedArray:y,option:w,vector:f,tuple(e,r){return new d.BcsTuple({fields:e,...r})},struct(e,r,a){return new d.BcsStruct({name:e,fields:r,...a})},enum(e,r,a){return new d.BcsEnum({name:e,fields:r,...a})},map:l,lazy(e){return d.lazyBcsType(e)}};exports.bcs=c;