@paradex/sdk 0.6.0 → 0.8.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.
@@ -1,4 +1,16 @@
1
1
  import * as Starknet from 'starknet';
2
+ // Class hashes for different account types
3
+ const ARGENT_V0_3_0_CLASS_HASH = '0x1a736d6ed154502257f02b1ccdf4d9d1089f80811cd6acad48e6b6a9d1f2003';
4
+ const ARGENT_V0_3_1_CLASS_HASH = '0x29927c8af6bccf3f6fda035981e765a7bdbf18a2dc0d630494f8758aa908e2b';
5
+ const ARGENT_V0_4_0_CLASS_HASH = '0x036078334509b514626504edc9fb252328d1a240e4e948bef8d0c08dff45927f';
6
+ const ARGENT_MULTICALL_CLASS_HASH = '0x0381f14e5e0db5889c981bf050fb034c0fbe0c4f070ee79346a05dbe2bf2af90';
7
+ const ARGENT_MULTISIG_V0_1_0_CLASS_HASH = '0x737ee2f87ce571a58c6c8da558ec18a07ceb64a6172d5ec46171fbc80077a48';
8
+ const ARGENT_MULTISIG_V0_1_1_CLASS_HASH = '0x6e150953b26271a740bf2b6e9bca17cc52c68d765f761295de51ceb8526ee72';
9
+ const ARGENT_MULTISIG_V0_2_0_CLASS_HASH = '0x07aeca3456816e3b833506d7cc5c1313d371fbdb0ae95ee70af72a4ddbf42594';
10
+ const BRAAVOS_MULTI_OWNER_V1_0_0_CLASS_HASH = '0x041bf1e71792aecb9df3e9d04e1540091c5e13122a731e02bec588f71dc1a5c3';
11
+ const BRAAVOS_V1_0_0_CLASS_HASH = '0x00816dd0297efc55dc1e7559020a3a825e81ef734b558f03c83325d4da7e6253';
12
+ const BRAAVOS_V1_1_0_CLASS_HASH = '0x02c8c7e6fbcfb3e8e15a46648e8914c6aa1fc506fc1e7fb3d1e19630716174bc';
13
+ const BRAAVOS_V1_2_0_CLASS_HASH = '0x03957f9f5a1cbfe918cedc2015c85200ca51a5f7506ecb6de98a5207b759bf8a';
2
14
  export class AccountSupport {
3
15
  constructor(
4
16
  /** The contract instance of the account. */
@@ -14,13 +26,13 @@ export class AccountSupport {
14
26
  return this.classHash === Starknet.num.cleanHex(classHash);
15
27
  }
16
28
  async getFormat() {
17
- if (this.testClassHash('0x1a736d6ed154502257f02b1ccdf4d9d1089f80811cd6acad48e6b6a9d1f2003')) {
29
+ if (this.testClassHash(ARGENT_V0_3_0_CLASS_HASH)) {
18
30
  return 'argent-v0.3.0';
19
31
  }
20
- if (this.testClassHash('0x29927c8af6bccf3f6fda035981e765a7bdbf18a2dc0d630494f8758aa908e2b')) {
32
+ if (this.testClassHash(ARGENT_V0_3_1_CLASS_HASH)) {
21
33
  return 'argent-v0.3.1';
22
34
  }
23
- if (this.testClassHash('0x036078334509b514626504edc9fb252328d1a240e4e948bef8d0c08dff45927f')) {
35
+ if (this.testClassHash(ARGENT_V0_4_0_CLASS_HASH)) {
24
36
  const ownerTypeResp = (await this.contract.call('get_owner_type'));
25
37
  const ownerType = ownerTypeResp.activeVariant();
26
38
  switch (ownerType) {
@@ -38,24 +50,24 @@ export class AccountSupport {
38
50
  return 'unknown';
39
51
  }
40
52
  }
41
- if (this.testClassHash('0x0381f14e5e0db5889c981bf050fb034c0fbe0c4f070ee79346a05dbe2bf2af90')) {
53
+ if (this.testClassHash(ARGENT_MULTICALL_CLASS_HASH)) {
42
54
  return 'argent-multicall';
43
55
  }
44
- if (this.testClassHash('0x737ee2f87ce571a58c6c8da558ec18a07ceb64a6172d5ec46171fbc80077a48')) {
56
+ if (this.testClassHash(ARGENT_MULTISIG_V0_1_0_CLASS_HASH)) {
45
57
  return 'argent-multisig-v0.1.0';
46
58
  }
47
- if (this.testClassHash('0x6e150953b26271a740bf2b6e9bca17cc52c68d765f761295de51ceb8526ee72')) {
59
+ if (this.testClassHash(ARGENT_MULTISIG_V0_1_1_CLASS_HASH)) {
48
60
  return 'argent-multisig-v0.1.1';
49
61
  }
50
- if (this.testClassHash('0x07aeca3456816e3b833506d7cc5c1313d371fbdb0ae95ee70af72a4ddbf42594')) {
62
+ if (this.testClassHash(ARGENT_MULTISIG_V0_2_0_CLASS_HASH)) {
51
63
  return 'argent-multisig-v0.2.0';
52
64
  }
53
65
  // https://github.com/myBraavos/braavos-account-cairo/blob/6efdfd597bb051e99c79a512fccd14ee2523c898/README_MOA.md
54
- if (this.testClassHash('0x041bf1e71792aecb9df3e9d04e1540091c5e13122a731e02bec588f71dc1a5c3')) {
66
+ if (this.testClassHash(BRAAVOS_MULTI_OWNER_V1_0_0_CLASS_HASH)) {
55
67
  return 'braavos-multi-owner-v1.0.0';
56
68
  }
57
69
  // https://github.com/myBraavos/braavos-account-cairo/tree/v1.0.0
58
- if (this.testClassHash('0x00816dd0297efc55dc1e7559020a3a825e81ef734b558f03c83325d4da7e6253')) {
70
+ if (this.testClassHash(BRAAVOS_V1_0_0_CLASS_HASH)) {
59
71
  const multiSigThreshold = (await this.contract.call('get_multisig_threshold'));
60
72
  if (multiSigThreshold !== 0n) {
61
73
  return 'braavos-v1.0.0-multisig';
@@ -69,10 +81,8 @@ export class AccountSupport {
69
81
  return 'braavos-v1.0.0-stark-signer';
70
82
  return 'unknown';
71
83
  }
72
- // New Braavos account contract, not available on GitHub
73
- // Reported to be an upgrade to the previous Braavos account contract
74
- // https://tradeparadigm.slack.com/archives/C06TRUBLSDB/p1731706968018819?thread_ts=1720108178.898199&cid=C06TRUBLSDB
75
- if (this.testClassHash('0x02c8c7e6fbcfb3e8e15a46648e8914c6aa1fc506fc1e7fb3d1e19630716174bc')) {
84
+ // https://github.com/myBraavos/braavos-account-cairo/tree/v1.1.0
85
+ if (this.testClassHash(BRAAVOS_V1_1_0_CLASS_HASH)) {
76
86
  const multiSigThreshold = (await this.contract.call('get_multisig_threshold'));
77
87
  if (multiSigThreshold !== 0n) {
78
88
  return 'braavos-v1.1.0-multisig';
@@ -86,6 +96,21 @@ export class AccountSupport {
86
96
  return 'braavos-v1.1.0-stark-signer';
87
97
  return 'unknown';
88
98
  }
99
+ // https://github.com/myBraavos/braavos-account-cairo/tree/v1.2.0
100
+ if (this.testClassHash(BRAAVOS_V1_2_0_CLASS_HASH)) {
101
+ const multiSigThreshold = (await this.contract.call('get_multisig_threshold'));
102
+ if (multiSigThreshold !== 0n) {
103
+ return 'braavos-v1.2.0-multisig';
104
+ }
105
+ const signers = (await this.contract.call('get_signers'));
106
+ if (signers.secp256r1 != null && signers.secp256r1.length > 0)
107
+ return 'braavos-v1.2.0-strong-signer';
108
+ if (signers.webauthn != null && signers.webauthn.length > 0)
109
+ return 'braavos-v1.2.0-strong-signer';
110
+ if (signers.stark != null && signers.stark.length === 1)
111
+ return 'braavos-v1.2.0-stark-signer';
112
+ return 'unknown';
113
+ }
89
114
  return 'unknown';
90
115
  }
91
116
  async check() {
@@ -96,6 +121,7 @@ export class AccountSupport {
96
121
  case 'argent-v0.4.0-starknet-signer':
97
122
  case 'braavos-v1.0.0-stark-signer':
98
123
  case 'braavos-v1.1.0-stark-signer':
124
+ case 'braavos-v1.2.0-stark-signer':
99
125
  return { ok: true };
100
126
  case 'argent-v0.4.0-secp256k1-signer':
101
127
  return {
@@ -131,12 +157,14 @@ export class AccountSupport {
131
157
  };
132
158
  case 'braavos-v1.0.0-strong-signer':
133
159
  case 'braavos-v1.1.0-strong-signer':
160
+ case 'braavos-v1.2.0-strong-signer':
134
161
  return {
135
162
  ok: false,
136
163
  reason: 'Braavos strong signer is not supported',
137
164
  };
138
165
  case 'braavos-v1.0.0-multisig':
139
166
  case 'braavos-v1.1.0-multisig':
167
+ case 'braavos-v1.2.0-multisig':
140
168
  return {
141
169
  ok: false,
142
170
  reason: 'Braavos multisig is not supported',
@@ -183,7 +211,8 @@ export class AccountSupport {
183
211
  throw new Error('Unsupported Argent signature');
184
212
  }
185
213
  case 'braavos-v1.0.0-stark-signer':
186
- case 'braavos-v1.1.0-stark-signer': {
214
+ case 'braavos-v1.1.0-stark-signer':
215
+ case 'braavos-v1.2.0-stark-signer': {
187
216
  if (segments.length === 2) {
188
217
  const [r, _s] = segments;
189
218
  if (r == null)
@@ -208,8 +237,10 @@ export class AccountSupport {
208
237
  case 'argent-multisig-v0.2.0':
209
238
  case 'braavos-v1.0.0-strong-signer':
210
239
  case 'braavos-v1.1.0-strong-signer':
240
+ case 'braavos-v1.2.0-strong-signer':
211
241
  case 'braavos-v1.0.0-multisig':
212
242
  case 'braavos-v1.1.0-multisig':
243
+ case 'braavos-v1.2.0-multisig':
213
244
  case 'braavos-multi-owner-v1.0.0':
214
245
  throw new Error(`${this.signatureFormat} is not supported`);
215
246
  case 'unknown':
@@ -89,6 +89,10 @@ async function getAccountClassHash(provider, accountAddress) {
89
89
  }
90
90
  async function buildAccountContract(provider, accountAddress) {
91
91
  const accountClass = await provider.getClassAt(accountAddress);
92
- const contract = new Starknet.Contract(accountClass.abi, accountAddress, provider);
92
+ const contract = new Starknet.Contract({
93
+ abi: accountClass.abi,
94
+ address: accountAddress,
95
+ providerOrAccount: provider,
96
+ });
93
97
  return contract;
94
98
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paradex/sdk",
3
- "version": "0.6.0",
3
+ "version": "0.8.0",
4
4
  "description": "JavaScript SDK for Paradex",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -11,7 +11,8 @@
11
11
  "build": "tsc",
12
12
  "lint": "prettier --check . && eslint .",
13
13
  "format": "prettier --write .",
14
- "test": "jest"
14
+ "test": "jest",
15
+ "example:withdrawal": "tsx examples/withdrawal-node.ts"
15
16
  },
16
17
  "lint-staged": {
17
18
  "**/*": "prettier --write --ignore-unknown"
@@ -28,28 +29,35 @@
28
29
  },
29
30
  "dependencies": {
30
31
  "@starkware-industries/starkware-crypto-utils": "^0.2.1",
31
- "bignumber.js": "^9.1.2",
32
- "starknet": "^5.24.3"
32
+ "bignumber.js": "^9.3.1",
33
+ "starknet": "^8.6.0"
33
34
  },
34
35
  "devDependencies": {
35
- "@ianvs/prettier-plugin-sort-imports": "^4.2.1",
36
+ "@ianvs/prettier-plugin-sort-imports": "^4.7.0",
36
37
  "@types/elliptic": "^6.4.18",
37
- "@types/jest": "^29.5.12",
38
+ "@types/jest": "^29.5.14",
38
39
  "@typescript-eslint/eslint-plugin": "6.21.0",
39
40
  "@typescript-eslint/parser": "6.21.0",
40
- "eslint": "^8.57.0",
41
+ "eslint": "^8.57.1",
41
42
  "eslint-config-love": "^43.1.0",
42
- "eslint-config-prettier": "^9.1.0",
43
- "eslint-plugin-import": "^2.29.1",
43
+ "eslint-config-prettier": "^9.1.2",
44
+ "eslint-plugin-import": "^2.32.0",
44
45
  "eslint-plugin-n": "^16.6.2 ",
45
46
  "eslint-plugin-promise": "^6.0.0",
46
- "ethers": "^6.11.1",
47
- "husky": "^9.0.11",
47
+ "ethers": "^6.15.0",
48
+ "husky": "^9.1.7",
48
49
  "jest": "^29.7.0",
49
- "jest-ts-webcompat-resolver": "^1.0.0",
50
- "lint-staged": "^15.2.2",
51
- "prettier": "3.2.5",
52
- "ts-jest": "^29.1.2",
53
- "typescript": "~5.3.3"
50
+ "jest-ts-webcompat-resolver": "^1.0.1",
51
+ "lint-staged": "^15.5.2",
52
+ "prettier": "3.6.2",
53
+ "ts-jest": "^29.4.5",
54
+ "tsx": "^4.20.6",
55
+ "typescript": "~5.9.3"
56
+ },
57
+ "resolutions": {
58
+ "brace-expansion": "^2.0.2",
59
+ "js-yaml": "^4.1.1",
60
+ "micromatch": "^4.0.8",
61
+ "@babel/helpers": "^7.26.10"
54
62
  }
55
63
  }
@@ -1,6 +0,0 @@
1
- import { ethers } from 'ethers';
2
- declare global {
3
- interface Window {
4
- ethereum?: ethers.Eip1193Provider;
5
- }
6
- }
package/dist/_example.js DELETED
@@ -1,68 +0,0 @@
1
- import { ethers } from 'ethers';
2
- import * as Paradex from './index.js';
3
- // Flow summary:
4
- // 1. Fetch Paradex config
5
- // 2. Derive Paradex account from Ethereum signer
6
- // 3. Create Paraclear provider
7
- // 4. Get user's USDC balance
8
- // 5. Withdraw USDC
9
- // 1. Fetch Paradex config for the relevant environment
10
- const config = await Paradex.Config.fetchConfig('testnet'); // "testnet" | "mainnet"
11
- // 2. Create Paraclear provider
12
- const paraclearProvider = new Paradex.ParaclearProvider.DefaultProvider(config);
13
- // 3. Derive Paradex account from Ethereum signer
14
- // 3.1. Get ethers signer (example with injected provider)
15
- if (window.ethereum == null)
16
- throw new Error('Ethereum provider not found');
17
- const ethersProvider = new ethers.BrowserProvider(window.ethereum);
18
- const ethersSigner = await ethersProvider.getSigner();
19
- // 3.2. Create Ethereum signer based on ethers signer
20
- const signer = Paradex.Signer.ethersSignerAdapter(ethersSigner);
21
- // 3.3. Initialize the account with config and Ethereum signer
22
- const account = await Paradex.Account.fromEthSigner({
23
- provider: paraclearProvider,
24
- config,
25
- signer,
26
- });
27
- // 4. Get user's USDC balance
28
- const getBalanceResult = await Paradex.Paraclear.getTokenBalance({
29
- provider: paraclearProvider, // account can be passed as the provider
30
- config,
31
- account,
32
- token: 'USDC',
33
- });
34
- console.log(getBalanceResult); // { size: '100.45' }
35
- // 5. Withdrawal
36
- // 5.1. Get receivable amount and socialized loss factor
37
- const receivableAmountResult = await Paradex.Paraclear.getReceivableAmount({
38
- provider: paraclearProvider, // account can be passed as the provider
39
- config,
40
- amount: '50.4',
41
- });
42
- // 5.2. Check if socialized loss factor is not 0
43
- if (Number(receivableAmountResult.socializedLossFactor) !== 0) {
44
- // Display a warning to the user, suggesting to withdraw a smaller
45
- // amount or to wait for the socialized loss factor to decrease.
46
- console.log(`Socialized loss is active. You will receive` +
47
- ` ${receivableAmountResult.receivableAmount} USDC.`);
48
- }
49
- // 5.3. Request withdrawal (batches 1. withdraw from Paraclear contract
50
- // and 2. deposit to the bridge in `bridgeCall`) for atomic transaction.
51
- // Note that the requested withdraw amount can be different from the amount
52
- // that will be received if socialized loss is active. Use the receivable
53
- // amount to make the bridge call.
54
- const withdrawResult = await Paradex.Paraclear.withdraw({
55
- config,
56
- account,
57
- token: 'USDC',
58
- amount: '50.4',
59
- bridgeCall: {
60
- contractAddress: '0x...',
61
- entrypoint: 'deposit',
62
- calldata: ['...', receivableAmountResult.receivableAmountChain],
63
- },
64
- });
65
- console.log(withdrawResult); // { hash: '0x...' }
66
- // 5.4. Monitor batch withdrawal transaction to completion
67
- // https://www.starknetjs.com/docs/api/classes/providerinterface/#waitfortransaction
68
- await paraclearProvider.waitForTransaction(withdrawResult.hash);
package/dist/utils.d.ts DELETED
@@ -1,5 +0,0 @@
1
- /**
2
- * Generates a pseudorandom integer between 0 and `max`.
3
- * @param max Maximum value for the noise.
4
- */
5
- export declare function intNoise(max: number): number;
package/dist/utils.js DELETED
@@ -1,7 +0,0 @@
1
- /**
2
- * Generates a pseudorandom integer between 0 and `max`.
3
- * @param max Maximum value for the noise.
4
- */
5
- export function intNoise(max) {
6
- return Math.round(Math.random() * max);
7
- }