@paradex/sdk 0.5.4 → 0.7.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.
- package/README.md +0 -1
- package/dist/account.d.ts +4 -0
- package/dist/account.js +22 -2
- package/dist/paraclear.js +10 -14
- package/dist/starknet-account-support.js +45 -14
- package/dist/starknet-signer.js +5 -1
- package/package.json +24 -16
- package/dist/_example.d.ts +0 -6
- package/dist/_example.js +0 -68
- package/dist/utils.d.ts +0 -5
- package/dist/utils.js +0 -7
package/README.md
CHANGED
package/dist/account.d.ts
CHANGED
|
@@ -25,4 +25,8 @@ interface FromStarknetAccountParams {
|
|
|
25
25
|
* @returns The generated Paradex account.
|
|
26
26
|
*/
|
|
27
27
|
export declare function fromStarknetAccount({ provider, config, account, starknetProvider, }: FromStarknetAccountParams): Promise<Account>;
|
|
28
|
+
/**
|
|
29
|
+
* Checks if starknet signatures are equal.
|
|
30
|
+
*/
|
|
31
|
+
export declare function isStarknetSignatureEqual(signature: Starknet.Signature, additionalSignature: Starknet.Signature): boolean;
|
|
28
32
|
export {};
|
package/dist/account.js
CHANGED
|
@@ -9,6 +9,9 @@ import * as starknetSigner from './starknet-signer.js';
|
|
|
9
9
|
export async function fromEthSigner({ provider, config, signer, }) {
|
|
10
10
|
const starkKeyTypedData = ethereumSigner.buildEthereumStarkKeyTypedData(config.ethereumChainId);
|
|
11
11
|
const seed = await signer.signTypedData(starkKeyTypedData);
|
|
12
|
+
const additionalSeed = await signer.signTypedData(starkKeyTypedData);
|
|
13
|
+
if (seed !== additionalSeed)
|
|
14
|
+
throw new Error('Wallet does not support deterministic signing. Please use different wallet.');
|
|
12
15
|
const privateKey = keyDerivation.getPrivateKeyFromEthSignature(seed);
|
|
13
16
|
const publicKey = keyDerivation.privateToStarkKey(privateKey);
|
|
14
17
|
const address = generateAccountAddress({
|
|
@@ -16,7 +19,7 @@ export async function fromEthSigner({ provider, config, signer, }) {
|
|
|
16
19
|
accountClassHash: config.paraclearAccountHash,
|
|
17
20
|
accountProxyClassHash: config.paraclearAccountProxyHash,
|
|
18
21
|
});
|
|
19
|
-
return new Starknet.Account(provider, address, `0x${privateKey}`);
|
|
22
|
+
return new Starknet.Account({ provider, address, signer: `0x${privateKey}` });
|
|
20
23
|
}
|
|
21
24
|
/**
|
|
22
25
|
* Generates a Paradex account from a Starknet signer.
|
|
@@ -27,6 +30,9 @@ export async function fromStarknetAccount({ provider, config, account, starknetP
|
|
|
27
30
|
const accountSupport = await starknetSigner.getAccountSupport(account, starknetProvider ??
|
|
28
31
|
starknetSigner.getPublicProvider(config.starknetChainId));
|
|
29
32
|
const signature = await account.signMessage(starkKeyTypedData);
|
|
33
|
+
const additionalSignature = await account.signMessage(starkKeyTypedData);
|
|
34
|
+
if (!isStarknetSignatureEqual(signature, additionalSignature))
|
|
35
|
+
throw new Error('Wallet does not support deterministic signing. Please use different wallet.');
|
|
30
36
|
const seed = accountSupport.getSeedFromSignature(signature);
|
|
31
37
|
const [privateKey, publicKey] = await starknetSigner.getStarkKeypairFromStarknetSignature(seed);
|
|
32
38
|
const address = generateAccountAddress({
|
|
@@ -34,7 +40,7 @@ export async function fromStarknetAccount({ provider, config, account, starknetP
|
|
|
34
40
|
accountClassHash: config.paraclearAccountHash,
|
|
35
41
|
accountProxyClassHash: config.paraclearAccountProxyHash,
|
|
36
42
|
});
|
|
37
|
-
return new Starknet.Account(provider, address, `0x${privateKey}`);
|
|
43
|
+
return new Starknet.Account({ provider, address, signer: `0x${privateKey}` });
|
|
38
44
|
}
|
|
39
45
|
/**
|
|
40
46
|
* Generates an account address based on the account contract and public key.
|
|
@@ -51,3 +57,17 @@ function generateAccountAddress({ accountClassHash, accountProxyClassHash, publi
|
|
|
51
57
|
const address = Starknet.hash.calculateContractAddressFromHash(publicKey, accountProxyClassHash, callData, 0);
|
|
52
58
|
return address;
|
|
53
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Checks if starknet signatures are equal.
|
|
62
|
+
*/
|
|
63
|
+
export function isStarknetSignatureEqual(signature, additionalSignature) {
|
|
64
|
+
if (Array.isArray(signature) && Array.isArray(additionalSignature)) {
|
|
65
|
+
return (signature.length === additionalSignature.length &&
|
|
66
|
+
signature.every((value, index) => value === additionalSignature[index]));
|
|
67
|
+
}
|
|
68
|
+
// Cast Starknet.WeierstrassSignatureType
|
|
69
|
+
const signatureWeierstrass = signature;
|
|
70
|
+
const additionalSignatureWeierstrass = additionalSignature;
|
|
71
|
+
return (signatureWeierstrass.r === additionalSignatureWeierstrass.r &&
|
|
72
|
+
signatureWeierstrass.s === additionalSignatureWeierstrass.s);
|
|
73
|
+
}
|
package/dist/paraclear.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { BigNumber } from 'bignumber.js';
|
|
2
2
|
import * as Starknet from 'starknet';
|
|
3
|
-
const MAX_FEE = BigNumber('5e17'); // 5e17 WEI = 0.5 ETH
|
|
4
3
|
/**
|
|
5
4
|
* Get the Paraclear balance of the given token for the given account.
|
|
6
5
|
*/
|
|
@@ -9,7 +8,7 @@ export async function getTokenBalance(params) {
|
|
|
9
8
|
if (token == null) {
|
|
10
9
|
throw new Error(`Token ${params.token} is not supported`);
|
|
11
10
|
}
|
|
12
|
-
const
|
|
11
|
+
const result = await params.provider.callContract({
|
|
13
12
|
contractAddress: params.config.paraclearAddress,
|
|
14
13
|
entrypoint: 'getTokenAssetBalance',
|
|
15
14
|
calldata: Starknet.CallData.compile([
|
|
@@ -37,7 +36,7 @@ export async function getTokenBalance(params) {
|
|
|
37
36
|
* requested amount.
|
|
38
37
|
*/
|
|
39
38
|
export async function getSocializedLossFactor(params) {
|
|
40
|
-
const
|
|
39
|
+
const result = await params.provider.callContract({
|
|
41
40
|
contractAddress: params.config.paraclearAddress,
|
|
42
41
|
entrypoint: 'getSocializedLossFactor',
|
|
43
42
|
});
|
|
@@ -100,9 +99,7 @@ export async function withdraw(params) {
|
|
|
100
99
|
throw new Error(`Token ${params.token} is not supported`);
|
|
101
100
|
}
|
|
102
101
|
const chainAmountBn = toChainSize(params.amount, params.config.paraclearDecimals);
|
|
103
|
-
|
|
104
|
-
const maxFee = MAX_FEE.plus(intNoise(10000));
|
|
105
|
-
const result = await params.account.execute([
|
|
102
|
+
const txnInvocation = [
|
|
106
103
|
{
|
|
107
104
|
contractAddress: params.config.paraclearAddress,
|
|
108
105
|
entrypoint: 'withdraw',
|
|
@@ -111,7 +108,13 @@ export async function withdraw(params) {
|
|
|
111
108
|
...(Array.isArray(params.bridgeCall)
|
|
112
109
|
? params.bridgeCall
|
|
113
110
|
: [params.bridgeCall]),
|
|
114
|
-
]
|
|
111
|
+
];
|
|
112
|
+
// Estimate fees to get proper resource bounds
|
|
113
|
+
const fees = await params.account.estimateInvokeFee(txnInvocation);
|
|
114
|
+
// Use the resource bounds from fee estimation
|
|
115
|
+
const result = await params.account.execute(txnInvocation, {
|
|
116
|
+
resourceBounds: fees.resourceBounds,
|
|
117
|
+
});
|
|
115
118
|
return { hash: result.transaction_hash };
|
|
116
119
|
}
|
|
117
120
|
function fromChainSize(size, decimals) {
|
|
@@ -122,10 +125,3 @@ function toChainSize(size, decimals) {
|
|
|
122
125
|
.times(10 ** decimals)
|
|
123
126
|
.integerValue(BigNumber.ROUND_FLOOR);
|
|
124
127
|
}
|
|
125
|
-
/**
|
|
126
|
-
* Generates a pseudorandom integer between 0 and `max`.
|
|
127
|
-
* @param max Maximum value for the noise.
|
|
128
|
-
*/
|
|
129
|
-
function intNoise(max) {
|
|
130
|
-
return Math.round(Math.random() * max);
|
|
131
|
-
}
|
|
@@ -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(
|
|
29
|
+
if (this.testClassHash(ARGENT_V0_3_0_CLASS_HASH)) {
|
|
18
30
|
return 'argent-v0.3.0';
|
|
19
31
|
}
|
|
20
|
-
if (this.testClassHash(
|
|
32
|
+
if (this.testClassHash(ARGENT_V0_3_1_CLASS_HASH)) {
|
|
21
33
|
return 'argent-v0.3.1';
|
|
22
34
|
}
|
|
23
|
-
if (this.testClassHash(
|
|
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(
|
|
53
|
+
if (this.testClassHash(ARGENT_MULTICALL_CLASS_HASH)) {
|
|
42
54
|
return 'argent-multicall';
|
|
43
55
|
}
|
|
44
|
-
if (this.testClassHash(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
-
//
|
|
73
|
-
|
|
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':
|
package/dist/starknet-signer.js
CHANGED
|
@@ -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(
|
|
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.
|
|
3
|
+
"version": "0.7.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
|
|
32
|
-
"starknet": "^
|
|
32
|
+
"bignumber.js": "^9.3.1",
|
|
33
|
+
"starknet": "^8.6.0"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
|
-
"@ianvs/prettier-plugin-sort-imports": "^4.
|
|
36
|
+
"@ianvs/prettier-plugin-sort-imports": "^4.7.0",
|
|
36
37
|
"@types/elliptic": "^6.4.18",
|
|
37
|
-
"@types/jest": "^29.5.
|
|
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.
|
|
41
|
+
"eslint": "^8.57.1",
|
|
41
42
|
"eslint-config-love": "^43.1.0",
|
|
42
|
-
"eslint-config-prettier": "^9.1.
|
|
43
|
-
"eslint-plugin-import": "^2.
|
|
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.
|
|
47
|
-
"husky": "^9.
|
|
47
|
+
"ethers": "^6.15.0",
|
|
48
|
+
"husky": "^9.1.7",
|
|
48
49
|
"jest": "^29.7.0",
|
|
49
|
-
"jest-ts-webcompat-resolver": "^1.0.
|
|
50
|
-
"lint-staged": "^15.
|
|
51
|
-
"prettier": "3.2
|
|
52
|
-
"ts-jest": "^29.
|
|
53
|
-
"
|
|
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
|
}
|
package/dist/_example.d.ts
DELETED
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