@cordystackx/cordy_minikit 3.0.3 → 3.0.5
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 +14 -16
- package/dist/client/jwt.d.ts +15 -15
- package/dist/client/jwt.d.ts.map +1 -1
- package/dist/client/jwt.js +65 -62
- package/dist/client/transfer.d.ts +1 -1
- package/dist/client/transfer.d.ts.map +1 -1
- package/dist/client/transfer.js +16 -7
- package/dist/client.d.ts +2 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/package.json +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
|
|
2
1
|
<div align="center">
|
|
3
2
|
<img src="https://raw.githubusercontent.com/cordyStackX/cordy_minikit_official/21cb17b5569b79b29545da80da33d82625e26c7b/assets/cordy-logo.svg" alt="Cordy Minikit logo" width="160" />
|
|
4
3
|
<h1>Cordy Minikit</h1>
|
|
5
|
-
<p>Typed Web3 toolkit for EVM and Stellar/Soroban wallet connections, balances, transfers, and
|
|
4
|
+
<p>Typed Web3 toolkit for EVM and Stellar/Soroban wallet connections, balances, transfers, and wallet connection checks.</p>
|
|
6
5
|
</div>
|
|
7
6
|
|
|
8
7
|
<p align="center">
|
|
9
|
-
<a href="https://badge.socket.dev/npm/package/@cordystackx/cordy_minikit/3.0.
|
|
10
|
-
<img src="https://badge.socket.dev/npm/package/@cordystackx/cordy_minikit/3.0.
|
|
8
|
+
<a href="https://badge.socket.dev/npm/package/@cordystackx/cordy_minikit/3.0.5">
|
|
9
|
+
<img src="https://badge.socket.dev/npm/package/@cordystackx/cordy_minikit/3.0.5" alt="Socket Badge" />
|
|
11
10
|
</a>
|
|
12
11
|
</p>
|
|
13
12
|
|
|
@@ -37,44 +36,43 @@ npm install @cordystackx/cordy_minikit
|
|
|
37
36
|
pnpm add @cordystackx/cordy_minikit
|
|
38
37
|
```
|
|
39
38
|
|
|
40
|
-
## 3.0.
|
|
39
|
+
## 3.0.5 documentation
|
|
41
40
|
|
|
42
41
|
Read the complete documentation in the [`docs/` folder](./docs/README.md):
|
|
43
42
|
|
|
44
43
|
- [Documentation index](https://github.com/cordyStackX/cordy_minikit_official/blob/main/docs/README.md)
|
|
45
44
|
- [Environment configuration](https://github.com/cordyStackX/cordy_minikit_official/blob/main/docs/environment.md)
|
|
46
|
-
- [3.0.
|
|
45
|
+
- [3.0.5 API reference](https://github.com/cordyStackX/cordy_minikit_official/blob/main/docs/api.md)
|
|
47
46
|
- [3.0.0 migration guide](https://github.com/cordyStackX/cordy_minikit_official/blob/main/docs/migration-3.0.0.md)
|
|
48
47
|
- [Provider and wallet UI setup](https://github.com/cordyStackX/cordy_minikit_official/blob/main/docs/setup.md)
|
|
49
|
-
- [Server session endpoint examples](https://github.com/cordyStackX/cordy_minikit_official/blob/main/docs/server-endpoints.md)
|
|
50
48
|
|
|
51
49
|
## Current API
|
|
52
50
|
|
|
53
51
|
```ts
|
|
54
52
|
import { cordy } from "@cordystackx/cordy_minikit";
|
|
55
53
|
|
|
56
|
-
const
|
|
54
|
+
const wallet = await cordy.cons_verify();
|
|
57
55
|
const balance = await cordy.balance();
|
|
58
56
|
const transfer = await cordy.transfer("1", recipient);
|
|
59
|
-
await cordy.
|
|
57
|
+
await cordy.cons_disconnect();
|
|
60
58
|
```
|
|
61
59
|
|
|
62
|
-
The current 3.0.
|
|
60
|
+
The current 3.0.5 API is:
|
|
63
61
|
|
|
64
62
|
- `cordy.configure({ assets })`
|
|
65
|
-
- `cordy.
|
|
66
|
-
- `cordy.
|
|
63
|
+
- `cordy.cons_verify()`
|
|
64
|
+
- `cordy.cons_disconnect()`
|
|
67
65
|
- `cordy.transfer()`
|
|
68
66
|
- `cordy.balance()`
|
|
69
67
|
- `cordy.swap(amount, from, to)`
|
|
70
68
|
|
|
71
|
-
|
|
69
|
+
`cordy.cons_verify()` checks whether an EVM or Stellar wallet is connected in the browser. It returns status `200` when connected and `401` when disconnected; it does not make an HTTP request or authenticate wallet ownership to your server. `cordy.cons_disconnect()` disconnects the wallet locally. Legacy controller helpers remain available for compatibility, but new integrations should use the `cordy.*` API.
|
|
72
70
|
|
|
73
71
|
## Experimental API
|
|
74
72
|
|
|
75
|
-
`cordy.bridge()` is experimental in 3.0.
|
|
73
|
+
`cordy.bridge()` is experimental in 3.0.5 and currently supports test USDT between BOT Chain Testnet and Ethereum Sepolia only. See the [bridge API example](./docs/api.md#cordybridgeamount-from-to-recipient).
|
|
76
74
|
|
|
77
|
-
`cordy.swap(amount, from, to)` is available for configured EVM and Stellar assets. EVM networks need a Uniswap V2-compatible `swapRouterAddress`; native EVM swaps also need `wrappedNativeTokenAddress`. Stellar swaps use Horizon strict-send path payments and require a live liquidity path.
|
|
75
|
+
`cordy.swap(amount, from, to, tolerancePercent?)` is available for configured EVM and Stellar assets. EVM networks need a Uniswap V2-compatible `swapRouterAddress`; native EVM swaps also need `wrappedNativeTokenAddress`. Stellar swaps use Horizon strict-send path payments and require a live liquidity path. The optional fourth argument is a percentage: `1` means 1% tolerance, and omission defaults to 1%.
|
|
78
76
|
|
|
79
77
|
## Links
|
|
80
78
|
|
|
@@ -82,4 +80,4 @@ Use `cordy.jwt_verify()` to check the app's session. Legacy controller helpers r
|
|
|
82
80
|
- [GitHub repository](https://github.com/cordyStackX/cordy_minikit_official)
|
|
83
81
|
- [Changelog](https://github.com/cordyStackX/cordy_minikit_official/blob/main/CHANGELOG.md)
|
|
84
82
|
- [Contributing guide](https://github.com/cordyStackX/cordy_minikit_official/blob/main/CONTRIBUTING.md)
|
|
85
|
-
- [Security policy](https://github.com/cordyStackX/cordy_minikit_official/blob/main/SECURITY.md)
|
|
83
|
+
- [Security policy](https://github.com/cordyStackX/cordy_minikit_official/blob/main/SECURITY.md)
|
package/dist/client/jwt.d.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import { configureCordyAssets, cordy_balance, cordy_bridge, cordy_swap, cordy_transfer } from "./transfer";
|
|
2
|
-
export type
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export type ConsVerifyResult = {
|
|
3
|
+
/** Application-level status; no HTTP request is made. */
|
|
4
|
+
status: 200 | 401;
|
|
5
|
+
connected: boolean;
|
|
6
|
+
network?: "evm" | "stellar";
|
|
7
|
+
address?: string;
|
|
5
8
|
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
10
|
-
export type JwtDisconnectResult = {
|
|
9
|
+
/** @deprecated Use JwtVerifyResult; this describes wallet state, not a JWT session. */
|
|
10
|
+
export type ConsSessionResult = ConsVerifyResult;
|
|
11
|
+
export type ConsDisconnectResult = {
|
|
11
12
|
success: boolean;
|
|
12
13
|
walletDisconnected: boolean;
|
|
13
|
-
status?: number;
|
|
14
14
|
error?: string;
|
|
15
15
|
};
|
|
16
|
-
/**
|
|
17
|
-
export declare function
|
|
18
|
-
/**
|
|
19
|
-
export declare function
|
|
16
|
+
/** Check whether this browser currently has a connected EVM or Stellar wallet. */
|
|
17
|
+
export declare function cons_verify(): Promise<ConsVerifyResult>;
|
|
18
|
+
/** Disconnect the connected EVM wallet and clear the Minikit Stellar wallet selection. */
|
|
19
|
+
export declare function cons_disconnect(): Promise<ConsDisconnectResult>;
|
|
20
20
|
export declare const cordy: {
|
|
21
21
|
configure: typeof configureCordyAssets;
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
cons_verify: typeof cons_verify;
|
|
23
|
+
cons_disconnect: typeof cons_disconnect;
|
|
24
24
|
balance: typeof cordy_balance;
|
|
25
25
|
transfer: typeof cordy_transfer;
|
|
26
26
|
swap: typeof cordy_swap;
|
package/dist/client/jwt.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../client/jwt.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE3G,MAAM,MAAM,gBAAgB,GAAG;IAC7B,
|
|
1
|
+
{"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../client/jwt.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE3G,MAAM,MAAM,gBAAgB,GAAG;IAC7B,yDAAyD;IACzD,MAAM,EAAE,GAAG,GAAG,GAAG,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,uFAAuF;AACvF,MAAM,MAAM,iBAAiB,GAAG,gBAAgB,CAAC;AAEjD,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAkBF,kFAAkF;AAClF,wBAAsB,WAAW,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAgC7D;AAED,0FAA0F;AAC1F,wBAAsB,eAAe,IAAI,OAAO,CAAC,oBAAoB,CAAC,CAyBrE;AAED,eAAO,MAAM,KAAK;;;;;;;;CAQjB,CAAC"}
|
package/dist/client/jwt.js
CHANGED
|
@@ -1,79 +1,82 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { configureCordyAssets, cordy_balance, cordy_bridge, cordy_swap, cordy_transfer } from "./transfer";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
throw new Error(`Session check failed (${response.status})`);
|
|
3
|
+
const STELLAR_WALLET_STORAGE_KEY = "cordy_minikit_stellar_wallet";
|
|
4
|
+
const ACTIVE_WALLET_SESSION_KEY = "cordy_minikit_active_wallet_session";
|
|
5
|
+
function getStellarAddress() {
|
|
6
|
+
try {
|
|
7
|
+
const raw = window.localStorage.getItem(STELLAR_WALLET_STORAGE_KEY);
|
|
8
|
+
if (!raw)
|
|
9
|
+
return undefined;
|
|
10
|
+
const wallet = JSON.parse(raw);
|
|
11
|
+
if (typeof wallet !== "object" || wallet === null || !("address" in wallet))
|
|
12
|
+
return undefined;
|
|
13
|
+
const address = wallet.address;
|
|
14
|
+
return typeof address === "string" && address.length > 0 ? address : undefined;
|
|
16
15
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return { ...data, authenticated: true };
|
|
16
|
+
catch {
|
|
17
|
+
return undefined;
|
|
20
18
|
}
|
|
21
|
-
return { authenticated: true };
|
|
22
19
|
}
|
|
23
|
-
/**
|
|
24
|
-
export async function
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
let errorMessage;
|
|
28
|
-
try {
|
|
29
|
-
const response = await fetch(options.endpoint ?? "/api/auth/logout", {
|
|
30
|
-
method: "POST",
|
|
31
|
-
credentials: "include",
|
|
32
|
-
cache: "no-store",
|
|
33
|
-
headers: { Accept: "application/json" },
|
|
34
|
-
});
|
|
35
|
-
status = response.status;
|
|
36
|
-
// A missing or expired session is already logged out.
|
|
37
|
-
sessionCleared = response.ok || response.status === 401;
|
|
38
|
-
if (!sessionCleared)
|
|
39
|
-
errorMessage = `Session logout failed (${response.status})`;
|
|
20
|
+
/** Check whether this browser currently has a connected EVM or Stellar wallet. */
|
|
21
|
+
export async function cons_verify() {
|
|
22
|
+
if (typeof window === "undefined") {
|
|
23
|
+
return { status: 401, connected: false };
|
|
40
24
|
}
|
|
41
|
-
|
|
42
|
-
|
|
25
|
+
const stellarAddress = getStellarAddress();
|
|
26
|
+
const activeWallet = window.localStorage.getItem(ACTIVE_WALLET_SESSION_KEY);
|
|
27
|
+
if (activeWallet === "stellar" && stellarAddress) {
|
|
28
|
+
return { status: 200, connected: true, network: "stellar", address: stellarAddress };
|
|
43
29
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
window.localStorage.removeItem("cordy_minikit_stellar_wallet");
|
|
55
|
-
window.localStorage.removeItem("cordy_minikit_active_wallet_session");
|
|
56
|
-
window.dispatchEvent(new Event("cordy:disconnect-stellar-wallet"));
|
|
57
|
-
walletDisconnected = true;
|
|
30
|
+
try {
|
|
31
|
+
const { getActiveWagmiConfig } = await import("../config/walletConfig");
|
|
32
|
+
const state = getActiveWagmiConfig().state;
|
|
33
|
+
const currentConnection = state.current ? state.connections.get(state.current) : undefined;
|
|
34
|
+
const connection = currentConnection?.accounts[0]
|
|
35
|
+
? currentConnection
|
|
36
|
+
: Array.from(state.connections.values()).find((item) => item.accounts[0]);
|
|
37
|
+
const address = connection?.accounts[0];
|
|
38
|
+
if (address) {
|
|
39
|
+
return { status: 200, connected: true, network: "evm", address };
|
|
58
40
|
}
|
|
59
|
-
|
|
60
|
-
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
// A missing or unavailable EVM connector does not prevent checking Stellar.
|
|
44
|
+
}
|
|
45
|
+
if (stellarAddress) {
|
|
46
|
+
return { status: 200, connected: true, network: "stellar", address: stellarAddress };
|
|
47
|
+
}
|
|
48
|
+
return { status: 401, connected: false };
|
|
49
|
+
}
|
|
50
|
+
/** Disconnect the connected EVM wallet and clear the Minikit Stellar wallet selection. */
|
|
51
|
+
export async function cons_disconnect() {
|
|
52
|
+
if (typeof window === "undefined") {
|
|
53
|
+
return { success: false, walletDisconnected: false, error: "Wallet disconnect is only available in the browser." };
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
const { disconnect } = await import("wagmi/actions");
|
|
57
|
+
const { getActiveWagmiConfig } = await import("../config/walletConfig");
|
|
58
|
+
const config = getActiveWagmiConfig();
|
|
59
|
+
const connections = Array.from(config.state.connections.values());
|
|
60
|
+
for (const connection of connections) {
|
|
61
|
+
await disconnect(config, { connector: connection.connector });
|
|
61
62
|
}
|
|
63
|
+
window.localStorage.removeItem(STELLAR_WALLET_STORAGE_KEY);
|
|
64
|
+
window.localStorage.removeItem(ACTIVE_WALLET_SESSION_KEY);
|
|
65
|
+
window.dispatchEvent(new Event("cordy:disconnect-stellar-wallet"));
|
|
66
|
+
return { success: true, walletDisconnected: true };
|
|
62
67
|
}
|
|
63
|
-
|
|
64
|
-
|
|
68
|
+
catch (error) {
|
|
69
|
+
return {
|
|
70
|
+
success: false,
|
|
71
|
+
walletDisconnected: false,
|
|
72
|
+
error: error instanceof Error ? error.message : "Wallet disconnect failed.",
|
|
73
|
+
};
|
|
65
74
|
}
|
|
66
|
-
return {
|
|
67
|
-
success: sessionCleared && walletDisconnected,
|
|
68
|
-
walletDisconnected,
|
|
69
|
-
status,
|
|
70
|
-
...(errorMessage ? { error: errorMessage } : {}),
|
|
71
|
-
};
|
|
72
75
|
}
|
|
73
76
|
export const cordy = {
|
|
74
77
|
configure: configureCordyAssets,
|
|
75
|
-
|
|
76
|
-
|
|
78
|
+
cons_verify,
|
|
79
|
+
cons_disconnect,
|
|
77
80
|
balance: cordy_balance,
|
|
78
81
|
transfer: cordy_transfer,
|
|
79
82
|
swap: cordy_swap,
|
|
@@ -55,7 +55,7 @@ export declare function cordy_bridge(amount: number | string, from: CordyBridgeS
|
|
|
55
55
|
/** Read the full-precision balance for the active wallet and selected asset. */
|
|
56
56
|
export declare function cordy_balance(options?: CordyBalanceOptions): Promise<CordyBalanceResult>;
|
|
57
57
|
/** Swap two configured assets using the active EVM or Stellar wallet. */
|
|
58
|
-
export declare function cordy_swap(amount: number | string, from: string, to: string): Promise<CordySwapResult>;
|
|
58
|
+
export declare function cordy_swap(amount: number | string, from: string, to: string, tolerancePercent?: number): Promise<CordySwapResult>;
|
|
59
59
|
/** Configure a caller-owned JSON asset registry before requesting transfers. */
|
|
60
60
|
export declare function cordy_configure(options: {
|
|
61
61
|
assets: CordyAssetsConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transfer.d.ts","sourceRoot":"","sources":["../../client/transfer.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,iBAAiB,EAAwD,MAAM,iBAAiB,CAAC;AAE/G,YAAY,EAAE,iBAAiB,EAAE,cAAc,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAKrI,MAAM,MAAM,oBAAoB,GAAG;IACjC,sDAAsD;IACtD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;IAC5B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,iHAAiH;IACjH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;IAC5B,IAA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AC;IACjC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAsBF,wBAAgB,oBAAoB,CAAC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,iBAAiB,CAAA;CAAE,GAAG,IAAI,CAcpF;AAuND,6FAA6F;AAC7F,wBAAsB,YAAY,CAChC,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,IAAI,EAAE,eAAe,EACrB,EAAE,EAAE,eAAe,EACnB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,iBAAiB,CAAC,CAM5B;AAyHD,gFAAgF;AAChF,wBAAsB,aAAa,CAAC,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAYlG;AA0MD,yEAAyE;AACzE,wBAAsB,UAAU,CAC9B,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,gBAAgB,SAAiC,GAChD,OAAO,CAAC,eAAe,CAAC,CAW1B;AAED,gFAAgF;AAChF,wBAAgB,eAAe,CAAC,OAAO,EAAE;IAAE,MAAM,EAAE,iBAAiB,CAAA;CAAE,GAAG,IAAI,CAE5E;AAED,2EAA2E;AAC3E,wBAAsB,cAAc,CAClC,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,mBAAmB,CAAC,CAa9B"}
|
package/dist/client/transfer.js
CHANGED
|
@@ -105,6 +105,14 @@ const ERC20_SWAP_ABI = [
|
|
|
105
105
|
"function allowance(address owner,address spender) view returns (uint256)",
|
|
106
106
|
"function decimals() view returns (uint8)",
|
|
107
107
|
];
|
|
108
|
+
const SWAP_BPS_DENOMINATOR = 10000n;
|
|
109
|
+
const DEFAULT_SWAP_TOLERANCE_PERCENT = 1;
|
|
110
|
+
function swapMinimumOutputBps(tolerancePercent = DEFAULT_SWAP_TOLERANCE_PERCENT) {
|
|
111
|
+
if (!Number.isFinite(tolerancePercent) || tolerancePercent < 0 || tolerancePercent >= 100) {
|
|
112
|
+
throw new Error("Swap tolerance must be a number from 0% up to, but not including, 100%.");
|
|
113
|
+
}
|
|
114
|
+
return BigInt(Math.round((100 - tolerancePercent) * 100));
|
|
115
|
+
}
|
|
108
116
|
function resolveEvmSwapNetworkConfig(chainId) {
|
|
109
117
|
const registered = configuredAssets?.networks?.find((network) => network.chainId === chainId);
|
|
110
118
|
if (registered)
|
|
@@ -428,7 +436,7 @@ async function transferStellar(amount, recipient, requestedSymbol, memo) {
|
|
|
428
436
|
throw new Error("Stellar transfer did not complete successfully.");
|
|
429
437
|
return { success: true, asset: symbol, network: "stellar", transactionHash: receipt.hash };
|
|
430
438
|
}
|
|
431
|
-
async function swapEvm(amount, fromSymbol, toSymbol) {
|
|
439
|
+
async function swapEvm(amount, fromSymbol, toSymbol, tolerancePercent) {
|
|
432
440
|
const walletConfig = getActiveWagmiConfig();
|
|
433
441
|
const current = walletConfig.state.current;
|
|
434
442
|
const connection = current ? walletConfig.state.connections.get(current) : undefined;
|
|
@@ -470,7 +478,7 @@ async function swapEvm(amount, fromSymbol, toSymbol) {
|
|
|
470
478
|
const quotedOut = BigInt(amounts[amounts.length - 1].toString());
|
|
471
479
|
if (quotedOut <= 0n)
|
|
472
480
|
throw new Error(`No swap quote is available for ${fromSymbol} to ${toSymbol} on ${networkName}.`);
|
|
473
|
-
const minOut = quotedOut *
|
|
481
|
+
const minOut = quotedOut * swapMinimumOutputBps(tolerancePercent) / SWAP_BPS_DENOMINATOR;
|
|
474
482
|
const deadline = Math.floor(Date.now() / 1000) + 20 * 60;
|
|
475
483
|
let transaction;
|
|
476
484
|
if (fromNative) {
|
|
@@ -511,7 +519,7 @@ async function swapEvm(amount, fromSymbol, toSymbol) {
|
|
|
511
519
|
function stellarAssetFromConfig(asset) {
|
|
512
520
|
return asset.type === "native" ? Asset.native() : new Asset(asset.code, asset.issuer);
|
|
513
521
|
}
|
|
514
|
-
async function swapStellar(amount, fromSymbol, toSymbol) {
|
|
522
|
+
async function swapStellar(amount, fromSymbol, toSymbol, tolerancePercent) {
|
|
515
523
|
const stellarConfig = requireStellarNetwork();
|
|
516
524
|
if (fromSymbol.toLowerCase() === toSymbol.toLowerCase())
|
|
517
525
|
throw new Error("Choose two different assets to swap.");
|
|
@@ -535,7 +543,7 @@ async function swapStellar(amount, fromSymbol, toSymbol) {
|
|
|
535
543
|
const route = paths.records[0];
|
|
536
544
|
if (!route)
|
|
537
545
|
throw new Error(`No Stellar path is available to swap ${fromSymbol} to ${toSymbol}.`);
|
|
538
|
-
const minOut = (Number(route.destination_amount) *
|
|
546
|
+
const minOut = (Number(route.destination_amount) * Number(swapMinimumOutputBps(tolerancePercent)) / Number(SWAP_BPS_DENOMINATOR)).toFixed(7);
|
|
539
547
|
const routeAssets = route.path.map((item) => item.asset_type === "native"
|
|
540
548
|
? Asset.native()
|
|
541
549
|
: new Asset(item.asset_code, item.asset_issuer));
|
|
@@ -567,13 +575,14 @@ async function swapStellar(amount, fromSymbol, toSymbol) {
|
|
|
567
575
|
};
|
|
568
576
|
}
|
|
569
577
|
/** Swap two configured assets using the active EVM or Stellar wallet. */
|
|
570
|
-
export async function cordy_swap(amount, from, to) {
|
|
578
|
+
export async function cordy_swap(amount, from, to, tolerancePercent = DEFAULT_SWAP_TOLERANCE_PERCENT) {
|
|
571
579
|
try {
|
|
580
|
+
swapMinimumOutputBps(tolerancePercent);
|
|
572
581
|
const normalized = normalizedAmount(amount);
|
|
573
582
|
const activeWallet = getActiveWallet();
|
|
574
583
|
return activeWallet === "stellar"
|
|
575
|
-
? await swapStellar(normalized, from, to)
|
|
576
|
-
: await swapEvm(normalized, from, to);
|
|
584
|
+
? await swapStellar(normalized, from, to, tolerancePercent)
|
|
585
|
+
: await swapEvm(normalized, from, to, tolerancePercent);
|
|
577
586
|
}
|
|
578
587
|
catch (error) {
|
|
579
588
|
return { success: false, error: error instanceof Error ? error.message : "Could not swap the selected assets." };
|
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { cordy,
|
|
2
|
-
export type {
|
|
1
|
+
export { cordy, cons_verify, cons_disconnect } from "./client/jwt";
|
|
2
|
+
export type { ConsDisconnectResult, ConsSessionResult, ConsVerifyResult } from "./client/jwt";
|
|
3
3
|
export { configureCordyAssets, cordy_configure, cordy_bridge, cordy_swap, cordy_transfer } from "./client/transfer";
|
|
4
4
|
export type { CordyAssetsConfig, CordyBridgeResult, CordyBridgeSide, CordyTransferOptions, CordyTransferResult, CordySwapResult, EvmAssetConfig, EvmNetworkConfig, StellarAssetConfig } from "./client/transfer";
|
|
5
5
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACnE,YAAY,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAE9F,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACpH,YAAY,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,eAAe,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,eAAe,EAAE,cAAc,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/client.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { cordy,
|
|
1
|
+
export { cordy, cons_verify, cons_disconnect } from "./client/jwt";
|
|
2
2
|
export { configureCordyAssets, cordy_configure, cordy_bridge, cordy_swap, cordy_transfer } from "./client/transfer";
|
package/dist/index.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ export { default as getConfig } from "./config/walletConfig";
|
|
|
3
3
|
export { useWalletModal } from "./wagmi__providers";
|
|
4
4
|
export { ConnectWalletBT } from "./components";
|
|
5
5
|
export { CordyStackTrans, CordyStackTransStellar, useWalletStatus, useDisconnectWallets, WalletButton, StellarWalletButton } from "./controllers";
|
|
6
|
-
export { cordy,
|
|
7
|
-
export type {
|
|
6
|
+
export { cordy, cons_verify, cons_disconnect } from "./client";
|
|
7
|
+
export type { ConsDisconnectResult, ConsSessionResult, ConsVerifyResult } from "./client";
|
|
8
8
|
export { configureCordyAssets, cordy_balance, cordy_configure, cordy_bridge, cordy_swap, cordy_transfer } from "./client/transfer";
|
|
9
9
|
export type { CordyAssetsConfig, CordyBalanceOptions, CordyBalanceResult, CordyTransferOptions, CordyTransferResult, CordySwapResult, CordyBridgeResult, CordyBridgeSide, EvmAssetConfig, EvmNetworkConfig, StellarAssetConfig, StellarNetworkConfig } from "./client/transfer";
|
|
10
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,IAAI,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAGvE,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAG7D,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGpD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAG/C,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,eAAe,EACf,oBAAoB,EACpB,YAAY,EACZ,mBAAmB,EACpB,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,IAAI,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAGvE,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAG7D,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGpD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAG/C,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,eAAe,EACf,oBAAoB,EACpB,YAAY,EACZ,mBAAmB,EACpB,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC/D,YAAY,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE1F,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,eAAe,EAAE,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnI,YAAY,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,eAAe,EAAE,iBAAiB,EAAE,eAAe,EAAE,cAAc,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -9,5 +9,5 @@ export { ConnectWalletBT } from "./components";
|
|
|
9
9
|
//Controllers
|
|
10
10
|
export { CordyStackTrans, CordyStackTransStellar, useWalletStatus, useDisconnectWallets, WalletButton, StellarWalletButton } from "./controllers";
|
|
11
11
|
// Client-side JWT session helpers (safe for browser imports).
|
|
12
|
-
export { cordy,
|
|
12
|
+
export { cordy, cons_verify, cons_disconnect } from "./client";
|
|
13
13
|
export { configureCordyAssets, cordy_balance, cordy_configure, cordy_bridge, cordy_swap, cordy_transfer } from "./client/transfer";
|