swaply-sdk-ts 0.0.1 → 0.0.3

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/.gitignore ADDED
@@ -0,0 +1,175 @@
1
+ # Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
2
+
3
+ # Logs
4
+
5
+ logs
6
+ _.log
7
+ npm-debug.log_
8
+ yarn-debug.log*
9
+ yarn-error.log*
10
+ lerna-debug.log*
11
+ .pnpm-debug.log*
12
+
13
+ # Caches
14
+
15
+ .cache
16
+
17
+ # Diagnostic reports (https://nodejs.org/api/report.html)
18
+
19
+ report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
20
+
21
+ # Runtime data
22
+
23
+ pids
24
+ _.pid
25
+ _.seed
26
+ *.pid.lock
27
+
28
+ # Directory for instrumented libs generated by jscoverage/JSCover
29
+
30
+ lib-cov
31
+
32
+ # Coverage directory used by tools like istanbul
33
+
34
+ coverage
35
+ *.lcov
36
+
37
+ # nyc test coverage
38
+
39
+ .nyc_output
40
+
41
+ # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
42
+
43
+ .grunt
44
+
45
+ # Bower dependency directory (https://bower.io/)
46
+
47
+ bower_components
48
+
49
+ # node-waf configuration
50
+
51
+ .lock-wscript
52
+
53
+ # Compiled binary addons (https://nodejs.org/api/addons.html)
54
+
55
+ build/Release
56
+
57
+ # Dependency directories
58
+
59
+ node_modules/
60
+ jspm_packages/
61
+
62
+ # Snowpack dependency directory (https://snowpack.dev/)
63
+
64
+ web_modules/
65
+
66
+ # TypeScript cache
67
+
68
+ *.tsbuildinfo
69
+
70
+ # Optional npm cache directory
71
+
72
+ .npm
73
+
74
+ # Optional eslint cache
75
+
76
+ .eslintcache
77
+
78
+ # Optional stylelint cache
79
+
80
+ .stylelintcache
81
+
82
+ # Microbundle cache
83
+
84
+ .rpt2_cache/
85
+ .rts2_cache_cjs/
86
+ .rts2_cache_es/
87
+ .rts2_cache_umd/
88
+
89
+ # Optional REPL history
90
+
91
+ .node_repl_history
92
+
93
+ # Output of 'npm pack'
94
+
95
+ *.tgz
96
+
97
+ # Yarn Integrity file
98
+
99
+ .yarn-integrity
100
+
101
+ # dotenv environment variable files
102
+
103
+ .env
104
+ .env.development.local
105
+ .env.test.local
106
+ .env.production.local
107
+ .env.local
108
+
109
+ # parcel-bundler cache (https://parceljs.org/)
110
+
111
+ .parcel-cache
112
+
113
+ # Next.js build output
114
+
115
+ .next
116
+ out
117
+
118
+ # Nuxt.js build / generate output
119
+
120
+ .nuxt
121
+ dist
122
+
123
+ # Gatsby files
124
+
125
+ # Comment in the public line in if your project uses Gatsby and not Next.js
126
+
127
+ # https://nextjs.org/blog/next-9-1#public-directory-support
128
+
129
+ # public
130
+
131
+ # vuepress build output
132
+
133
+ .vuepress/dist
134
+
135
+ # vuepress v2.x temp and cache directory
136
+
137
+ .temp
138
+
139
+ # Docusaurus cache and generated files
140
+
141
+ .docusaurus
142
+
143
+ # Serverless directories
144
+
145
+ .serverless/
146
+
147
+ # FuseBox cache
148
+
149
+ .fusebox/
150
+
151
+ # DynamoDB Local files
152
+
153
+ .dynamodb/
154
+
155
+ # TernJS port file
156
+
157
+ .tern-port
158
+
159
+ # Stores VSCode versions used for testing VSCode extensions
160
+
161
+ .vscode-test
162
+
163
+ # yarn v2
164
+
165
+ .yarn/cache
166
+ .yarn/unplugged
167
+ .yarn/build-state.yml
168
+ .yarn/install-state.gz
169
+ .pnp.*
170
+
171
+ # IntelliJ based IDEs
172
+ .idea
173
+
174
+ # Finder (MacOS) folder config
175
+ .DS_Store
@@ -0,0 +1,68 @@
1
+ import axios from 'axios';
2
+ export class SwaplyApiClient {
3
+ client;
4
+ constructor(apiUrl, apiKey, config) {
5
+ this.client = axios.create({
6
+ baseURL: apiUrl,
7
+ headers: {
8
+ 'x-api-key': apiKey,
9
+ },
10
+ ...config,
11
+ });
12
+ }
13
+ async getQuote(sourceChain, sourceToken, destChain, destToken, amount, slippageBps, swapType, retailUserId = null) {
14
+ const response = await this.client.post('/quotes/best', {
15
+ source_chain: sourceChain,
16
+ source_token: sourceToken,
17
+ dest_chain: destChain,
18
+ dest_token: destToken,
19
+ amount,
20
+ slippage_bps: slippageBps.toString(),
21
+ swap_type: swapType,
22
+ retail_user_id: retailUserId,
23
+ });
24
+ return response.data;
25
+ }
26
+ async createIntent(quoteId, userSourcePublicKey, userSourceAddress, userDestinationAddress, refundAddress) {
27
+ const response = await this.client.post('/intents/create', {
28
+ quote_id: quoteId,
29
+ user_source_public_key: userSourcePublicKey,
30
+ user_source_address: userSourceAddress,
31
+ user_destination_address: userDestinationAddress,
32
+ refund_address: refundAddress,
33
+ });
34
+ return response.data;
35
+ }
36
+ async addApproval(signedData, intentId) {
37
+ await this.client.post(`/intents/${intentId}/approvals`, signedData);
38
+ }
39
+ async getIntentStatus(intentId) {
40
+ const response = await this.client.get(`/intents/${intentId}/status`);
41
+ return response.data.status;
42
+ }
43
+ async listRetailUserHistory(walletAddressOrRetailId) {
44
+ const response = await this.client.get(`/history/${walletAddressOrRetailId}`);
45
+ return response.data;
46
+ }
47
+ async getSwapByIntentId(intentId) {
48
+ const response = await this.client.get(`/swaps/intents/${intentId}`);
49
+ return response.data;
50
+ }
51
+ async listNetworks(token) {
52
+ const endpoint = token ? `/networks?token=${token}` : '/networks';
53
+ const response = await this.client.get(endpoint);
54
+ return response.data;
55
+ }
56
+ async listTokens(limit = 20, offset = 0, q, networkId) {
57
+ let endpoint = `/tokens?limit=${limit}&offset=${offset}`;
58
+ if (q) {
59
+ endpoint += `&q=${q}`;
60
+ }
61
+ if (networkId) {
62
+ endpoint += `&network_id=${networkId}`;
63
+ }
64
+ const response = await this.client.get(endpoint);
65
+ return response.data;
66
+ }
67
+ }
68
+ export default SwaplyApiClient;
@@ -0,0 +1,28 @@
1
+ import { SwapType } from './types';
2
+ export const signPermit2Approval = async (permit2Approval, quote, userAddress, signTypedData) => {
3
+ const permit2Data = permit2Approval.additional_data;
4
+ const domain = {
5
+ name: permit2Data.domain.name,
6
+ chainId: permit2Data.domain.chain_id,
7
+ verifyingContract: permit2Data.domain.verifying_contract,
8
+ };
9
+ const witness = permit2Data.witness;
10
+ const message = {
11
+ permitted: {
12
+ token: quote.source_token,
13
+ amount: BigInt(quote.source_amount_lots),
14
+ },
15
+ spender: permit2Approval.escrow_contract_address,
16
+ nonce: permit2Approval.nonce,
17
+ deadline: permit2Approval.deadline,
18
+ witness,
19
+ };
20
+ const signature = await signTypedData({
21
+ domain,
22
+ types: permit2Data.types,
23
+ primaryType: 'PermitWitnessTransferFrom',
24
+ message,
25
+ account: userAddress,
26
+ });
27
+ return signature;
28
+ };
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from './apiClient';
2
+ export * from './approvals';
3
+ export * from './types';
package/dist/types.js ADDED
@@ -0,0 +1,32 @@
1
+ export var SwapType;
2
+ (function (SwapType) {
3
+ SwapType["Standard"] = "Standard";
4
+ SwapType["Optimized"] = "Optimized";
5
+ })(SwapType || (SwapType = {}));
6
+ export var IntentStatus;
7
+ (function (IntentStatus) {
8
+ IntentStatus["Initiated"] = "Initiated";
9
+ IntentStatus["ApprovalAdded"] = "ApprovalAdded";
10
+ IntentStatus["Accepted"] = "Accepted";
11
+ IntentStatus["Declined"] = "Declined";
12
+ IntentStatus["DeclinedDueToKytCheck"] = "DeclinedDueToKytCheck";
13
+ IntentStatus["UserDeposited"] = "UserDeposited";
14
+ IntentStatus["KycRequested"] = "KycRequested";
15
+ IntentStatus["Fulfilled"] = "Fulfilled";
16
+ IntentStatus["Expired"] = "Expired";
17
+ IntentStatus["RefundRequested"] = "RefundRequested";
18
+ IntentStatus["Refunded"] = "Refunded";
19
+ })(IntentStatus || (IntentStatus = {}));
20
+ export var NetworkType;
21
+ (function (NetworkType) {
22
+ NetworkType["EVM"] = "EVM";
23
+ NetworkType["TRON"] = "TRON";
24
+ NetworkType["BITCOIN"] = "BITCOIN";
25
+ NetworkType["SOLANA"] = "SOLANA";
26
+ })(NetworkType || (NetworkType = {}));
27
+ /**
28
+ * API Error Codes
29
+ */
30
+ export const API_ERROR_CODES = {
31
+ INSUFFICIENT_ALLOWANCE: 25,
32
+ };
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "swaply-sdk-ts",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
- "module": "src/index.ts",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist",
7
+ "files": [
8
+ "**"
9
+ ],
6
10
  "dependencies": {
7
11
  "axios": "^1.13.4",
8
12
  "viem": "^2.45.0"
package/src/apiClient.ts CHANGED
@@ -14,10 +14,8 @@ import type {
14
14
 
15
15
  export class SwaplyApiClient {
16
16
  private client: AxiosInstance;
17
- private apiUrl: string;
18
17
 
19
18
  constructor(apiUrl: string, apiKey: string, config?: AxiosRequestConfig) {
20
- this.apiUrl = apiUrl;
21
19
  this.client = axios.create({
22
20
  baseURL: apiUrl,
23
21
  headers: {
package/src/types.ts CHANGED
@@ -152,3 +152,35 @@ export interface Token {
152
152
  icon_url: string;
153
153
  wrapped_token_address: string | null;
154
154
  }
155
+
156
+ export type ApiEntity =
157
+ | 'Approval'
158
+ | 'Intent'
159
+ | 'Network'
160
+ | 'Quote'
161
+ | 'Resolver'
162
+ | 'SupportedToken'
163
+ | 'Swap'
164
+ | 'Token'
165
+ | 'UserNonce'
166
+ | 'Transaction'
167
+ | 'TransactionReceipt'
168
+ | 'InternalEvent'
169
+ | 'BlockchainEvent'
170
+ | 'WatcherRequest'
171
+ | 'Webhooks'
172
+ | 'Affiliate'
173
+ | 'Other';
174
+
175
+ export interface ApiError {
176
+ code: number;
177
+ entity: ApiEntity;
178
+ message: string;
179
+ }
180
+
181
+ /**
182
+ * API Error Codes
183
+ */
184
+ export const API_ERROR_CODES = {
185
+ INSUFFICIENT_ALLOWANCE: 25,
186
+ } as const;
package/tsconfig.json CHANGED
@@ -7,12 +7,11 @@
7
7
  "moduleDetection": "force",
8
8
  "jsx": "react-jsx",
9
9
  "allowJs": true,
10
+ "outDir": "./dist",
10
11
 
11
12
  // Bundler mode
12
13
  "moduleResolution": "bundler",
13
- "allowImportingTsExtensions": true,
14
14
  "verbatimModuleSyntax": true,
15
- "noEmit": true,
16
15
 
17
16
  // Best practices
18
17
  "strict": true,
@@ -24,5 +23,5 @@
24
23
  "noUnusedParameters": false,
25
24
  "noPropertyAccessFromIndexSignature": false,
26
25
  },
27
- "include": ["src", "eslint.config.ts"],
26
+ "include": ["src"],
28
27
  }