@ubi.fun/sdk 0.1.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/LICENSE +10 -0
- package/README.md +279 -0
- package/dist/abi/AddressFeeSplitManager.d.cts +938 -0
- package/dist/abi/AddressFeeSplitManager.d.ts +939 -0
- package/dist/abi/AddressFeeSplitManager.d.ts.map +1 -0
- package/dist/abi/BidWall.d.cts +739 -0
- package/dist/abi/BidWall.d.ts +740 -0
- package/dist/abi/BidWall.d.ts.map +1 -0
- package/dist/abi/FairLaunch.d.cts +535 -0
- package/dist/abi/FairLaunch.d.ts +536 -0
- package/dist/abi/FairLaunch.d.ts.map +1 -0
- package/dist/abi/FeeEscrow.d.cts +281 -0
- package/dist/abi/FeeEscrow.d.ts +282 -0
- package/dist/abi/FeeEscrow.d.ts.map +1 -0
- package/dist/abi/Flaunch.d.cts +775 -0
- package/dist/abi/Flaunch.d.ts +776 -0
- package/dist/abi/Flaunch.d.ts.map +1 -0
- package/dist/abi/FlaunchPositionManager.d.cts +2170 -0
- package/dist/abi/FlaunchPositionManager.d.ts +2171 -0
- package/dist/abi/FlaunchPositionManager.d.ts.map +1 -0
- package/dist/abi/FlaunchZap.d.cts +300 -0
- package/dist/abi/FlaunchZap.d.ts +301 -0
- package/dist/abi/FlaunchZap.d.ts.map +1 -0
- package/dist/abi/InitialPrice.d.cts +252 -0
- package/dist/abi/InitialPrice.d.ts +253 -0
- package/dist/abi/InitialPrice.d.ts.map +1 -0
- package/dist/abi/Memecoin.d.cts +680 -0
- package/dist/abi/Memecoin.d.ts +681 -0
- package/dist/abi/Memecoin.d.ts.map +1 -0
- package/dist/abi/Multicall.d.cts +332 -0
- package/dist/abi/Multicall.d.ts +333 -0
- package/dist/abi/Multicall.d.ts.map +1 -0
- package/dist/abi/PoolManager.d.cts +1056 -0
- package/dist/abi/PoolManager.d.ts +1057 -0
- package/dist/abi/PoolManager.d.ts.map +1 -0
- package/dist/abi/PoolSwap.d.cts +89 -0
- package/dist/abi/PoolSwap.d.ts +90 -0
- package/dist/abi/PoolSwap.d.ts.map +1 -0
- package/dist/abi/Quoter.d.cts +485 -0
- package/dist/abi/Quoter.d.ts +486 -0
- package/dist/abi/Quoter.d.ts.map +1 -0
- package/dist/abi/ReferralEscrow.d.cts +459 -0
- package/dist/abi/ReferralEscrow.d.ts +460 -0
- package/dist/abi/ReferralEscrow.d.ts.map +1 -0
- package/dist/abi/TreasuryManager.d.cts +325 -0
- package/dist/abi/TreasuryManager.d.ts +326 -0
- package/dist/abi/TreasuryManager.d.ts.map +1 -0
- package/dist/abi/TreasuryManagerFactory.d.cts +433 -0
- package/dist/abi/TreasuryManagerFactory.d.ts +434 -0
- package/dist/abi/TreasuryManagerFactory.d.ts.map +1 -0
- package/dist/abi/UniversalRewardsDistributor.d.cts +191 -0
- package/dist/abi/UniversalRewardsDistributor.d.ts +192 -0
- package/dist/abi/UniversalRewardsDistributor.d.ts.map +1 -0
- package/dist/abi/XHandleClaims.d.cts +383 -0
- package/dist/abi/XHandleClaims.d.ts +384 -0
- package/dist/abi/XHandleClaims.d.ts.map +1 -0
- package/dist/abi/index.cjs +13541 -0
- package/dist/abi/index.cjs.map +1 -0
- package/dist/abi/index.d.cts +18 -0
- package/dist/abi/index.d.ts +19 -0
- package/dist/abi/index.d.ts.map +1 -0
- package/dist/abi/index.js +13522 -0
- package/dist/abi/index.js.map +1 -0
- package/dist/addresses/index.cjs +90 -0
- package/dist/addresses/index.cjs.map +1 -0
- package/dist/addresses/index.js +70 -0
- package/dist/addresses/index.js.map +1 -0
- package/dist/addresses.d.cts +48 -0
- package/dist/addresses.d.ts +49 -0
- package/dist/addresses.d.ts.map +1 -0
- package/dist/clients/BidWallClient.d.cts +44 -0
- package/dist/clients/BidWallClient.d.ts +45 -0
- package/dist/clients/BidWallClient.d.ts.map +1 -0
- package/dist/clients/FairLaunchClient.d.cts +47 -0
- package/dist/clients/FairLaunchClient.d.ts +48 -0
- package/dist/clients/FairLaunchClient.d.ts.map +1 -0
- package/dist/clients/FeeEscrowClient.d.cts +40 -0
- package/dist/clients/FeeEscrowClient.d.ts +41 -0
- package/dist/clients/FeeEscrowClient.d.ts.map +1 -0
- package/dist/clients/FlaunchClient.d.cts +35 -0
- package/dist/clients/FlaunchClient.d.ts +36 -0
- package/dist/clients/FlaunchClient.d.ts.map +1 -0
- package/dist/clients/FlaunchPositionManagerClient.d.cts +117 -0
- package/dist/clients/FlaunchPositionManagerClient.d.ts +118 -0
- package/dist/clients/FlaunchPositionManagerClient.d.ts.map +1 -0
- package/dist/clients/FlaunchZapClient.d.cts +127 -0
- package/dist/clients/FlaunchZapClient.d.ts +128 -0
- package/dist/clients/FlaunchZapClient.d.ts.map +1 -0
- package/dist/clients/InitialPriceClient.d.cts +32 -0
- package/dist/clients/InitialPriceClient.d.ts +33 -0
- package/dist/clients/InitialPriceClient.d.ts.map +1 -0
- package/dist/clients/MemecoinClient.d.cts +66 -0
- package/dist/clients/MemecoinClient.d.ts +67 -0
- package/dist/clients/MemecoinClient.d.ts.map +1 -0
- package/dist/clients/MulticallClient.d.cts +15 -0
- package/dist/clients/MulticallClient.d.ts +16 -0
- package/dist/clients/MulticallClient.d.ts.map +1 -0
- package/dist/clients/PoolManagerClient.d.cts +50 -0
- package/dist/clients/PoolManagerClient.d.ts +51 -0
- package/dist/clients/PoolManagerClient.d.ts.map +1 -0
- package/dist/clients/PoolSwapClient.d.cts +37 -0
- package/dist/clients/PoolSwapClient.d.ts +38 -0
- package/dist/clients/PoolSwapClient.d.ts.map +1 -0
- package/dist/clients/QuoterClient.d.cts +58 -0
- package/dist/clients/QuoterClient.d.ts +59 -0
- package/dist/clients/QuoterClient.d.ts.map +1 -0
- package/dist/clients/ReferralEscrowClient.d.cts +39 -0
- package/dist/clients/ReferralEscrowClient.d.ts +40 -0
- package/dist/clients/ReferralEscrowClient.d.ts.map +1 -0
- package/dist/clients/TreasuryManagerClient.d.cts +71 -0
- package/dist/clients/TreasuryManagerClient.d.ts +72 -0
- package/dist/clients/TreasuryManagerClient.d.ts.map +1 -0
- package/dist/clients/TreasuryManagerFactoryClient.d.cts +15 -0
- package/dist/clients/TreasuryManagerFactoryClient.d.ts +16 -0
- package/dist/clients/TreasuryManagerFactoryClient.d.ts.map +1 -0
- package/dist/clients/UniversalRewardsDistributorClient.d.cts +45 -0
- package/dist/clients/UniversalRewardsDistributorClient.d.ts +46 -0
- package/dist/clients/UniversalRewardsDistributorClient.d.ts.map +1 -0
- package/dist/clients/XHandleClaimsClient.d.cts +64 -0
- package/dist/clients/XHandleClaimsClient.d.ts +65 -0
- package/dist/clients/XHandleClaimsClient.d.ts.map +1 -0
- package/dist/helpers/chainIdToChain.d.cts +113 -0
- package/dist/helpers/chainIdToChain.d.ts +114 -0
- package/dist/helpers/chainIdToChain.d.ts.map +1 -0
- package/dist/helpers/hex.d.cts +3 -0
- package/dist/helpers/hex.d.ts +4 -0
- package/dist/helpers/hex.d.ts.map +1 -0
- package/dist/helpers/index.cjs +196 -0
- package/dist/helpers/index.cjs.map +1 -0
- package/dist/helpers/index.d.cts +3 -0
- package/dist/helpers/index.d.ts +4 -0
- package/dist/helpers/index.d.ts.map +1 -0
- package/dist/helpers/index.js +184 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/helpers/ipfs.d.cts +56 -0
- package/dist/helpers/ipfs.d.ts +57 -0
- package/dist/helpers/ipfs.d.ts.map +1 -0
- package/dist/hooks/FlaunchPositionManagerHooks.d.cts +28 -0
- package/dist/hooks/FlaunchPositionManagerHooks.d.ts +29 -0
- package/dist/hooks/FlaunchPositionManagerHooks.d.ts.map +1 -0
- package/dist/hooks/index.cjs +73 -0
- package/dist/hooks/index.cjs.map +1 -0
- package/dist/hooks/index.d.cts +1 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +70 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/index.cjs +16808 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +31 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16718 -0
- package/dist/index.js.map +1 -0
- package/dist/index.umd.cjs +2 -0
- package/dist/index.umd.cjs.map +1 -0
- package/dist/sdk/FlaunchSDK.d.cts +520 -0
- package/dist/sdk/FlaunchSDK.d.ts +521 -0
- package/dist/sdk/FlaunchSDK.d.ts.map +1 -0
- package/dist/sdk/calldata.d.cts +65 -0
- package/dist/sdk/calldata.d.ts +66 -0
- package/dist/sdk/calldata.d.ts.map +1 -0
- package/dist/sdk/drift.d.cts +20 -0
- package/dist/sdk/drift.d.ts +21 -0
- package/dist/sdk/drift.d.ts.map +1 -0
- package/dist/sdk/factory.d.cts +20 -0
- package/dist/sdk/factory.d.ts +21 -0
- package/dist/sdk/factory.d.ts.map +1 -0
- package/dist/types.d.cts +56 -0
- package/dist/types.d.ts +57 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/index.cjs +455 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +4 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +431 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/parseSwap.d.cts +45 -0
- package/dist/utils/parseSwap.d.ts +46 -0
- package/dist/utils/parseSwap.d.ts.map +1 -0
- package/dist/utils/slippage.d.cts +11 -0
- package/dist/utils/slippage.d.ts +12 -0
- package/dist/utils/slippage.d.ts.map +1 -0
- package/dist/utils/swap.d.cts +49 -0
- package/dist/utils/swap.d.ts +50 -0
- package/dist/utils/swap.d.ts.map +1 -0
- package/dist/utils/univ4.d.cts +78 -0
- package/dist/utils/univ4.d.ts +79 -0
- package/dist/utils/univ4.d.ts.map +1 -0
- package/package.json +161 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Drift, ReadWriteAdapter } from "@delvtech/drift";
|
|
2
|
+
import type { PublicClient, WalletClient } from "viem";
|
|
3
|
+
export type CreateDriftParams = {
|
|
4
|
+
publicClient: PublicClient;
|
|
5
|
+
walletClient?: WalletClient;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Creates a read-only Drift instance with only public client
|
|
9
|
+
* @param params - Parameters with only publicClient
|
|
10
|
+
* @returns Drift instance for read-only operations
|
|
11
|
+
* @throws Error if publicClient.chain is not configured
|
|
12
|
+
*/
|
|
13
|
+
export declare function createDrift(params: Omit<CreateDriftParams, "walletClient">): Drift;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a read-write Drift instance with both public and wallet clients
|
|
16
|
+
* @param params - Parameters with both publicClient and walletClient
|
|
17
|
+
* @returns Drift instance for read and write operations
|
|
18
|
+
* @throws Error if publicClient.chain is not configured
|
|
19
|
+
*/
|
|
20
|
+
export declare function createDrift(params: Required<CreateDriftParams>): Drift<ReadWriteAdapter>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Drift, ReadWriteAdapter } from "@delvtech/drift";
|
|
2
|
+
import type { PublicClient, WalletClient } from "viem";
|
|
3
|
+
export type CreateDriftParams = {
|
|
4
|
+
publicClient: PublicClient;
|
|
5
|
+
walletClient?: WalletClient;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Creates a read-only Drift instance with only public client
|
|
9
|
+
* @param params - Parameters with only publicClient
|
|
10
|
+
* @returns Drift instance for read-only operations
|
|
11
|
+
* @throws Error if publicClient.chain is not configured
|
|
12
|
+
*/
|
|
13
|
+
export declare function createDrift(params: Omit<CreateDriftParams, "walletClient">): Drift;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a read-write Drift instance with both public and wallet clients
|
|
16
|
+
* @param params - Parameters with both publicClient and walletClient
|
|
17
|
+
* @returns Drift instance for read and write operations
|
|
18
|
+
* @throws Error if publicClient.chain is not configured
|
|
19
|
+
*/
|
|
20
|
+
export declare function createDrift(params: Required<CreateDriftParams>): Drift<ReadWriteAdapter>;
|
|
21
|
+
//# sourceMappingURL=drift.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drift.d.ts","sourceRoot":"","sources":["../../src/sdk/drift.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,EACL,gBAAgB,EACjB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEvD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,YAAY,EAAE,YAAY,CAAC;IAC3B,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,IAAI,CAAC,iBAAiB,EAAE,cAAc,CAAC,GAC9C,KAAK,CAAC;AACT;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,QAAQ,CAAC,iBAAiB,CAAC,GAClC,KAAK,CAAC,gBAAgB,CAAC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { PublicClient, WalletClient } from "viem";
|
|
2
|
+
import { ReadFlaunchSDK, ReadWriteFlaunchSDK } from "./FlaunchSDK.cjs";
|
|
3
|
+
export type CreateFlaunchParams = {
|
|
4
|
+
publicClient: PublicClient;
|
|
5
|
+
walletClient?: WalletClient;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Creates a read-only Flaunch SDK instance with only public client
|
|
9
|
+
* @param params - Parameters with only publicClient
|
|
10
|
+
* @returns ReadFlaunchSDK for read-only operations
|
|
11
|
+
* @throws Error if publicClient.chain is not configured
|
|
12
|
+
*/
|
|
13
|
+
export declare function createFlaunch(params: Omit<CreateFlaunchParams, "walletClient">): ReadFlaunchSDK;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a read-write Flaunch SDK instance with both public and wallet clients
|
|
16
|
+
* @param params - Parameters with both publicClient and walletClient
|
|
17
|
+
* @returns ReadWriteFlaunchSDK for read and write operations
|
|
18
|
+
* @throws Error if publicClient.chain is not configured
|
|
19
|
+
*/
|
|
20
|
+
export declare function createFlaunch(params: Required<CreateFlaunchParams>): ReadWriteFlaunchSDK;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { PublicClient, WalletClient } from "viem";
|
|
2
|
+
import { ReadFlaunchSDK, ReadWriteFlaunchSDK } from "./FlaunchSDK.js";
|
|
3
|
+
export type CreateFlaunchParams = {
|
|
4
|
+
publicClient: PublicClient;
|
|
5
|
+
walletClient?: WalletClient;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Creates a read-only Flaunch SDK instance with only public client
|
|
9
|
+
* @param params - Parameters with only publicClient
|
|
10
|
+
* @returns ReadFlaunchSDK for read-only operations
|
|
11
|
+
* @throws Error if publicClient.chain is not configured
|
|
12
|
+
*/
|
|
13
|
+
export declare function createFlaunch(params: Omit<CreateFlaunchParams, "walletClient">): ReadFlaunchSDK;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a read-write Flaunch SDK instance with both public and wallet clients
|
|
16
|
+
* @param params - Parameters with both publicClient and walletClient
|
|
17
|
+
* @returns ReadWriteFlaunchSDK for read and write operations
|
|
18
|
+
* @throws Error if publicClient.chain is not configured
|
|
19
|
+
*/
|
|
20
|
+
export declare function createFlaunch(params: Required<CreateFlaunchParams>): ReadWriteFlaunchSDK;
|
|
21
|
+
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/sdk/factory.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEnE,MAAM,MAAM,mBAAmB,GAAG;IAChC,YAAY,EAAE,YAAY,CAAC;IAC3B,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,IAAI,CAAC,mBAAmB,EAAE,cAAc,CAAC,GAChD,cAAc,CAAC;AAClB;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,QAAQ,CAAC,mBAAmB,CAAC,GACpC,mBAAmB,CAAC"}
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Address, Hex } from "viem";
|
|
2
|
+
export interface Addresses {
|
|
3
|
+
[chainId: number]: Address;
|
|
4
|
+
}
|
|
5
|
+
export interface PoolKey {
|
|
6
|
+
currency0: Address;
|
|
7
|
+
currency1: Address;
|
|
8
|
+
fee: number;
|
|
9
|
+
tickSpacing: number;
|
|
10
|
+
hooks: Address;
|
|
11
|
+
}
|
|
12
|
+
export interface CoinMetadata {
|
|
13
|
+
name: string;
|
|
14
|
+
description: string;
|
|
15
|
+
image: string;
|
|
16
|
+
external_link: string;
|
|
17
|
+
collaborators: string[];
|
|
18
|
+
discordUrl: string;
|
|
19
|
+
twitterUrl: string;
|
|
20
|
+
telegramUrl: string;
|
|
21
|
+
}
|
|
22
|
+
export interface IPFSParams {
|
|
23
|
+
metadata: {
|
|
24
|
+
base64Image: string;
|
|
25
|
+
description: string;
|
|
26
|
+
websiteUrl?: string;
|
|
27
|
+
discordUrl?: string;
|
|
28
|
+
twitterUrl?: string;
|
|
29
|
+
telegramUrl?: string;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Parsed data from a PoolCreated event (the ubi.fun v5 PositionManager shape:
|
|
34
|
+
* FlaunchParams carries fairLaunchDuration).
|
|
35
|
+
*/
|
|
36
|
+
export type PoolCreatedEventData = {
|
|
37
|
+
poolId: Hex;
|
|
38
|
+
memecoin: Address;
|
|
39
|
+
memecoinTreasury: Address;
|
|
40
|
+
tokenId: bigint;
|
|
41
|
+
currencyFlipped: boolean;
|
|
42
|
+
flaunchFee: bigint;
|
|
43
|
+
params: {
|
|
44
|
+
name: string;
|
|
45
|
+
symbol: string;
|
|
46
|
+
tokenUri: string;
|
|
47
|
+
initialTokenFairLaunch: bigint;
|
|
48
|
+
fairLaunchDuration: bigint;
|
|
49
|
+
premineAmount: bigint;
|
|
50
|
+
creator: Address;
|
|
51
|
+
creatorFeeAllocation: number;
|
|
52
|
+
flaunchAt: bigint;
|
|
53
|
+
initialPriceParams: Hex;
|
|
54
|
+
feeCalculatorParams: Hex;
|
|
55
|
+
};
|
|
56
|
+
};
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Address, Hex } from "viem";
|
|
2
|
+
export interface Addresses {
|
|
3
|
+
[chainId: number]: Address;
|
|
4
|
+
}
|
|
5
|
+
export interface PoolKey {
|
|
6
|
+
currency0: Address;
|
|
7
|
+
currency1: Address;
|
|
8
|
+
fee: number;
|
|
9
|
+
tickSpacing: number;
|
|
10
|
+
hooks: Address;
|
|
11
|
+
}
|
|
12
|
+
export interface CoinMetadata {
|
|
13
|
+
name: string;
|
|
14
|
+
description: string;
|
|
15
|
+
image: string;
|
|
16
|
+
external_link: string;
|
|
17
|
+
collaborators: string[];
|
|
18
|
+
discordUrl: string;
|
|
19
|
+
twitterUrl: string;
|
|
20
|
+
telegramUrl: string;
|
|
21
|
+
}
|
|
22
|
+
export interface IPFSParams {
|
|
23
|
+
metadata: {
|
|
24
|
+
base64Image: string;
|
|
25
|
+
description: string;
|
|
26
|
+
websiteUrl?: string;
|
|
27
|
+
discordUrl?: string;
|
|
28
|
+
twitterUrl?: string;
|
|
29
|
+
telegramUrl?: string;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Parsed data from a PoolCreated event (the ubi.fun v5 PositionManager shape:
|
|
34
|
+
* FlaunchParams carries fairLaunchDuration).
|
|
35
|
+
*/
|
|
36
|
+
export type PoolCreatedEventData = {
|
|
37
|
+
poolId: Hex;
|
|
38
|
+
memecoin: Address;
|
|
39
|
+
memecoinTreasury: Address;
|
|
40
|
+
tokenId: bigint;
|
|
41
|
+
currencyFlipped: boolean;
|
|
42
|
+
flaunchFee: bigint;
|
|
43
|
+
params: {
|
|
44
|
+
name: string;
|
|
45
|
+
symbol: string;
|
|
46
|
+
tokenUri: string;
|
|
47
|
+
initialTokenFairLaunch: bigint;
|
|
48
|
+
fairLaunchDuration: bigint;
|
|
49
|
+
premineAmount: bigint;
|
|
50
|
+
creator: Address;
|
|
51
|
+
creatorFeeAllocation: number;
|
|
52
|
+
flaunchAt: bigint;
|
|
53
|
+
initialPriceParams: Hex;
|
|
54
|
+
feeCalculatorParams: Hex;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAEpC,MAAM,WAAW,SAAS;IACxB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,OAAO;IACtB,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE;QACR,WAAW,EAAE,MAAM,CAAC;QACpB,WAAW,EAAE,MAAM,CAAC;QACpB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;CACH;AAED;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,EAAE,GAAG,CAAC;IACZ,QAAQ,EAAE,OAAO,CAAC;IAClB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,OAAO,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;QACjB,sBAAsB,EAAE,MAAM,CAAC;QAC/B,kBAAkB,EAAE,MAAM,CAAC;QAC3B,aAAa,EAAE,MAAM,CAAC;QACtB,OAAO,EAAE,OAAO,CAAC;QACjB,oBAAoB,EAAE,MAAM,CAAC;QAC7B,SAAS,EAAE,MAAM,CAAC;QAClB,kBAAkB,EAAE,GAAG,CAAC;QACxB,mBAAmB,EAAE,GAAG,CAAC;KAC1B,CAAC;CACH,CAAC"}
|
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var viem = require('viem');
|
|
4
|
+
|
|
5
|
+
const TickFinder = {
|
|
6
|
+
MIN_TICK: -887220,
|
|
7
|
+
MAX_TICK: 887220
|
|
8
|
+
};
|
|
9
|
+
const Q96 = 2n ** 96n;
|
|
10
|
+
const Q192 = 2n ** 192n;
|
|
11
|
+
const TICK_SPACING = 60;
|
|
12
|
+
const getPoolId = (poolKey) => {
|
|
13
|
+
const packed = viem.concat([
|
|
14
|
+
viem.pad(poolKey.currency0, { size: 32 }),
|
|
15
|
+
// address padded to 32 bytes
|
|
16
|
+
viem.pad(poolKey.currency1, { size: 32 }),
|
|
17
|
+
// address padded to 32 bytes
|
|
18
|
+
viem.pad(viem.toHex(poolKey.fee), { size: 32 }),
|
|
19
|
+
// uint24 padded to 32 bytes
|
|
20
|
+
viem.pad(viem.toHex(poolKey.tickSpacing), { size: 32 }),
|
|
21
|
+
// int24 padded to 32 bytes
|
|
22
|
+
viem.pad(poolKey.hooks, { size: 32 })
|
|
23
|
+
// address padded to 32 bytes
|
|
24
|
+
]);
|
|
25
|
+
return viem.keccak256(packed);
|
|
26
|
+
};
|
|
27
|
+
const orderPoolKey = (poolKey) => {
|
|
28
|
+
const [currency0, currency1] = poolKey.currency0.toLowerCase() < poolKey.currency1.toLowerCase() ? [poolKey.currency0, poolKey.currency1] : [poolKey.currency1, poolKey.currency0];
|
|
29
|
+
return {
|
|
30
|
+
...poolKey,
|
|
31
|
+
currency0,
|
|
32
|
+
currency1
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
const getValidTick = ({
|
|
36
|
+
tick,
|
|
37
|
+
tickSpacing,
|
|
38
|
+
roundDown = true
|
|
39
|
+
}) => {
|
|
40
|
+
if (tick % tickSpacing === 0) {
|
|
41
|
+
return tick;
|
|
42
|
+
}
|
|
43
|
+
let validTick = Math.trunc(tick / tickSpacing) * tickSpacing;
|
|
44
|
+
if (tick < 0 && tick % tickSpacing !== 0) {
|
|
45
|
+
validTick -= tickSpacing;
|
|
46
|
+
}
|
|
47
|
+
if (!roundDown) {
|
|
48
|
+
validTick += tickSpacing;
|
|
49
|
+
}
|
|
50
|
+
return validTick;
|
|
51
|
+
};
|
|
52
|
+
const getNearestUsableTick = ({
|
|
53
|
+
tick,
|
|
54
|
+
tickSpacing
|
|
55
|
+
}) => {
|
|
56
|
+
const rounded = Math.round(tick / tickSpacing) * tickSpacing;
|
|
57
|
+
return Math.max(TickFinder.MIN_TICK, Math.min(TickFinder.MAX_TICK, rounded));
|
|
58
|
+
};
|
|
59
|
+
const getAmount0ForLiquidity = (sqrtRatioAX96, sqrtRatioBX96, liquidity) => {
|
|
60
|
+
let [sqrtRatioA, sqrtRatioB] = [sqrtRatioAX96, sqrtRatioBX96];
|
|
61
|
+
if (sqrtRatioA > sqrtRatioB) {
|
|
62
|
+
[sqrtRatioA, sqrtRatioB] = [sqrtRatioB, sqrtRatioA];
|
|
63
|
+
}
|
|
64
|
+
const leftShiftedLiquidity = liquidity << 96n;
|
|
65
|
+
const sqrtDiff = sqrtRatioB - sqrtRatioA;
|
|
66
|
+
const multipliedRes = leftShiftedLiquidity * sqrtDiff;
|
|
67
|
+
const numerator = multipliedRes / sqrtRatioB;
|
|
68
|
+
const amount0 = numerator / sqrtRatioA;
|
|
69
|
+
return amount0;
|
|
70
|
+
};
|
|
71
|
+
const getAmount1ForLiquidity = (sqrtRatioAX96, sqrtRatioBX96, liquidity) => {
|
|
72
|
+
let [sqrtRatioA, sqrtRatioB] = [sqrtRatioAX96, sqrtRatioBX96];
|
|
73
|
+
if (sqrtRatioA > sqrtRatioB) {
|
|
74
|
+
[sqrtRatioA, sqrtRatioB] = [sqrtRatioB, sqrtRatioA];
|
|
75
|
+
}
|
|
76
|
+
const sqrtDiff = sqrtRatioB - sqrtRatioA;
|
|
77
|
+
const multipliedRes = liquidity * sqrtDiff;
|
|
78
|
+
const amount1 = multipliedRes / 2n ** 96n;
|
|
79
|
+
return amount1;
|
|
80
|
+
};
|
|
81
|
+
const getSqrtPriceX96FromTick = (tick) => {
|
|
82
|
+
const absTick = tick < 0 ? BigInt(-tick) : BigInt(tick);
|
|
83
|
+
if (absTick > TickFinder.MAX_TICK) {
|
|
84
|
+
throw new Error("Tick out of range");
|
|
85
|
+
}
|
|
86
|
+
let ratio = (absTick & 1n) !== 0n ? 0xfffcb933bd6fad37aa2d162d1a594001n : 0x100000000000000000000000000000000n;
|
|
87
|
+
if ((absTick & 2n) !== 0n)
|
|
88
|
+
ratio = ratio * 0xfff97272373d413259a46990580e213an >> 128n;
|
|
89
|
+
if ((absTick & 4n) !== 0n)
|
|
90
|
+
ratio = ratio * 0xfff2e50f5f656932ef12357cf3c7fdccn >> 128n;
|
|
91
|
+
if ((absTick & 8n) !== 0n)
|
|
92
|
+
ratio = ratio * 0xffe5caca7e10e4e61c3624eaa0941cd0n >> 128n;
|
|
93
|
+
if ((absTick & 16n) !== 0n)
|
|
94
|
+
ratio = ratio * 0xffcb9843d60f6159c9db58835c926644n >> 128n;
|
|
95
|
+
if ((absTick & 32n) !== 0n)
|
|
96
|
+
ratio = ratio * 0xff973b41fa98c081472e6896dfb254c0n >> 128n;
|
|
97
|
+
if ((absTick & 64n) !== 0n)
|
|
98
|
+
ratio = ratio * 0xff2ea16466c96a3843ec78b326b52861n >> 128n;
|
|
99
|
+
if ((absTick & 128n) !== 0n)
|
|
100
|
+
ratio = ratio * 0xfe5dee046a99a2a811c461f1969c3053n >> 128n;
|
|
101
|
+
if ((absTick & 256n) !== 0n)
|
|
102
|
+
ratio = ratio * 0xfcbe86c7900a88aedcffc83b479aa3a4n >> 128n;
|
|
103
|
+
if ((absTick & 512n) !== 0n)
|
|
104
|
+
ratio = ratio * 0xf987a7253ac413176f2b074cf7815e54n >> 128n;
|
|
105
|
+
if ((absTick & 1024n) !== 0n)
|
|
106
|
+
ratio = ratio * 0xf3392b0822b70005940c7a398e4b70f3n >> 128n;
|
|
107
|
+
if ((absTick & 2048n) !== 0n)
|
|
108
|
+
ratio = ratio * 0xe7159475a2c29b7443b29c7fa6e889d9n >> 128n;
|
|
109
|
+
if ((absTick & 4096n) !== 0n)
|
|
110
|
+
ratio = ratio * 0xd097f3bdfd2022b8845ad8f792aa5825n >> 128n;
|
|
111
|
+
if ((absTick & 8192n) !== 0n)
|
|
112
|
+
ratio = ratio * 0xa9f746462d870fdf8a65dc1f90e061e5n >> 128n;
|
|
113
|
+
if ((absTick & 16384n) !== 0n)
|
|
114
|
+
ratio = ratio * 0x70d869a156d2a1b890bb3df62baf32f7n >> 128n;
|
|
115
|
+
if ((absTick & 32768n) !== 0n)
|
|
116
|
+
ratio = ratio * 0x31be135f97d08fd981231505542fcfa6n >> 128n;
|
|
117
|
+
if ((absTick & 65536n) !== 0n)
|
|
118
|
+
ratio = ratio * 0x9aa508b5b7a84e1c677de54f3e99bc9n >> 128n;
|
|
119
|
+
if ((absTick & 131072n) !== 0n)
|
|
120
|
+
ratio = ratio * 0x5d6af8dedb81196699c329225ee604n >> 128n;
|
|
121
|
+
if ((absTick & 262144n) !== 0n)
|
|
122
|
+
ratio = ratio * 0x2216e584f5fa1ea926041bedfe98n >> 128n;
|
|
123
|
+
if ((absTick & 524288n) !== 0n)
|
|
124
|
+
ratio = ratio * 0x48a170391f7dc42444e8fa2n >> 128n;
|
|
125
|
+
if (tick > 0) {
|
|
126
|
+
ratio = (2n ** 256n - 1n) / ratio;
|
|
127
|
+
}
|
|
128
|
+
const resultShifted = ratio >> 32n;
|
|
129
|
+
if (ratio % (1n << 32n) === 0n) {
|
|
130
|
+
return resultShifted;
|
|
131
|
+
}
|
|
132
|
+
return resultShifted + 1n;
|
|
133
|
+
};
|
|
134
|
+
const calculateUnderlyingTokenBalances = (liquidity, tickLower, tickUpper, tickCurrent) => {
|
|
135
|
+
const sqrtPriceCurrentX96 = getSqrtPriceX96FromTick(tickCurrent);
|
|
136
|
+
const sqrtPriceLowerX96 = getSqrtPriceX96FromTick(tickLower);
|
|
137
|
+
const sqrtPriceUpperX96 = getSqrtPriceX96FromTick(tickUpper);
|
|
138
|
+
let amount0 = 0n;
|
|
139
|
+
let amount1 = 0n;
|
|
140
|
+
if (sqrtPriceCurrentX96 <= sqrtPriceLowerX96) {
|
|
141
|
+
amount0 = getAmount0ForLiquidity(
|
|
142
|
+
sqrtPriceLowerX96,
|
|
143
|
+
sqrtPriceUpperX96,
|
|
144
|
+
liquidity
|
|
145
|
+
);
|
|
146
|
+
} else if (sqrtPriceCurrentX96 < sqrtPriceUpperX96) {
|
|
147
|
+
amount0 = getAmount0ForLiquidity(
|
|
148
|
+
sqrtPriceCurrentX96,
|
|
149
|
+
sqrtPriceUpperX96,
|
|
150
|
+
liquidity
|
|
151
|
+
);
|
|
152
|
+
amount1 = getAmount1ForLiquidity(
|
|
153
|
+
sqrtPriceLowerX96,
|
|
154
|
+
sqrtPriceCurrentX96,
|
|
155
|
+
liquidity
|
|
156
|
+
);
|
|
157
|
+
} else {
|
|
158
|
+
amount1 = getAmount1ForLiquidity(
|
|
159
|
+
sqrtPriceLowerX96,
|
|
160
|
+
sqrtPriceUpperX96,
|
|
161
|
+
liquidity
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
return { amount0, amount1 };
|
|
165
|
+
};
|
|
166
|
+
const priceRatioToTick = ({
|
|
167
|
+
priceInput,
|
|
168
|
+
isDirection1Per0,
|
|
169
|
+
decimals0,
|
|
170
|
+
decimals1,
|
|
171
|
+
spacing,
|
|
172
|
+
shouldGetNearestUsableTick = true
|
|
173
|
+
}) => {
|
|
174
|
+
if (!priceInput || isNaN(Number(priceInput))) return 0;
|
|
175
|
+
const inputPrice = Number(priceInput);
|
|
176
|
+
try {
|
|
177
|
+
let priceRatio;
|
|
178
|
+
if (isDirection1Per0) {
|
|
179
|
+
priceRatio = inputPrice / Math.pow(10, decimals0 - decimals1);
|
|
180
|
+
} else {
|
|
181
|
+
priceRatio = 1 / inputPrice / Math.pow(10, decimals0 - decimals1);
|
|
182
|
+
}
|
|
183
|
+
const tick = Math.log(priceRatio) / Math.log(1.0001);
|
|
184
|
+
if (shouldGetNearestUsableTick) {
|
|
185
|
+
return getValidTick({
|
|
186
|
+
tick: Math.round(tick),
|
|
187
|
+
tickSpacing: spacing
|
|
188
|
+
});
|
|
189
|
+
} else {
|
|
190
|
+
return Math.round(tick);
|
|
191
|
+
}
|
|
192
|
+
} catch (error) {
|
|
193
|
+
console.error("Error converting price to tick:", error);
|
|
194
|
+
const rawTick = Math.floor(Math.log(inputPrice) / Math.log(1.0001));
|
|
195
|
+
if (shouldGetNearestUsableTick) {
|
|
196
|
+
return getValidTick({
|
|
197
|
+
tick: rawTick,
|
|
198
|
+
tickSpacing: spacing
|
|
199
|
+
});
|
|
200
|
+
} else {
|
|
201
|
+
return rawTick;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
const getLiquidityFromAmounts = (params) => {
|
|
206
|
+
const sqrtRatioCurrentX96 = getSqrtPriceX96FromTick(params.currentTick);
|
|
207
|
+
let sqrtRatioAX96 = getSqrtPriceX96FromTick(params.tickLower);
|
|
208
|
+
let sqrtRatioBX96 = getSqrtPriceX96FromTick(params.tickUpper);
|
|
209
|
+
if (sqrtRatioAX96 > sqrtRatioBX96) {
|
|
210
|
+
[sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96];
|
|
211
|
+
}
|
|
212
|
+
if (sqrtRatioCurrentX96 <= sqrtRatioAX96) {
|
|
213
|
+
return maxLiquidityForAmount0Precise(
|
|
214
|
+
sqrtRatioAX96,
|
|
215
|
+
sqrtRatioBX96,
|
|
216
|
+
params.amount0
|
|
217
|
+
);
|
|
218
|
+
} else if (sqrtRatioCurrentX96 < sqrtRatioBX96) {
|
|
219
|
+
const liquidity0 = maxLiquidityForAmount0Precise(
|
|
220
|
+
sqrtRatioCurrentX96,
|
|
221
|
+
sqrtRatioBX96,
|
|
222
|
+
params.amount0
|
|
223
|
+
);
|
|
224
|
+
const liquidity1 = maxLiquidityForAmount1(
|
|
225
|
+
sqrtRatioAX96,
|
|
226
|
+
sqrtRatioCurrentX96,
|
|
227
|
+
params.amount1
|
|
228
|
+
);
|
|
229
|
+
return liquidity0 < liquidity1 ? liquidity0 : liquidity1;
|
|
230
|
+
} else {
|
|
231
|
+
return maxLiquidityForAmount1(sqrtRatioAX96, sqrtRatioBX96, params.amount1);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
function maxLiquidityForAmount0Precise(sqrtRatioAX96, sqrtRatioBX96, amount0) {
|
|
235
|
+
if (sqrtRatioAX96 > sqrtRatioBX96) {
|
|
236
|
+
[sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96];
|
|
237
|
+
}
|
|
238
|
+
if (sqrtRatioAX96 === sqrtRatioBX96) {
|
|
239
|
+
return 0n;
|
|
240
|
+
}
|
|
241
|
+
const Q962 = 2n ** 96n;
|
|
242
|
+
const numerator = amount0 * sqrtRatioAX96 * sqrtRatioBX96;
|
|
243
|
+
const denominator = Q962 * (sqrtRatioBX96 - sqrtRatioAX96);
|
|
244
|
+
return numerator / denominator;
|
|
245
|
+
}
|
|
246
|
+
function maxLiquidityForAmount1(sqrtRatioAX96, sqrtRatioBX96, amount1) {
|
|
247
|
+
if (sqrtRatioAX96 > sqrtRatioBX96) {
|
|
248
|
+
[sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96];
|
|
249
|
+
}
|
|
250
|
+
if (sqrtRatioAX96 === sqrtRatioBX96) {
|
|
251
|
+
return 0n;
|
|
252
|
+
}
|
|
253
|
+
const Q962 = 2n ** 96n;
|
|
254
|
+
return amount1 * Q962 / (sqrtRatioBX96 - sqrtRatioAX96);
|
|
255
|
+
}
|
|
256
|
+
const getAmountsForLiquidity = (params) => {
|
|
257
|
+
if (params.liquidity === 0n) {
|
|
258
|
+
return { amount0: 0n, amount1: 0n };
|
|
259
|
+
}
|
|
260
|
+
const sqrtRatioCurrentX96 = getSqrtPriceX96FromTick(params.currentTick);
|
|
261
|
+
let sqrtRatioAX96 = getSqrtPriceX96FromTick(params.tickLower);
|
|
262
|
+
let sqrtRatioBX96 = getSqrtPriceX96FromTick(params.tickUpper);
|
|
263
|
+
if (sqrtRatioAX96 > sqrtRatioBX96) {
|
|
264
|
+
[sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96];
|
|
265
|
+
}
|
|
266
|
+
let amount0 = 0n;
|
|
267
|
+
let amount1 = 0n;
|
|
268
|
+
if (sqrtRatioCurrentX96 <= sqrtRatioAX96) {
|
|
269
|
+
amount0 = getAmount0ForLiquidity(
|
|
270
|
+
sqrtRatioAX96,
|
|
271
|
+
sqrtRatioBX96,
|
|
272
|
+
params.liquidity
|
|
273
|
+
);
|
|
274
|
+
} else if (sqrtRatioCurrentX96 < sqrtRatioBX96) {
|
|
275
|
+
amount0 = getAmount0ForLiquidity(
|
|
276
|
+
sqrtRatioCurrentX96,
|
|
277
|
+
sqrtRatioBX96,
|
|
278
|
+
params.liquidity
|
|
279
|
+
);
|
|
280
|
+
amount1 = getAmount1ForLiquidity(
|
|
281
|
+
sqrtRatioAX96,
|
|
282
|
+
sqrtRatioCurrentX96,
|
|
283
|
+
params.liquidity
|
|
284
|
+
);
|
|
285
|
+
} else {
|
|
286
|
+
amount1 = getAmount1ForLiquidity(
|
|
287
|
+
sqrtRatioAX96,
|
|
288
|
+
sqrtRatioBX96,
|
|
289
|
+
params.liquidity
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
return { amount0, amount1 };
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
function parseSwapData(args, usdcIsCurrencyZero) {
|
|
296
|
+
const {
|
|
297
|
+
flAmount0,
|
|
298
|
+
flAmount1,
|
|
299
|
+
flFee0,
|
|
300
|
+
flFee1,
|
|
301
|
+
ispAmount0,
|
|
302
|
+
ispAmount1,
|
|
303
|
+
ispFee0,
|
|
304
|
+
ispFee1,
|
|
305
|
+
uniAmount0,
|
|
306
|
+
uniAmount1,
|
|
307
|
+
uniFee0,
|
|
308
|
+
uniFee1
|
|
309
|
+
} = args;
|
|
310
|
+
const currency0Delta = flAmount0 + ispAmount0 + uniAmount0;
|
|
311
|
+
const currency1Delta = flAmount1 + ispAmount1 + uniAmount1;
|
|
312
|
+
const currency0Fees = flFee0 + ispFee0 + uniFee0;
|
|
313
|
+
const currency1Fees = flFee1 + ispFee1 + uniFee1;
|
|
314
|
+
let feesIsInUSDC;
|
|
315
|
+
let swapType;
|
|
316
|
+
if (usdcIsCurrencyZero) {
|
|
317
|
+
swapType = currency0Delta < 0 ? "BUY" : "SELL";
|
|
318
|
+
feesIsInUSDC = currency0Fees < 0;
|
|
319
|
+
} else {
|
|
320
|
+
swapType = currency1Delta < 0 ? "BUY" : "SELL";
|
|
321
|
+
feesIsInUSDC = currency1Fees < 0;
|
|
322
|
+
}
|
|
323
|
+
const absCurrency0Delta = currency0Delta < 0 ? -currency0Delta : currency0Delta;
|
|
324
|
+
const absCurrency1Delta = currency1Delta < 0 ? -currency1Delta : currency1Delta;
|
|
325
|
+
const absCurrency0Fees = currency0Fees < 0 ? -currency0Fees : currency0Fees;
|
|
326
|
+
const absCurrency1Fees = currency1Fees < 0 ? -currency1Fees : currency1Fees;
|
|
327
|
+
const fees = {
|
|
328
|
+
isInUSDC: feesIsInUSDC,
|
|
329
|
+
amount: usdcIsCurrencyZero ? feesIsInUSDC ? absCurrency0Fees : absCurrency1Fees : feesIsInUSDC ? absCurrency1Fees : absCurrency0Fees
|
|
330
|
+
};
|
|
331
|
+
if (swapType === "BUY") {
|
|
332
|
+
return {
|
|
333
|
+
type: swapType,
|
|
334
|
+
delta: {
|
|
335
|
+
coinsBought: usdcIsCurrencyZero ? absCurrency1Delta - (!fees.isInUSDC ? fees.amount : 0n) : absCurrency0Delta - (!fees.isInUSDC ? fees.amount : 0n),
|
|
336
|
+
usdcSold: usdcIsCurrencyZero ? absCurrency0Delta - (fees.isInUSDC ? fees.amount : 0n) : absCurrency1Delta - (fees.isInUSDC ? fees.amount : 0n),
|
|
337
|
+
fees
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
} else {
|
|
341
|
+
return {
|
|
342
|
+
type: swapType,
|
|
343
|
+
delta: {
|
|
344
|
+
coinsSold: usdcIsCurrencyZero ? absCurrency1Delta - (!fees.isInUSDC ? fees.amount : 0n) : absCurrency0Delta - (!fees.isInUSDC ? fees.amount : 0n),
|
|
345
|
+
usdcBought: usdcIsCurrencyZero ? absCurrency0Delta - (fees.isInUSDC ? fees.amount : 0n) : absCurrency1Delta - (fees.isInUSDC ? fees.amount : 0n),
|
|
346
|
+
fees
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
const getAmountWithSlippage = ({
|
|
353
|
+
amount,
|
|
354
|
+
slippage,
|
|
355
|
+
swapType
|
|
356
|
+
}) => {
|
|
357
|
+
if (amount == null) {
|
|
358
|
+
return 0n;
|
|
359
|
+
}
|
|
360
|
+
const absAmount = amount < 0n ? -amount : amount;
|
|
361
|
+
const slippageMultiplier = swapType === "EXACT_IN" ? BigInt(1e18) - viem.parseEther(slippage) : BigInt(1e18) + viem.parseEther(slippage);
|
|
362
|
+
return absAmount * slippageMultiplier / BigInt(1e18);
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
const USDC_ADDRESS = "0x3600000000000000000000000000000000000000";
|
|
366
|
+
|
|
367
|
+
function referrerHookData(referrer) {
|
|
368
|
+
return referrer && viem.isAddress(referrer) && referrer !== viem.zeroAddress ? viem.encodeAbiParameters([{ type: "address" }], [referrer]) : "0x";
|
|
369
|
+
}
|
|
370
|
+
function coinPoolKey(coinAddress, positionManagerAddress) {
|
|
371
|
+
return orderPoolKey({
|
|
372
|
+
currency0: USDC_ADDRESS,
|
|
373
|
+
currency1: coinAddress,
|
|
374
|
+
fee: 0,
|
|
375
|
+
tickSpacing: 60,
|
|
376
|
+
hooks: positionManagerAddress
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
function usdcIsCurrencyZero(coinAddress) {
|
|
380
|
+
return coinAddress.toLowerCase() > USDC_ADDRESS.toLowerCase();
|
|
381
|
+
}
|
|
382
|
+
function swapDirection(side, coinAddress) {
|
|
383
|
+
return side === "buy" ? usdcIsCurrencyZero(coinAddress) : !usdcIsCurrencyZero(coinAddress);
|
|
384
|
+
}
|
|
385
|
+
const MIN_SQRT_PRICE = 4295128739n + 1n;
|
|
386
|
+
const MAX_SQRT_PRICE = 1461446703485210103287273052203988822378723970342n - 1n;
|
|
387
|
+
function bigintSqrt(value) {
|
|
388
|
+
if (value < 2n) {
|
|
389
|
+
return value;
|
|
390
|
+
}
|
|
391
|
+
let current = value;
|
|
392
|
+
let next = (current + value / current) / 2n;
|
|
393
|
+
while (next < current) {
|
|
394
|
+
current = next;
|
|
395
|
+
next = (current + value / current) / 2n;
|
|
396
|
+
}
|
|
397
|
+
return current;
|
|
398
|
+
}
|
|
399
|
+
function expectedEndSqrtPriceX96({
|
|
400
|
+
current,
|
|
401
|
+
zeroForOne,
|
|
402
|
+
amountIn,
|
|
403
|
+
amountOut
|
|
404
|
+
}) {
|
|
405
|
+
if (current === 0n || amountIn <= 0n || amountOut <= 0n) {
|
|
406
|
+
return current;
|
|
407
|
+
}
|
|
408
|
+
const end = zeroForOne ? amountOut * Q192 / (amountIn * current) : amountIn * Q192 / (amountOut * current);
|
|
409
|
+
if (zeroForOne) {
|
|
410
|
+
return end < current ? end : current;
|
|
411
|
+
}
|
|
412
|
+
return end > current ? end : current;
|
|
413
|
+
}
|
|
414
|
+
function sqrtPriceLimit({
|
|
415
|
+
current,
|
|
416
|
+
zeroForOne,
|
|
417
|
+
slippageBps
|
|
418
|
+
}) {
|
|
419
|
+
if (!Number.isInteger(slippageBps) || slippageBps < 0 || slippageBps >= 1e4) {
|
|
420
|
+
throw new Error(
|
|
421
|
+
`slippageBps must be an integer in [0, 10000), got ${slippageBps}`
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
const factor = BigInt(
|
|
425
|
+
zeroForOne ? 1e4 - slippageBps : 1e4 + slippageBps
|
|
426
|
+
);
|
|
427
|
+
const multiplier = bigintSqrt(factor * 10n ** 18n / 10000n);
|
|
428
|
+
const limit = current * multiplier / 10n ** 9n;
|
|
429
|
+
return zeroForOne ? limit > MIN_SQRT_PRICE ? limit : MIN_SQRT_PRICE : limit < MAX_SQRT_PRICE ? limit : MAX_SQRT_PRICE;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
exports.Q192 = Q192;
|
|
433
|
+
exports.Q96 = Q96;
|
|
434
|
+
exports.TICK_SPACING = TICK_SPACING;
|
|
435
|
+
exports.TickFinder = TickFinder;
|
|
436
|
+
exports.calculateUnderlyingTokenBalances = calculateUnderlyingTokenBalances;
|
|
437
|
+
exports.coinPoolKey = coinPoolKey;
|
|
438
|
+
exports.expectedEndSqrtPriceX96 = expectedEndSqrtPriceX96;
|
|
439
|
+
exports.getAmountWithSlippage = getAmountWithSlippage;
|
|
440
|
+
exports.getAmountsForLiquidity = getAmountsForLiquidity;
|
|
441
|
+
exports.getLiquidityFromAmounts = getLiquidityFromAmounts;
|
|
442
|
+
exports.getNearestUsableTick = getNearestUsableTick;
|
|
443
|
+
exports.getPoolId = getPoolId;
|
|
444
|
+
exports.getSqrtPriceX96FromTick = getSqrtPriceX96FromTick;
|
|
445
|
+
exports.getValidTick = getValidTick;
|
|
446
|
+
exports.maxLiquidityForAmount0Precise = maxLiquidityForAmount0Precise;
|
|
447
|
+
exports.maxLiquidityForAmount1 = maxLiquidityForAmount1;
|
|
448
|
+
exports.orderPoolKey = orderPoolKey;
|
|
449
|
+
exports.parseSwapData = parseSwapData;
|
|
450
|
+
exports.priceRatioToTick = priceRatioToTick;
|
|
451
|
+
exports.referrerHookData = referrerHookData;
|
|
452
|
+
exports.sqrtPriceLimit = sqrtPriceLimit;
|
|
453
|
+
exports.swapDirection = swapDirection;
|
|
454
|
+
exports.usdcIsCurrencyZero = usdcIsCurrencyZero;
|
|
455
|
+
//# sourceMappingURL=index.cjs.map
|