swig-developer-sdk 0.6.0__tar.gz → 0.7.0__tar.gz

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.
Files changed (24) hide show
  1. {swig_developer_sdk-0.6.0 → swig_developer_sdk-0.7.0}/PKG-INFO +5 -1
  2. {swig_developer_sdk-0.6.0 → swig_developer_sdk-0.7.0}/README.md +4 -0
  3. {swig_developer_sdk-0.6.0 → swig_developer_sdk-0.7.0}/pyproject.toml +1 -1
  4. {swig_developer_sdk-0.6.0 → swig_developer_sdk-0.7.0}/src/swig_developer_sdk/wallets.py +16 -11
  5. {swig_developer_sdk-0.6.0 → swig_developer_sdk-0.7.0}/tests/test_client.py +113 -1
  6. {swig_developer_sdk-0.6.0 → swig_developer_sdk-0.7.0}/uv.lock +1 -1
  7. {swig_developer_sdk-0.6.0 → swig_developer_sdk-0.7.0}/.gitignore +0 -0
  8. {swig_developer_sdk-0.6.0 → swig_developer_sdk-0.7.0}/scripts/local_transaction_e2e.py +0 -0
  9. {swig_developer_sdk-0.6.0 → swig_developer_sdk-0.7.0}/src/swig_developer_sdk/__init__.py +0 -0
  10. {swig_developer_sdk-0.6.0 → swig_developer_sdk-0.7.0}/src/swig_developer_sdk/client.py +0 -0
  11. {swig_developer_sdk-0.6.0 → swig_developer_sdk-0.7.0}/src/swig_developer_sdk/common.py +0 -0
  12. {swig_developer_sdk-0.6.0 → swig_developer_sdk-0.7.0}/src/swig_developer_sdk/core.py +0 -0
  13. {swig_developer_sdk-0.6.0 → swig_developer_sdk-0.7.0}/src/swig_developer_sdk/evm.py +0 -0
  14. {swig_developer_sdk-0.6.0 → swig_developer_sdk-0.7.0}/src/swig_developer_sdk/one_business.py +0 -0
  15. {swig_developer_sdk-0.6.0 → swig_developer_sdk-0.7.0}/src/swig_developer_sdk/passkeys.py +0 -0
  16. {swig_developer_sdk-0.6.0 → swig_developer_sdk-0.7.0}/src/swig_developer_sdk/paymaster.py +0 -0
  17. {swig_developer_sdk-0.6.0 → swig_developer_sdk-0.7.0}/src/swig_developer_sdk/proxy.py +0 -0
  18. {swig_developer_sdk-0.6.0 → swig_developer_sdk-0.7.0}/src/swig_developer_sdk/ramp.py +0 -0
  19. {swig_developer_sdk-0.6.0 → swig_developer_sdk-0.7.0}/src/swig_developer_sdk/signing.py +0 -0
  20. {swig_developer_sdk-0.6.0 → swig_developer_sdk-0.7.0}/src/swig_developer_sdk/transactions.py +0 -0
  21. {swig_developer_sdk-0.6.0 → swig_developer_sdk-0.7.0}/tests/test_helpers.py +0 -0
  22. {swig_developer_sdk-0.6.0 → swig_developer_sdk-0.7.0}/tests/test_proxy.py +0 -0
  23. {swig_developer_sdk-0.6.0 → swig_developer_sdk-0.7.0}/tests/test_resource_clients.py +0 -0
  24. {swig_developer_sdk-0.6.0 → swig_developer_sdk-0.7.0}/tests/test_signing.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: swig-developer-sdk
3
- Version: 0.6.0
3
+ Version: 0.7.0
4
4
  Summary: Python SDK for preparing and locally signing Swig wallet transactions
5
5
  Project-URL: Repository, https://github.com/anagrambuild/swig-ts
6
6
  Author: Anagram
@@ -39,6 +39,10 @@ prepared = await wallet.transfer.sol(
39
39
  )
40
40
  ```
41
41
 
42
+ Use `wallet.build_transaction(...)` to supply raw Solana instructions for the
43
+ backend to wrap in the Swig signing flow. The returned transaction is still
44
+ signed and submitted client-side.
45
+
42
46
  `wallet.transfer(...)` and `wallet.swap(...)` are callable like their
43
47
  TypeScript counterparts. Their explicit `sol`, `token`, `spl_token`, and
44
48
  `jupiter` methods are available as well.
@@ -26,6 +26,10 @@ prepared = await wallet.transfer.sol(
26
26
  )
27
27
  ```
