@silentswap/sdk 0.0.21 → 0.0.23
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/assets.d.ts +55 -0
- package/dist/assets.js +101 -0
- package/dist/bridge.d.ts +211 -0
- package/dist/bridge.js +615 -0
- package/dist/chain.d.ts +35 -0
- package/dist/chain.js +81 -0
- package/dist/constants.d.ts +8 -0
- package/dist/constants.js +16 -0
- package/dist/data/filtered.json +2179 -0
- package/dist/index.d.ts +9 -1
- package/dist/index.js +8 -0
- package/dist/quote-utils.d.ts +75 -0
- package/dist/quote-utils.js +185 -0
- package/dist/storage.d.ts +74 -0
- package/dist/storage.js +161 -0
- package/dist/transaction-utils.d.ts +19 -0
- package/dist/transaction-utils.js +85 -0
- package/dist/wallet.d.ts +18 -0
- package/dist/wallet.js +107 -0
- package/package.json +10 -4
- package/src/data/filtered.json +2179 -0
package/dist/wallet.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { createPublicClient, http, getAddress, encodeFunctionData } from 'viem';
|
|
2
|
+
import { avalanche } from 'viem/chains';
|
|
3
|
+
import { S0X_ADDR_GATEWAY } from './constants.js';
|
|
4
|
+
/**
|
|
5
|
+
* Query the number of deposits made by a user to the Gateway contract
|
|
6
|
+
*
|
|
7
|
+
* @param userAddress - The user's EVM address
|
|
8
|
+
* @returns The number of deposits made by the user
|
|
9
|
+
*/
|
|
10
|
+
export async function queryDepositCount(userAddress) {
|
|
11
|
+
const normalizedAddress = getAddress(userAddress);
|
|
12
|
+
// Create a public client for Avalanche
|
|
13
|
+
const publicClient = createPublicClient({
|
|
14
|
+
chain: avalanche,
|
|
15
|
+
transport: http(),
|
|
16
|
+
});
|
|
17
|
+
// Query the signerCounts function on the Gateway contract
|
|
18
|
+
const depositCount = await publicClient.readContract({
|
|
19
|
+
address: S0X_ADDR_GATEWAY,
|
|
20
|
+
abi: [
|
|
21
|
+
{
|
|
22
|
+
inputs: [
|
|
23
|
+
{
|
|
24
|
+
internalType: 'address',
|
|
25
|
+
name: '',
|
|
26
|
+
type: 'address',
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
name: 'signerCounts',
|
|
30
|
+
outputs: [
|
|
31
|
+
{
|
|
32
|
+
internalType: 'uint256',
|
|
33
|
+
name: '',
|
|
34
|
+
type: 'uint256',
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
stateMutability: 'view',
|
|
38
|
+
type: 'function',
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
functionName: 'signerCounts',
|
|
42
|
+
args: [normalizedAddress],
|
|
43
|
+
});
|
|
44
|
+
return depositCount;
|
|
45
|
+
}
|
|
46
|
+
// Nil data constants for phony deposit calldata
|
|
47
|
+
const NIL_DATA_32 = '0x0000000000000000000000000000000000000000000000000000000000000000';
|
|
48
|
+
const NIL_DATA_65 = '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
|
|
49
|
+
const NIL_DATA_288 = '0x' + '00'.repeat(288);
|
|
50
|
+
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
|
|
51
|
+
/**
|
|
52
|
+
* Generate phony deposit proxy calldata for testing/estimation purposes
|
|
53
|
+
* This creates a valid calldata structure without actual signature data
|
|
54
|
+
*
|
|
55
|
+
* @param signerAddress - The signer's EVM address (or zero address for anonymous)
|
|
56
|
+
* @param approvalExpiration - Timestamp when approval expires (default: 12 hours from now)
|
|
57
|
+
* @param duration - Duration of the deposit in seconds (default: 7 days)
|
|
58
|
+
* @returns Encoded calldata for depositProxy2 function
|
|
59
|
+
*/
|
|
60
|
+
export function createPhonyDepositCalldata(signerAddress = ZERO_ADDRESS, approvalExpiration, duration = BigInt(3600 * 24 * 7)) {
|
|
61
|
+
const expiration = approvalExpiration ?? BigInt(Math.floor((Date.now() + 12 * 3600e3) / 1e3));
|
|
62
|
+
return encodeFunctionData({
|
|
63
|
+
abi: [
|
|
64
|
+
{
|
|
65
|
+
name: 'depositProxy2',
|
|
66
|
+
type: 'function',
|
|
67
|
+
stateMutability: 'nonpayable',
|
|
68
|
+
inputs: [
|
|
69
|
+
{
|
|
70
|
+
name: 'params',
|
|
71
|
+
type: 'tuple',
|
|
72
|
+
components: [
|
|
73
|
+
{ name: 'orderId', type: 'bytes32' },
|
|
74
|
+
{ name: 'orderApproval', type: 'bytes' },
|
|
75
|
+
{ name: 'typedDataSignature', type: 'bytes' },
|
|
76
|
+
{ name: 'receiveAuthorization', type: 'bytes' },
|
|
77
|
+
{ name: 'notary', type: 'address' },
|
|
78
|
+
{ name: 'approver', type: 'address' },
|
|
79
|
+
{ name: 'payloadHash', type: 'bytes32' },
|
|
80
|
+
{ name: 'domainSepHash', type: 'bytes32' },
|
|
81
|
+
{ name: 'signer', type: 'address' },
|
|
82
|
+
{ name: 'approvalExpiration', type: 'uint256' },
|
|
83
|
+
{ name: 'duration', type: 'uint256' },
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
outputs: [],
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
functionName: 'depositProxy2',
|
|
91
|
+
args: [
|
|
92
|
+
{
|
|
93
|
+
orderId: NIL_DATA_32,
|
|
94
|
+
orderApproval: NIL_DATA_65,
|
|
95
|
+
typedDataSignature: NIL_DATA_65,
|
|
96
|
+
receiveAuthorization: NIL_DATA_288,
|
|
97
|
+
notary: ZERO_ADDRESS,
|
|
98
|
+
approver: ZERO_ADDRESS,
|
|
99
|
+
payloadHash: NIL_DATA_32,
|
|
100
|
+
domainSepHash: NIL_DATA_32,
|
|
101
|
+
signer: signerAddress,
|
|
102
|
+
approvalExpiration: expiration,
|
|
103
|
+
duration,
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
});
|
|
107
|
+
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@silentswap/sdk",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.23",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"files": [
|
|
8
|
-
"dist"
|
|
8
|
+
"dist",
|
|
9
|
+
"src/data"
|
|
9
10
|
],
|
|
10
11
|
"scripts": {
|
|
11
|
-
"build": "tsc"
|
|
12
|
+
"build": "tsc && mkdir -p dist/data && cp src/data/filtered.json dist/data/filtered.json",
|
|
13
|
+
"clean": "rm -rf dist",
|
|
14
|
+
"dev": "tsc --watch",
|
|
15
|
+
"lint": "eslint src --ext .ts",
|
|
16
|
+
"lint:fix": "eslint src --ext .ts --fix"
|
|
12
17
|
},
|
|
13
18
|
"dependencies": {
|
|
14
19
|
"@cosmjs/amino": "0.36.2",
|
|
@@ -17,7 +22,8 @@
|
|
|
17
22
|
"@solar-republic/wasm-secp256k1": "0.6.3",
|
|
18
23
|
"bignumber.js": "9.3.1",
|
|
19
24
|
"siwe": "3.0.0",
|
|
20
|
-
"viem": "2.
|
|
25
|
+
"viem": "2.40.0",
|
|
26
|
+
"wagmi": "3.0.1"
|
|
21
27
|
},
|
|
22
28
|
"devDependencies": {
|
|
23
29
|
"@eslint/js": "9.38.0",
|