@interest-protocol/vortex-sdk 7.1.0 → 7.3.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.
@@ -59,4 +59,5 @@ export declare const parseVortexPool: (data: SuiObjectData) => {
59
59
  export * from './events';
60
60
  export * from './prove';
61
61
  export * from './decrypt';
62
+ export * from './validate';
62
63
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGpD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAKnD,MAAM,MAAM,UAAU,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;AAE5C,wBAAgB,aAAa,CAC3B,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,IAAI,GAAG,IAAI,GAChB,UAAU,CAkEZ;AAED,UAAU,gBAAgB;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,UAAU,CAAC;IACxB,WAAW,EAAE,UAAU,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,aAAa,CAAC;IAC7B,UAAU,EAAE,IAAI,CAAC;IACjB,UAAU,EAAE,IAAI,CAAC;IACjB,WAAW,EAAE,IAAI,CAAC;IAClB,WAAW,EAAE,IAAI,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,eAAO,MAAM,YAAY,GAAI,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,eAAe,GAAI,MAAM,aAAa;;;;;;;CAelD,CAAC;AAEF,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare function validateDepositWithAccountCommands(commands: object[]): void;
2
+ export declare function validateWithdrawCommands(commands: object[]): void;
3
+ //# sourceMappingURL=validate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/utils/validate.ts"],"names":[],"mappings":"AA8MA,wBAAgB,kCAAkC,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,CAE3E;AAED,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,CAEjE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@interest-protocol/vortex-sdk",
3
- "version": "7.1.0",
3
+ "version": "7.3.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "module": "./dist/index.mjs",
@@ -37,8 +37,8 @@
37
37
  "rimraf": "^6.0.1",
38
38
  "ts-jest": "^29.1.1",
39
39
  "tsup": "^8.3.5",
40
- "@interest-protocol/prettier-config": "1.0.0",
41
- "@interest-protocol/typescript-config": "1.0.0"
40
+ "@interest-protocol/typescript-config": "1.0.0",
41
+ "@interest-protocol/prettier-config": "1.0.0"
42
42
  },