28
28
 
29
+ Use `wallet.build_transaction(...)` to supply raw Solana instructions for the
30
+ backend to wrap in the Swig signing flow. The returned transaction is still
31
+ signed and submitted client-side.
32
+
29
33
  `wallet.transfer(...)` and `wallet.swap(...)` are callable like their
30
34
  TypeScript counterparts. Their explicit `sol`, `token`, `spl_token`, and
31
35
  `jupiter` methods are available as well.
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "swig-developer-sdk"
7
- version = "0.6.0"
7
+ version = "0.7.0"
8
8
  description = "Python SDK for preparing and locally signing Swig wallet transactions"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -295,7 +295,7 @@ class WalletsClient:
295
295
  ) -> PreparedTransactionsResult:
296
296
  authority = _requester_authority(wallet, requester_authority)
297
297
  response = await self._http.post(
298
- "/transaction/prepare",
298
+ "/transaction/prepare/batch",
299
299
  {
300
300
  **_base_write_request(
301
301
  wallet, fee_payer, network, self._default_network
@@ -575,26 +575,29 @@ class WalletsClient:
575
575
  )
576
576
  )
577
577
 
578
- async def execute(
578
+ async def build_transaction(
579
579
  self,
580
580
  wallet: WalletHandle,
581
581
  *,
582
+ fee_payer: str,
582
583
  instructions: Sequence[SolanaInstructionInput],
584
+ requester_authority: WalletAuthority | None = None,
583
585
  address_lookup_table_accounts: Sequence[str] | None = None,
584
586
  network: Network | None = None,
585
- idempotency_key: str | None = None,
586
587
  ) -> PreparedTransaction:
588
+ authority = _requester_authority(wallet, requester_authority)
587
589
  return normalize_prepared_transaction(
588
590
  await self._http.post(
589
- f"/v1/wallets/{quote(wallet.swig_config_address, safe='')}/execute",
591
+ "/transaction/prepare/custom",
590
592
  {
591
- "wallet": wallet.swig_config_address,
592
- "network": network or wallet.network or self._default_network,
593
+ **_base_write_request(
594
+ wallet, fee_payer, network, self._default_network
595
+ ),
596
+ "requesterAuthority": wallet_authority_to_wire(authority),
593
597
  "instructions": [
594
598
  _instruction_to_wire(item) for item in instructions
595
599
  ],
596
600
  "addressLookupTableAccounts": address_lookup_table_accounts,
597
- "idempotencyKey": idempotency_key,
598
601
  },
599
602
  )
600
603
  )
@@ -679,20 +682,22 @@ class WalletHandle:
679
682
  idempotency_key=idempotency_key,
680
683
  )
681
684
 
682
- async def execute(
685
+ async def build_transaction(
683
686
  self,
684
687
  *,
688
+ fee_payer: str,
685
689
  instructions: Sequence[SolanaInstructionInput],
690
+ requester_authority: WalletAuthority | None = None,
686
691
  address_lookup_table_accounts: Sequence[str] | None = None,
687
692
  network: Network | None = None,
688
- idempotency_key: str | None = None,
689
693
  ) -> PreparedTransaction:
690
- return await self._wallets.execute(
694
+ return await self._wallets.build_transaction(
691
695
  self,
696
+ fee_payer=fee_payer,
692
697
  instructions=instructions,
698
+ requester_authority=requester_authority,
693
699
  address_lookup_table_accounts=address_lookup_table_accounts,
694
700
  network=network,
695
- idempotency_key=idempotency_key,
696
701
  )
697
702
 
698
703
  async def get_usd_balance(
@@ -5,7 +5,14 @@ import json
5
5
  import httpx
6
6
  import pytest
7
7
 
8
- from swig_developer_sdk import RetryOptions, SwigClient, SwigDeveloperSdkError
8
+ from swig_developer_sdk import (
9
+ RetryOptions,
10
+ SolanaAccountMeta,
11
+ SolanaInstructionInput,
12
+ SwigClient,
13
+ SwigDeveloperSdkError,
14
+ TransferSolOperation,
15
+ )
9
16
 
10
17
 
11
18
  async def test_wallet_transfer_matches_typescript_wire_contract() -> None:
@@ -65,6 +72,111 @@ async def test_wallet_transfer_matches_typescript_wire_contract() -> None:
65
72
  }
66
73
 
67
74
 
75
+ async def test_wallet_prepare_uses_batch_preparation_endpoint() -> None:
76
+ requests: list[httpx.Request] = []
77
+
78
+ def handler(request: httpx.Request) -> httpx.Response:
79
+ requests.append(request)
80
+ return httpx.Response(
81
+ 200,
82
+ json={"data": {"transactions": [], "network": "NETWORK_DEVNET"}},
83
+ )
84
+
85
+ swig = SwigClient(
86
+ api_key="secret",
87
+ base_url="https://example.test",
88
+ network="devnet",
89
+ transport=httpx.MockTransport(handler),
90
+ )
91
+ wallet = swig.wallets.use(
92
+ "swig-address",
93
+ requester_authority={"ed25519": {"publicKey": "requester"}},
94
+ )
95
+
96
+ await wallet.prepare(
97
+ fee_payer="payer",
98
+ operations=(TransferSolOperation(destination="destination", amount=123),),
99
+ )
100
+
101
+ assert requests[0].url.path == "/transaction/prepare/batch"
102
+ assert json.loads(requests[0].content) == {
103
+ "network": "NETWORK_DEVNET",
104
+ "feePayer": "payer",
105
+ "swigAddress": "swig-address",
106
+ "requesterAuthority": {"ed25519": {"publicKey": "requester"}},
107
+ "operations": [
108
+ {"transferSol": {"destination": "destination", "lamports": "123"}}
109
+ ],
110
+ }
111
+
112
+
113
+ async def test_wallet_build_transaction_matches_custom_preparation_contract() -> None:
114
+ requests: list[httpx.Request] = []
115
+
116
+ def handler(request: httpx.Request) -> httpx.Response:
117
+ requests.append(request)
118
+ return httpx.Response(
119
+ 200,
120
+ json={
121
+ "data": {
122
+ "transaction": "prepared-custom-base64",
123
+ "transactionEncoding": "TRANSACTION_ENCODING_BASE64",
124
+ "network": "NETWORK_DEVNET",
125
+ }
126
+ },
127
+ )
128
+
129
+ swig = SwigClient(
130
+ api_key="secret",
131
+ base_url="https://example.test",
132
+ network="devnet",
133
+ transport=httpx.MockTransport(handler),
134
+ )
135
+ wallet = swig.wallets.use(
136
+ "swig-address",
137
+ requester_authority={"ed25519": {"publicKey": "requester"}},
138
+ )
139
+
140
+ prepared = await wallet.build_transaction(
141
+ fee_payer="payer",
142
+ instructions=(
143
+ SolanaInstructionInput(
144
+ program_id="program",
145
+ accounts=(
146
+ SolanaAccountMeta(
147
+ pubkey="account", is_signer=True, is_writable=True
148
+ ),
149
+ ),
150
+ data=b"\x01\x02\x03",
151
+ ),
152
+ ),
153
+ address_lookup_table_accounts=("lookup-table",),
154
+ )
155
+
156
+ assert prepared.transaction == "prepared-custom-base64"
157
+ assert requests[0].url.path == "/transaction/prepare/custom"
158
+ assert json.loads(requests[0].content) == {
159
+ "network": "NETWORK_DEVNET",
160
+ "feePayer": "payer",
161
+ "swigAddress": "swig-address",
162
+ "requesterAuthority": {"ed25519": {"publicKey": "requester"}},
163
+ "instructions": [
164
+ {
165
+ "programId": "program",
166
+ "accounts": [
167
+ {
168
+ "pubkey": "account",
169
+ "isSigner": True,
170
+ "isWritable": True,
171
+ }
172
+ ],
173
+ "data": "AQID",
174
+ }
175
+ ],
176
+ "addressLookupTableAccounts": ["lookup-table"],
177
+ }
178
+
179
+
68
180
  async def test_http_client_does_not_retry_client_errors() -> None:
69
181
  attempts = 0
70
182
 
@@ -575,7 +575,7 @@ wheels = [
575
575
 
576
576
  [[package]]
577
577
  name = "swig-developer-sdk"
578
- version = "0.6.0"
578
+ version = "0.7.0"
579
579
  source = { editable = "." }
580
580
  dependencies = [
581
581
  { name = "base58" },