@scallop-io/scallop-swap-sdk-react 1.2.0 → 2.0.0
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/index.d.mts +9 -4
- package/dist/index.d.ts +9 -4
- package/dist/index.js +7 -7
- package/dist/index.mjs +3 -3
- package/package.json +10 -13
- package/src/index.ts +11 -6
- package/src/providers/scallop-swap-sdk-provider/index.tsx +10 -27
- package/src/providers/scallop-swap-sdk-provider/types.ts +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
2
2
|
import { UseQueryOptions, QueryKey, UseMutationOptions } from '@tanstack/react-query';
|
|
3
3
|
import { Aggregator, FetchRouteResult } from '@scallop-io/scallop-swap-sdk';
|
|
4
|
-
export {
|
|
4
|
+
export { FetchRouteResult, FormattedRouteResult } from '@scallop-io/scallop-swap-sdk';
|
|
5
5
|
import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
|
|
6
|
-
import { SuiClient } from '@mysten/sui/client';
|
|
7
6
|
import { QueryClient } from '@tanstack/query-core';
|
|
7
|
+
import { ClientWithCoreApi } from '@mysten/sui/client';
|
|
8
8
|
import { FC, PropsWithChildren } from 'react';
|
|
9
9
|
import { StateStorage } from 'zustand/middleware';
|
|
10
|
+
export { CetusFetchRouteSettings, RouterDataV3 } from '@scallop-io/scallop-swap-sdk/cetus';
|
|
11
|
+
export { AggregatorQuoter, FlowXFetchRouteSettings, GetRoutesResult } from '@scallop-io/scallop-swap-sdk/flowx';
|
|
12
|
+
export { Aftermath, AftermathFetchRouteSettings, RouterCompleteTradeRoute } from '@scallop-io/scallop-swap-sdk/aftermath';
|
|
13
|
+
export { _7kFetchRouteSettings, _7kQuoteResponse } from '@scallop-io/scallop-swap-sdk/7k';
|
|
10
14
|
|
|
11
15
|
type SwapRoutesResult = Awaited<ReturnType<Aggregator['fetchRoutes']>>;
|
|
12
16
|
declare const useGetSwapRoutes: ({ coinInType, coinOutType, swapAmount, }: {
|
|
@@ -54,11 +58,12 @@ declare const useBuildSwapTransaction: ({ mutationKey, ...mutationOptions }?: Us
|
|
|
54
58
|
|
|
55
59
|
type ScallopSwapSdkProviderContext = {
|
|
56
60
|
aggregator: Aggregator;
|
|
57
|
-
client:
|
|
61
|
+
client: ClientWithCoreApi;
|
|
58
62
|
};
|
|
59
63
|
type ScallopSwapSdkProviderProps = {
|
|
60
|
-
client:
|
|
64
|
+
client: ClientWithCoreApi;
|
|
61
65
|
walletAddress: string;
|
|
66
|
+
swaps?: Parameters<Aggregator['addAggregator']>[0];
|
|
62
67
|
aggregator?: Aggregator;
|
|
63
68
|
queryClient?: QueryClient;
|
|
64
69
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
2
2
|
import { UseQueryOptions, QueryKey, UseMutationOptions } from '@tanstack/react-query';
|
|
3
3
|
import { Aggregator, FetchRouteResult } from '@scallop-io/scallop-swap-sdk';
|
|
4
|
-
export {
|
|
4
|
+
export { FetchRouteResult, FormattedRouteResult } from '@scallop-io/scallop-swap-sdk';
|
|
5
5
|
import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
|
|
6
|
-
import { SuiClient } from '@mysten/sui/client';
|
|
7
6
|
import { QueryClient } from '@tanstack/query-core';
|
|
7
|
+
import { ClientWithCoreApi } from '@mysten/sui/client';
|
|
8
8
|
import { FC, PropsWithChildren } from 'react';
|
|
9
9
|
import { StateStorage } from 'zustand/middleware';
|
|
10
|
+
export { CetusFetchRouteSettings, RouterDataV3 } from '@scallop-io/scallop-swap-sdk/cetus';
|
|
11
|
+
export { AggregatorQuoter, FlowXFetchRouteSettings, GetRoutesResult } from '@scallop-io/scallop-swap-sdk/flowx';
|
|
12
|
+
export { Aftermath, AftermathFetchRouteSettings, RouterCompleteTradeRoute } from '@scallop-io/scallop-swap-sdk/aftermath';
|
|
13
|
+
export { _7kFetchRouteSettings, _7kQuoteResponse } from '@scallop-io/scallop-swap-sdk/7k';
|
|
10
14
|
|
|
11
15
|
type SwapRoutesResult = Awaited<ReturnType<Aggregator['fetchRoutes']>>;
|
|
12
16
|
declare const useGetSwapRoutes: ({ coinInType, coinOutType, swapAmount, }: {
|
|
@@ -54,11 +58,12 @@ declare const useBuildSwapTransaction: ({ mutationKey, ...mutationOptions }?: Us
|
|
|
54
58
|
|
|
55
59
|
type ScallopSwapSdkProviderContext = {
|
|
56
60
|
aggregator: Aggregator;
|
|
57
|
-
client:
|
|
61
|
+
client: ClientWithCoreApi;
|
|
58
62
|
};
|
|
59
63
|
type ScallopSwapSdkProviderProps = {
|
|
60
|
-
client:
|
|
64
|
+
client: ClientWithCoreApi;
|
|
61
65
|
walletAddress: string;
|
|
66
|
+
swaps?: Parameters<Aggregator['addAggregator']>[0];
|
|
62
67
|
aggregator?: Aggregator;
|
|
63
68
|
queryClient?: QueryClient;
|
|
64
69
|
};
|
package/dist/index.js
CHANGED
|
@@ -7,12 +7,12 @@ var zustand = require('zustand');
|
|
|
7
7
|
var middleware = require('zustand/middleware');
|
|
8
8
|
var jsxRuntime = require('react/jsx-runtime');
|
|
9
9
|
|
|
10
|
-
var S=react.createContext(null);var
|
|
10
|
+
var S=react.createContext(null);var m=()=>{let t=new Map;return {getItem(e){return t.get(e)},setItem(e,o){t.set(e,o);},removeItem(e){t.delete(e);}}};var d=.003,f=typeof window<"u"&&window.localStorage?localStorage:m(),C="scallop-swap-sdk-react-wallet-store-v1";var h=({storageKey:t})=>zustand.createStore()(middleware.persist((e,o)=>({activeAggregatorNames:{},slippage:d,activeDexes:{},setDefaultActiveDexes:r=>{e({activeDexes:r});},setActiveAggregatorNames:r=>{e({activeAggregatorNames:r});},setSlippage:r=>{e({slippage:r});},setActiveDexes:(r,n,s)=>{let a={...o().activeDexes};a[r][n]=s,e({activeDexes:a});},setBulkActiveDexes:(r,n)=>{let s={...o().activeDexes};s[r]=n,e({activeDexes:s});}}),{name:t,storage:middleware.createJSONStorage(()=>f)}));function p(t){let e=react.useContext(S);if(!e)throw new Error("Could not find SdkConfigContext. Ensure that you have set up the SdkConfigProvider.");return zustand.useStore(e,t)}var k=()=>{let t=p(s=>s.setActiveDexes),e=p(s=>s.setBulkActiveDexes),o=p(s=>s.activeDexes),r=react.useRef(o);r.current=o;let n=g().aggregator;react.useEffect(()=>{let s=({name:a,pool:i,enabled:u})=>{t(a,i,u);};return n.events.on("poolStatusChanged",s),()=>{n.events.off("poolStatusChanged",s);}},[n,t]),react.useEffect(()=>{let s=({name:a,enabled:i})=>{let u=r.current,c=Object.keys(u[a]||{}).reduce((A,F)=>(A[F]=i,A),{});e(a,c);};return n.events.on("allPoolStatusChanged",s),()=>{n.events.off("allPoolStatusChanged",s);}},[n,e]);};var P=()=>{let t=p(n=>n.activeDexes),e=p(n=>n.slippage),o=g().aggregator,r=p(n=>n.setDefaultActiveDexes);react.useEffect(()=>{if(Object.keys(t).length===0){let n=o.aggregators.reduce((s,a)=>(s[a.name]=a.pools.reduce((i,u)=>(i[u]=true,i),{}),s),{});r(n);}else Object.entries(t).forEach(([n,s])=>{let a=o.getAggregator(n);a&&(a.poolsMap=new Map(Object.entries(s)));});},[o]),react.useEffect(()=>{o.setSlippage(e);},[o]);};var E=()=>{let t=g().aggregator,e=p(o=>o.setSlippage);react.useEffect(()=>{let o=({slippageInDecimal:r})=>{e(r);};return t.events.on("aggregatorSlippageChanged",o),()=>{t.events.off("aggregatorSlippageChanged",o);}},[t,e]);};var x=({storage:t=f,storageKey:e=C,children:o})=>{let r=react.useRef(h({storageKey:e}));return jsxRuntime.jsx(S.Provider,{value:r.current,children:jsxRuntime.jsx(_,{children:o})})},_=({children:t})=>(P(),E(),k(),t);var v=react.createContext(null),W=({children:t,client:e,walletAddress:o,swaps:r,aggregator:n,queryClient:s})=>{let a=react.useMemo(()=>{if(n)return n;let c=new scallopSwapSdk.Aggregator({client:e,walletAddress:o});return c.setSlippage(d),r&&r.length>0&&c.addAggregator(r),c},[n,e,o,r]),i=react.useMemo(()=>s??new reactQuery.QueryClient,[s]),u=react.useMemo(()=>({aggregator:a,client:e}),[a,e]);return jsxRuntime.jsx(v.Provider,{value:u,children:jsxRuntime.jsx(reactQuery.QueryClientProvider,{client:i,children:jsxRuntime.jsx(x,{children:t})})})};var g=()=>{let t=react.useContext(v);if(!t)throw new Error("Could not find ScallopSwapSdkContext. Ensure that you have set up the ScallopSwapSdkProvider");return t};var l={api:{getAggregatorFetchStatus:()=>["api","getAggregatorFetchStatus"],getSwapRoutes:t=>["api","getSwapRoutes",t?.coinInType,t?.coinOutType,t?.swapAmount]},sdk:{aggregatorQuery:t=>[t.method,t.params]}};function V(t,e){let o=(t?.routes??[]).filter(n=>n.formattedResult.name!==e.formattedResult.name),r=o.findIndex(n=>e.formattedResult.coinOut.amount>=n.formattedResult.coinOut.amount);return r===-1?o.push(e):o.splice(r,0,e),{routes:o,errors:t?.errors??[]}}var X=({coinInType:t,coinOutType:e,swapAmount:o},r)=>{let{aggregator:n}=g(),s=reactQuery.useQueryClient(),a=l.api.getSwapRoutes({coinInType:t,coinOutType:e,swapAmount:o});return reactQuery.useQuery({...r,queryKey:a,queryFn:()=>n.fetchRoutes({coinInType:t,coinOutType:e,swapAmount:BigInt(o)},{onRouteFound:i=>{s.setQueryData(a,u=>V(u,i));},onError:i=>{console.error("Error fetching routes:",i);}})})};var Z=({mutationKey:t,...e}={})=>{let o=g();return reactQuery.useMutation({mutationKey:t??["buildSwapTransaction",o.client.network],mutationFn:async({route:r,options:n={}})=>{let{txExtensionParams:s,mergeResult:a,slippage:i}=n;return a===false?o.aggregator.buildRouteTransaction(r,{txExtensionParams:s,mergeResult:false,slippage:i}):o.aggregator.buildRouteTransaction(r,{txExtensionParams:s,slippage:i})},...e})};var oe=t=>{let{aggregator:e}=g(),o=reactQuery.useQueryClient(),r=l.api.getAggregatorFetchStatus();return react.useEffect(()=>{let n=({name:a})=>{o.setQueryData(r,i=>({...i??e.fetchingStatus,[a]:true}));},s=({name:a})=>{o.setQueryData(r,i=>({...i??e.fetchingStatus,[a]:false}));};return e.events.on("aggregatorFetchStart",n),e.events.on("aggregatorFetchEnd",s),()=>{e.events.off("aggregatorFetchStart",n),e.events.off("aggregatorFetchEnd",s);}},[e,o]),reactQuery.useQuery({...t,queryKey:r,staleTime:1/0,queryFn:()=>e.fetchingStatus})};
|
|
11
11
|
|
|
12
|
-
exports.ScallopSwapSdkProvider =
|
|
13
|
-
exports.SdkConfigProvider =
|
|
14
|
-
exports.queryKeys =
|
|
12
|
+
exports.ScallopSwapSdkProvider = W;
|
|
13
|
+
exports.SdkConfigProvider = x;
|
|
14
|
+
exports.queryKeys = l;
|
|
15
15
|
exports.useAggregatorContext = g;
|
|
16
|
-
exports.useAggregatorFetchingStatus =
|
|
17
|
-
exports.useBuildSwapTransaction =
|
|
18
|
-
exports.useGetSwapRoutes =
|
|
16
|
+
exports.useAggregatorFetchingStatus = oe;
|
|
17
|
+
exports.useBuildSwapTransaction = Z;
|
|
18
|
+
exports.useGetSwapRoutes = X;
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { QueryClient, QueryClientProvider, useQueryClient, useQuery, useMutation } from '@tanstack/react-query';
|
|
2
2
|
import { createContext, useRef, useMemo, useContext, useEffect } from 'react';
|
|
3
|
-
import { Aggregator
|
|
3
|
+
import { Aggregator } from '@scallop-io/scallop-swap-sdk';
|
|
4
4
|
import { createStore, useStore } from 'zustand';
|
|
5
5
|
import { persist, createJSONStorage } from 'zustand/middleware';
|
|
6
6
|
import { jsx } from 'react/jsx-runtime';
|
|
7
7
|
|
|
8
|
-
var S=createContext(null);var
|
|
8
|
+
var S=createContext(null);var m=()=>{let t=new Map;return {getItem(e){return t.get(e)},setItem(e,o){t.set(e,o);},removeItem(e){t.delete(e);}}};var d=.003,f=typeof window<"u"&&window.localStorage?localStorage:m(),C="scallop-swap-sdk-react-wallet-store-v1";var h=({storageKey:t})=>createStore()(persist((e,o)=>({activeAggregatorNames:{},slippage:d,activeDexes:{},setDefaultActiveDexes:r=>{e({activeDexes:r});},setActiveAggregatorNames:r=>{e({activeAggregatorNames:r});},setSlippage:r=>{e({slippage:r});},setActiveDexes:(r,n,s)=>{let a={...o().activeDexes};a[r][n]=s,e({activeDexes:a});},setBulkActiveDexes:(r,n)=>{let s={...o().activeDexes};s[r]=n,e({activeDexes:s});}}),{name:t,storage:createJSONStorage(()=>f)}));function p(t){let e=useContext(S);if(!e)throw new Error("Could not find SdkConfigContext. Ensure that you have set up the SdkConfigProvider.");return useStore(e,t)}var k=()=>{let t=p(s=>s.setActiveDexes),e=p(s=>s.setBulkActiveDexes),o=p(s=>s.activeDexes),r=useRef(o);r.current=o;let n=g().aggregator;useEffect(()=>{let s=({name:a,pool:i,enabled:u})=>{t(a,i,u);};return n.events.on("poolStatusChanged",s),()=>{n.events.off("poolStatusChanged",s);}},[n,t]),useEffect(()=>{let s=({name:a,enabled:i})=>{let u=r.current,c=Object.keys(u[a]||{}).reduce((A,F)=>(A[F]=i,A),{});e(a,c);};return n.events.on("allPoolStatusChanged",s),()=>{n.events.off("allPoolStatusChanged",s);}},[n,e]);};var P=()=>{let t=p(n=>n.activeDexes),e=p(n=>n.slippage),o=g().aggregator,r=p(n=>n.setDefaultActiveDexes);useEffect(()=>{if(Object.keys(t).length===0){let n=o.aggregators.reduce((s,a)=>(s[a.name]=a.pools.reduce((i,u)=>(i[u]=true,i),{}),s),{});r(n);}else Object.entries(t).forEach(([n,s])=>{let a=o.getAggregator(n);a&&(a.poolsMap=new Map(Object.entries(s)));});},[o]),useEffect(()=>{o.setSlippage(e);},[o]);};var E=()=>{let t=g().aggregator,e=p(o=>o.setSlippage);useEffect(()=>{let o=({slippageInDecimal:r})=>{e(r);};return t.events.on("aggregatorSlippageChanged",o),()=>{t.events.off("aggregatorSlippageChanged",o);}},[t,e]);};var x=({storage:t=f,storageKey:e=C,children:o})=>{let r=useRef(h({storageKey:e}));return jsx(S.Provider,{value:r.current,children:jsx(_,{children:o})})},_=({children:t})=>(P(),E(),k(),t);var v=createContext(null),W=({children:t,client:e,walletAddress:o,swaps:r,aggregator:n,queryClient:s})=>{let a=useMemo(()=>{if(n)return n;let c=new Aggregator({client:e,walletAddress:o});return c.setSlippage(d),r&&r.length>0&&c.addAggregator(r),c},[n,e,o,r]),i=useMemo(()=>s??new QueryClient,[s]),u=useMemo(()=>({aggregator:a,client:e}),[a,e]);return jsx(v.Provider,{value:u,children:jsx(QueryClientProvider,{client:i,children:jsx(x,{children:t})})})};var g=()=>{let t=useContext(v);if(!t)throw new Error("Could not find ScallopSwapSdkContext. Ensure that you have set up the ScallopSwapSdkProvider");return t};var l={api:{getAggregatorFetchStatus:()=>["api","getAggregatorFetchStatus"],getSwapRoutes:t=>["api","getSwapRoutes",t?.coinInType,t?.coinOutType,t?.swapAmount]},sdk:{aggregatorQuery:t=>[t.method,t.params]}};function V(t,e){let o=(t?.routes??[]).filter(n=>n.formattedResult.name!==e.formattedResult.name),r=o.findIndex(n=>e.formattedResult.coinOut.amount>=n.formattedResult.coinOut.amount);return r===-1?o.push(e):o.splice(r,0,e),{routes:o,errors:t?.errors??[]}}var X=({coinInType:t,coinOutType:e,swapAmount:o},r)=>{let{aggregator:n}=g(),s=useQueryClient(),a=l.api.getSwapRoutes({coinInType:t,coinOutType:e,swapAmount:o});return useQuery({...r,queryKey:a,queryFn:()=>n.fetchRoutes({coinInType:t,coinOutType:e,swapAmount:BigInt(o)},{onRouteFound:i=>{s.setQueryData(a,u=>V(u,i));},onError:i=>{console.error("Error fetching routes:",i);}})})};var Z=({mutationKey:t,...e}={})=>{let o=g();return useMutation({mutationKey:t??["buildSwapTransaction",o.client.network],mutationFn:async({route:r,options:n={}})=>{let{txExtensionParams:s,mergeResult:a,slippage:i}=n;return a===false?o.aggregator.buildRouteTransaction(r,{txExtensionParams:s,mergeResult:false,slippage:i}):o.aggregator.buildRouteTransaction(r,{txExtensionParams:s,slippage:i})},...e})};var oe=t=>{let{aggregator:e}=g(),o=useQueryClient(),r=l.api.getAggregatorFetchStatus();return useEffect(()=>{let n=({name:a})=>{o.setQueryData(r,i=>({...i??e.fetchingStatus,[a]:true}));},s=({name:a})=>{o.setQueryData(r,i=>({...i??e.fetchingStatus,[a]:false}));};return e.events.on("aggregatorFetchStart",n),e.events.on("aggregatorFetchEnd",s),()=>{e.events.off("aggregatorFetchStart",n),e.events.off("aggregatorFetchEnd",s);}},[e,o]),useQuery({...t,queryKey:r,staleTime:1/0,queryFn:()=>e.fetchingStatus})};
|
|
9
9
|
|
|
10
|
-
export {
|
|
10
|
+
export { W as ScallopSwapSdkProvider, x as SdkConfigProvider, l as queryKeys, g as useAggregatorContext, oe as useAggregatorFetchingStatus, Z as useBuildSwapTransaction, X as useGetSwapRoutes };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scallop-io/scallop-swap-sdk-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "A collection of React hooks for interacting with Scallop Swap Meta Aggregator SDK.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sui",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"types": "./dist/index.d.ts",
|
|
32
32
|
"exports": {
|
|
33
33
|
".": {
|
|
34
|
-
"
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
35
|
"import": "./dist/index.mjs",
|
|
36
36
|
"require": "./dist/index.js",
|
|
37
37
|
"default": "./dist/index.js"
|
|
@@ -67,25 +67,20 @@
|
|
|
67
67
|
"doc": "typedoc --out docs src/index.ts"
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@
|
|
71
|
-
"@scallop-io/scallop-swap-sdk": "2.2.0",
|
|
70
|
+
"@scallop-io/scallop-swap-sdk": "3.0.0",
|
|
72
71
|
"assert": "^2.1.0",
|
|
73
|
-
"react": "^18.3.1",
|
|
74
|
-
"react-dom": "^18.3.1",
|
|
75
72
|
"zustand": "^5.0.9"
|
|
76
73
|
},
|
|
77
74
|
"devDependencies": {
|
|
78
75
|
"@commitlint/cli": "^18.0.0",
|
|
79
76
|
"@commitlint/config-conventional": "^18.0.0",
|
|
80
77
|
"@commitlint/prompt-cli": "^18.0.0",
|
|
81
|
-
"@tanstack/query-core": "5.59.16",
|
|
82
|
-
"@tanstack/react-query": "5.59.16",
|
|
83
78
|
"@testing-library/dom": "^10.4.1",
|
|
84
79
|
"@testing-library/jest-dom": "^6.9.1",
|
|
85
80
|
"@testing-library/react": "16.3.2",
|
|
86
81
|
"@types/bn.js": "^5.2.0",
|
|
87
|
-
"@types/react": "
|
|
88
|
-
"@types/react-dom": "
|
|
82
|
+
"@types/react": ">=18",
|
|
83
|
+
"@types/react-dom": ">=18",
|
|
89
84
|
"@types/tmp": "^0.2.5",
|
|
90
85
|
"@typescript-eslint/eslint-plugin": "^8.11.0",
|
|
91
86
|
"@typescript-eslint/parser": "8.10.0",
|
|
@@ -110,9 +105,11 @@
|
|
|
110
105
|
"vitest": "^3.2.4"
|
|
111
106
|
},
|
|
112
107
|
"peerDependencies": {
|
|
113
|
-
"@mysten/sui": "
|
|
114
|
-
"@tanstack/
|
|
115
|
-
"react": "
|
|
108
|
+
"@mysten/sui": ">=2.0.0 < 3.0.0",
|
|
109
|
+
"@tanstack/query-core": ">=5.0.0 < 6.0.0",
|
|
110
|
+
"@tanstack/react-query": ">=5.0.0 < 6.0.0",
|
|
111
|
+
"react": ">=18",
|
|
112
|
+
"react-dom": ">=18"
|
|
116
113
|
},
|
|
117
114
|
"lint-staged": {
|
|
118
115
|
"**/*.ts": [
|
package/src/index.ts
CHANGED
|
@@ -6,13 +6,18 @@ export { queryKeys } from './constants/queryKeys';
|
|
|
6
6
|
export type {
|
|
7
7
|
RouterDataV3,
|
|
8
8
|
CetusFetchRouteSettings,
|
|
9
|
-
|
|
9
|
+
} from '@scallop-io/scallop-swap-sdk/cetus';
|
|
10
|
+
export type {
|
|
11
|
+
FlowXFetchRouteSettings,
|
|
12
|
+
AggregatorQuoter,
|
|
13
|
+
GetRoutesResult,
|
|
14
|
+
} from '@scallop-io/scallop-swap-sdk/flowx';
|
|
15
|
+
export type {
|
|
10
16
|
RouterCompleteTradeRoute,
|
|
11
17
|
AftermathFetchRouteSettings,
|
|
12
18
|
Aftermath,
|
|
19
|
+
} from '@scallop-io/scallop-swap-sdk/aftermath';
|
|
20
|
+
export type {
|
|
13
21
|
_7kFetchRouteSettings,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
AggregatorQuoter,
|
|
17
|
-
GetRoutesResult,
|
|
18
|
-
} from '@scallop-io/scallop-swap-sdk';
|
|
22
|
+
_7kQuoteResponse,
|
|
23
|
+
} from '@scallop-io/scallop-swap-sdk/7k';
|
|
@@ -3,30 +3,12 @@ import {
|
|
|
3
3
|
ScallopSwapSdkProviderContext,
|
|
4
4
|
ScallopSwapSdkProviderProps,
|
|
5
5
|
} from './types';
|
|
6
|
-
import {
|
|
7
|
-
Aggregator,
|
|
8
|
-
AftermathSwap,
|
|
9
|
-
CetusSwap,
|
|
10
|
-
FlowXSwap,
|
|
11
|
-
_7kSwap,
|
|
12
|
-
} from '@scallop-io/scallop-swap-sdk';
|
|
6
|
+
import { Aggregator } from '@scallop-io/scallop-swap-sdk';
|
|
13
7
|
import type { FC, PropsWithChildren } from 'react';
|
|
14
8
|
import { SdkConfigProvider } from '../sdk-config';
|
|
15
9
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
16
|
-
import { SuiClient } from '@mysten/sui/client';
|
|
17
10
|
import { DEFAULT_SLIPPAGE } from 'src/constants/defaults';
|
|
18
11
|
|
|
19
|
-
type AggregatorParams = { client: SuiClient; walletAddress: string };
|
|
20
|
-
|
|
21
|
-
const DEFAULT_SWAPS = [CetusSwap, AftermathSwap, FlowXSwap, _7kSwap] as const;
|
|
22
|
-
|
|
23
|
-
const initSwapAggregator = (params: AggregatorParams) => {
|
|
24
|
-
const aggregator = new Aggregator(params);
|
|
25
|
-
aggregator.setSlippage(DEFAULT_SLIPPAGE);
|
|
26
|
-
aggregator.addAggregator(DEFAULT_SWAPS.map((Swap) => new Swap(params)));
|
|
27
|
-
return aggregator;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
12
|
export const ScallopSwapSdkContext =
|
|
31
13
|
createContext<ScallopSwapSdkProviderContext | null>(null);
|
|
32
14
|
|
|
@@ -36,18 +18,19 @@ export const ScallopSwapSdkProvider: FC<
|
|
|
36
18
|
children,
|
|
37
19
|
client,
|
|
38
20
|
walletAddress,
|
|
21
|
+
swaps,
|
|
39
22
|
aggregator,
|
|
40
23
|
queryClient,
|
|
41
24
|
}: PropsWithChildren<ScallopSwapSdkProviderProps>) => {
|
|
42
25
|
const _aggregator = useMemo(() => {
|
|
43
|
-
return
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}, [aggregator, client, walletAddress]);
|
|
26
|
+
if (aggregator) return aggregator;
|
|
27
|
+
const agg = new Aggregator({ client, walletAddress });
|
|
28
|
+
agg.setSlippage(DEFAULT_SLIPPAGE);
|
|
29
|
+
if (swaps && swaps.length > 0) {
|
|
30
|
+
agg.addAggregator(swaps);
|
|
31
|
+
}
|
|
32
|
+
return agg;
|
|
33
|
+
}, [aggregator, client, walletAddress, swaps]);
|
|
51
34
|
|
|
52
35
|
const _queryClient = useMemo(
|
|
53
36
|
() => queryClient ?? new QueryClient(),
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
// import { SuiClient } from '@mysten/sui/client';
|
|
2
|
-
import { SuiClient } from '@mysten/sui/client';
|
|
3
1
|
import { Aggregator } from '@scallop-io/scallop-swap-sdk';
|
|
4
2
|
import { QueryClient } from '@tanstack/query-core';
|
|
3
|
+
import { ClientWithCoreApi } from '@mysten/sui/client';
|
|
5
4
|
|
|
6
5
|
export type ScallopSwapSdkProviderContext = {
|
|
7
6
|
aggregator: Aggregator;
|
|
8
|
-
client:
|
|
7
|
+
client: ClientWithCoreApi;
|
|
9
8
|
};
|
|
10
9
|
|
|
11
10
|
export type ScallopSwapSdkProviderProps = {
|
|
12
|
-
client:
|
|
11
|
+
client: ClientWithCoreApi;
|
|
13
12
|
walletAddress: string;
|
|
13
|
+
swaps?: Parameters<Aggregator['addAggregator']>[0];
|
|
14
14
|
aggregator?: Aggregator;
|
|
15
15
|
queryClient?: QueryClient;
|
|
16
16
|
};
|