43
43
  "publishConfig": {
44
44
  "access": "public",
@@ -178,3 +178,4 @@ export const parseVortexPool = (data: SuiObjectData) => {
178
178
  export * from './events';
179
179
  export * from './prove';
180
180
  export * from './decrypt';
181
+ export * from './validate';
@@ -0,0 +1,213 @@
1
+ import { normalizeSuiAddress, SUI_FRAMEWORK_ADDRESS } from '@mysten/sui/utils';
2
+ import invariant from 'tiny-invariant';
3
+ import { VORTEX_PACKAGE_ID } from '../constants';
4
+
5
+ interface MoveCall {
6
+ package: string;
7
+ module: string;
8
+ function: string;
9
+ typeArguments: string[];
10
+ arguments: object[];
11
+ }
12
+
13
+ interface ExpectedCommand {
14
+ MoveCall?: {
15
+ package: string;
16
+ module: string;
17
+ function: string;
18
+ arguments: object[];
19
+ };
20
+ MakeMoveVec?: {
21
+ elements?: object[];
22
+ };
23
+ TransferObjects?: {
24
+ objects: object[];
25
+ address?: object;
26
+ };
27
+ }
28
+
29
+ const EXPECTED_DEPOSIT_WITH_ACCOUNT_COMMANDS: ExpectedCommand[] = [
30
+ {
31
+ MoveCall: {
32
+ package: VORTEX_PACKAGE_ID,
33
+ module: 'vortex_ext_data',
34
+ function: 'new',
35
+ arguments: [
36
+ { Input: 0 },
37
+ { Input: 1 },
38
+ { Input: 2 },
39
+ { Input: 3 },
40
+ { Input: 4 },
41
+ { Input: 5 },
42
+ ],
43
+ },
44
+ },
45
+ {
46
+ MoveCall: {
47
+ package: VORTEX_PACKAGE_ID,
48
+ module: 'vortex_proof',
49
+ function: 'new',
50
+ arguments: [
51
+ { Input: 6 },
52
+ { Input: 7 },
53
+ { Input: 8 },
54
+ { Input: 9 },
55
+ { Input: 10 },
56
+ { Input: 11 },
57
+ { Input: 12 },
58
+ { Input: 13 },
59
+ ],
60
+ },
61
+ },
62
+ {
63
+ MakeMoveVec: {},
64
+ },
65
+ {
66
+ MoveCall: {
67
+ package: VORTEX_PACKAGE_ID,
68
+ module: 'vortex',
69
+ function: 'transact_with_account',
70
+ arguments: [
71
+ { Input: 14 },
72
+ { Input: 15 },
73
+ { Result: 2 },
74
+ { Result: 1 },
75
+ { Result: 0 },
76
+ ],
77
+ },
78
+ },
79
+ {
80
+ TransferObjects: {
81
+ objects: [{ Result: 3 }],
82
+ },
83
+ },
84
+ ];
85
+
86
+ const EXPECTED_WITHDRAW_COMMANDS: ExpectedCommand[] = [
87
+ {
88
+ MoveCall: {
89
+ package: VORTEX_PACKAGE_ID,
90
+ module: 'vortex_ext_data',
91
+ function: 'new',
92
+ arguments: [
93
+ { Input: 0 },
94
+ { Input: 1 },
95
+ { Input: 2 },
96
+ { Input: 3 },
97
+ { Input: 4 },
98
+ { Input: 5 },
99
+ ],
100
+ },
101
+ },
102
+ {
103
+ MoveCall: {
104
+ package: VORTEX_PACKAGE_ID,
105
+ module: 'vortex_proof',
106
+ function: 'new',
107
+ arguments: [
108
+ { Input: 6 },
109
+ { Input: 7 },
110
+ { Input: 8 },
111
+ { Input: 9 },
112
+ { Input: 10 },
113
+ { Input: 11 },
114
+ { Input: 12 },
115
+ { Input: 13 },
116
+ ],
117
+ },
118
+ },
119
+ {
120
+ MoveCall: {
121
+ package: SUI_FRAMEWORK_ADDRESS,
122
+ module: 'coin',
123
+ function: 'zero',
124
+ arguments: [],
125
+ },
126
+ },
127
+ {
128
+ MoveCall: {
129
+ package: VORTEX_PACKAGE_ID,
130
+ module: 'vortex',
131
+ function: 'transact',
132
+ arguments: [
133
+ { Input: 14 },
134
+ { Result: 2 },
135
+ { Result: 1 },
136
+ { Result: 0 },
137
+ ],
138
+ },
139
+ },
140
+ {
141
+ TransferObjects: {
142
+ objects: [{ Result: 3 }],
143
+ },
144
+ },
145
+ ];
146
+
147
+ function validateCommands(
148
+ commands: object[],
149
+ expectedCommands: ExpectedCommand[]
150
+ ): void {
151
+ invariant(
152
+ commands.length === expectedCommands.length,
153
+ `Expected ${expectedCommands.length} commands, got ${commands.length}`
154
+ );
155
+
156
+ for (let i = 0; i < commands.length; i++) {
157
+ const actual = commands[i] as Record<string, unknown>;
158
+ const expected = expectedCommands[i]!;
159
+
160
+ if ('MoveCall' in expected && expected.MoveCall) {
161
+ invariant('MoveCall' in actual, `Command ${i}: Expected MoveCall`);
162
+ const actualMoveCall = actual.MoveCall as MoveCall;
163
+ const expectedMoveCall = expected.MoveCall;
164
+
165
+ invariant(
166
+ normalizeSuiAddress(actualMoveCall.package) ===
167
+ normalizeSuiAddress(expectedMoveCall.package),
168
+ `Command ${i}: Package mismatch. Expected ${expectedMoveCall.package}, got ${actualMoveCall.package}`
169
+ );
170
+ invariant(
171
+ actualMoveCall.module === expectedMoveCall.module,
172
+ `Command ${i}: Module mismatch. Expected ${expectedMoveCall.module}, got ${actualMoveCall.module}`
173
+ );
174
+ invariant(
175
+ actualMoveCall.function === expectedMoveCall.function,
176
+ `Command ${i}: Function mismatch. Expected ${expectedMoveCall.function}, got ${actualMoveCall.function}`
177
+ );
178
+ invariant(
179
+ JSON.stringify(actualMoveCall.arguments) ===
180
+ JSON.stringify(expectedMoveCall.arguments),
181
+ `Command ${i}: Arguments mismatch`
182
+ );
183
+ } else if ('MakeMoveVec' in expected && expected.MakeMoveVec) {
184
+ invariant('MakeMoveVec' in actual, `Command ${i}: Expected MakeMoveVec`);
185
+ // Skip detailed validation of MakeMoveVec elements as they vary based on coin count
186
+ } else if ('TransferObjects' in expected && expected.TransferObjects) {
187
+ invariant(
188
+ 'TransferObjects' in actual,
189
+ `Command ${i}: Expected TransferObjects`
190
+ );
191
+ const actualTransfer = actual.TransferObjects as {
192
+ objects: object[];
193
+ address: object;
194
+ };
195
+ const expectedTransfer = expected.TransferObjects;
196
+
197
+ invariant(
198
+ JSON.stringify(actualTransfer.objects) ===
199
+ JSON.stringify(expectedTransfer.objects),
200
+ `Command ${i}: TransferObjects objects mismatch`
201
+ );
202
+ // Skip address validation as input index varies based on coin count
203
+ }
204
+ }
205
+ }
206
+
207
+ export function validateDepositWithAccountCommands(commands: object[]): void {
208
+ validateCommands(commands, EXPECTED_DEPOSIT_WITH_ACCOUNT_COMMANDS);
209
+ }
210
+
211
+ export function validateWithdrawCommands(commands: object[]): void {
212
+ validateCommands(commands, EXPECTED_WITHDRAW_COMMANDS);
213
+ }