npm.io
4.0.0 • Published 2d ago

@scallop-io/scallop-swap-sdk

Licence
Apache-2.0
Version
4.0.0
Deps
4
Size
229 kB
Vulns
0
Weekly
68

Scallop Swap Meta Aggregator SDK

A unified SDK that aggregates existing swap aggregators on Sui, including Aftermath, Cetus, 7K, and FlowX and provides a generic SwapSdkBase class for seamless integration and extension with future swap aggregators.

Adding a Custom SDK Integration

Extend SwapSdkBase with your own SDK-specific generic types:

import { SwapSdkBase, SwapSdkConstructorParams } from '@scallop-io/scallop-swap-sdk';

class MyDexSwap extends SwapSdkBase<MyPoolType, MyRawRoute, MyFetchSettings, MyClient> {
  constructor(params: SwapSdkConstructorParams<MyFetchSettings>) {
    super('mydex', params);
    this.client = new MyClient(/* ... */);
  }

  // Implement abstract methods: fetchRoute, buildSwapTransaction, setFetchRouteSettings, calcSlippage
}

To get type-safe access via aggregator.getAggregator('mydex'), extend the SdkRegistry interface using declaration merging:

declare module '@scallop-io/scallop-swap-sdk' {
  interface SdkRegistry {
    mydex: MyDexSwap;
  }
}

// Now fully typed:
const mydex = aggregator.getAggregator('mydex'); // MyDexSwap | undefined
mydex?.client; // MyClient | undefined

Keywords