@gala-chain/gswap-sdk 0.0.9 → 1.0.0-rc.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/README.md +63 -35
- package/dist/browser/index.js +2 -24
- package/dist/browser/index.js.map +1 -1
- package/dist/index.cjs +2033 -1345
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1008 -774
- package/dist/index.d.ts +1008 -774
- package/dist/index.mjs +2012 -1337
- package/dist/index.mjs.map +1 -1
- package/package.json +37 -26
package/README.md
CHANGED
|
@@ -1,50 +1,78 @@
|
|
|
1
1
|
# gSwap SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@gala-chain/gswap-sdk` is the TypeScript SDK for the current GalaChain DEX
|
|
4
|
+
contract. Version 1.0 uses trading symbols for pool operations, signs writes
|
|
5
|
+
with the signer supplied by the application, and submits them through the Chain
|
|
6
|
+
Gateway. Swap requests are queued for later application.
|
|
4
7
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
## Documentation
|
|
8
|
-
|
|
9
|
-
Visit [the documentation](https://galachain.github.io/gswap-sdk/docs/intro) for detailed guides and API references.
|
|
10
|
-
|
|
11
|
-
## Example SDK Usage
|
|
8
|
+
## Install
|
|
12
9
|
|
|
13
10
|
```bash
|
|
14
11
|
npm install @gala-chain/gswap-sdk
|
|
15
12
|
```
|
|
16
13
|
|
|
14
|
+
## Quick start
|
|
15
|
+
|
|
17
16
|
```typescript
|
|
18
17
|
import { GSwap, PrivateKeySigner } from '@gala-chain/gswap-sdk';
|
|
19
18
|
|
|
20
|
-
const
|
|
21
|
-
|
|
19
|
+
const signer = new PrivateKeySigner(process.env.GALACHAIN_PRIVATE_KEY!);
|
|
20
|
+
const gSwap = new GSwap({ signer, walletAddress: process.env.GALACHAIN_ADDRESS, env: 'stage' });
|
|
21
|
+
const quote = await gSwap.quoting.quoteExactInput('GALA', 'GUSDC', '100');
|
|
22
|
+
const tx = await gSwap.swaps.swap('GALA', 'GUSDC', quote.feeTier, {
|
|
23
|
+
exactIn: '100',
|
|
24
|
+
amountOutMinimum: quote.amountOut,
|
|
22
25
|
});
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
// Quote how much $GALA you can get for 10 USDC
|
|
27
|
-
const quote = await gSwap.quoting.quoteExactInput(
|
|
28
|
-
'GUSDC|Unit|none|none',
|
|
29
|
-
'GALA|Unit|none|none',
|
|
30
|
-
USDC_SELLING_AMOUNT,
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
console.log(`Best rate found on ${quote.feeTier} fee tier pool`);
|
|
34
|
-
|
|
35
|
-
// Execute a swap using the best fee tier from the quote
|
|
36
|
-
const result = await gSwap.swap(
|
|
37
|
-
'GUSDC|Unit|none|none',
|
|
38
|
-
'GALA|Unit|none|none',
|
|
39
|
-
quote.feeTier,
|
|
40
|
-
{
|
|
41
|
-
exactIn: USDC_SELLING_AMOUNT,
|
|
42
|
-
amountOutMinimum: quote.outTokenAmount.multipliedBy(0.95), // 5% slippage
|
|
43
|
-
},
|
|
44
|
-
'eth|123...abc', // your wallet address
|
|
45
|
-
);
|
|
26
|
+
console.log({ mode: tx.mode, uniqueKey: tx.uniqueKey, transactionId: tx.transactionId });
|
|
27
|
+
const applied = await tx.confirm();
|
|
28
|
+
console.log(applied.result);
|
|
46
29
|
```
|
|
47
30
|
|
|
48
|
-
|
|
31
|
+
The `env: 'stage'` preset targets the staging swap backend, and `prod` targets
|
|
32
|
+
the production swap backend. All SDK traffic uses the swap backend. Use class keys such as `GALA|Unit|none|none` when a symbol is not
|
|
33
|
+
available; the SDK resolves registered symbols and orders pool tokens for you.
|
|
34
|
+
Every write returns a `SubmittedTransaction`. A swap acknowledgement has
|
|
35
|
+
`mode === 'queued'`, `result === undefined`, and a durable `uniqueKey`; call
|
|
36
|
+
`confirm()` to read its applied outcome, or `swaps.confirmSwap(uniqueKey)` to
|
|
37
|
+
resolve it later from the persisted key alone. Liquidity writes continue to
|
|
38
|
+
confirm by re-reading position state. A request `transactionId` may be `null` when the
|
|
39
|
+
gateway does not provide one.
|
|
40
|
+
|
|
41
|
+
## Hosts and environment presets
|
|
42
|
+
|
|
43
|
+
The SDK has one network boundary: the swap backend. It does not call public
|
|
44
|
+
GalaChain gateway hosts directly.
|
|
45
|
+
|
|
46
|
+
| Preset | `dexBackendBaseUrl` |
|
|
47
|
+
| ------- | ---------------------------------------------- |
|
|
48
|
+
| `stage` | `https://swap-backend.stage.defi.ovh.gala.com` |
|
|
49
|
+
| `prod` | `https://dex-backend-prod1.defi.gala.com` |
|
|
50
|
+
|
|
51
|
+
Use `dexBackendBaseUrl` for a test or private deployment override.
|
|
52
|
+
|
|
53
|
+
## Signers and identity
|
|
54
|
+
|
|
55
|
+
| Signer | Scheme | Identity resolved by the chain |
|
|
56
|
+
| --------------------- | ------------------------------------------------------------------------- | ---------------------------------------- |
|
|
57
|
+
| `PrivateKeySigner` | GalaChain native signature | Recovered from the private key |
|
|
58
|
+
| `GalaWalletSigner` | Native `gala_signChainDto`, with personal-sign fallback for older wallets | Selected Ethereum account (`0x...` form) |
|
|
59
|
+
| `BrowserWalletSigner` | EIP-1193 `personal_sign` | Selected Ethereum account (`0x...` form) |
|
|
60
|
+
|
|
61
|
+
Native signing is the default for server keys and current Gala Wallets.
|
|
62
|
+
Browser wallet personal-sign signs the bare serialized DTO (the wallet applies
|
|
63
|
+
the EIP-191 header) and sends that header as the DTO's `prefix`, which is what
|
|
64
|
+
the chain prepends when it recovers the signer. EIP-712 is
|
|
65
|
+
not part of the v2 write protocol.
|
|
66
|
+
|
|
67
|
+
## Documentation
|
|
68
|
+
|
|
69
|
+
Read the [gSwap SDK documentation](https://galachain.github.io/gswap-sdk/docs/intro)
|
|
70
|
+
for setup, quoting, trading, liquidity, signing, migration, and API reference
|
|
71
|
+
guides. Working examples are in [`examples/cli`](./examples/cli) and
|
|
72
|
+
[`examples/full_dex`](./examples/full_dex).
|
|
73
|
+
|
|
74
|
+
## License
|
|
49
75
|
|
|
50
|
-
This SDK is provided under the Apache License 2.0. Gala™, GalaChain™, and
|
|
76
|
+
This SDK is provided under the Apache License 2.0. Gala™, GalaChain™, and
|
|
77
|
+
related marks are trademarks of Blockchain Game Partners Inc. This software is
|
|
78
|
+
provided “AS IS” without warranties of any kind.
|