clanker-sdk 3.1.13 → 3.3.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 +15 -38
- package/dist/index.d.ts +15 -38
- package/dist/index.js +60 -9
- package/dist/index.mjs +62 -11
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -16,6 +16,8 @@ interface VaultConfig {
|
|
|
16
16
|
interface PoolConfig {
|
|
17
17
|
pairedToken: Address;
|
|
18
18
|
initialMarketCapInPairedToken: bigint;
|
|
19
|
+
initialMarketCap?: string;
|
|
20
|
+
tickIfToken0IsNewToken: number;
|
|
19
21
|
}
|
|
20
22
|
interface InitialBuyConfig {
|
|
21
23
|
pairedTokenPoolFee: 10000;
|
|
@@ -28,6 +30,13 @@ interface RewardsConfig {
|
|
|
28
30
|
interfaceAdmin: Address;
|
|
29
31
|
interfaceRewardRecipient: Address;
|
|
30
32
|
}
|
|
33
|
+
interface DeploymentConfig {
|
|
34
|
+
tokenConfig: TokenConfig;
|
|
35
|
+
vaultConfig?: VaultConfig;
|
|
36
|
+
poolConfig: PoolConfig;
|
|
37
|
+
initialBuyConfig?: InitialBuyConfig;
|
|
38
|
+
rewardsConfig: RewardsConfig;
|
|
39
|
+
}
|
|
31
40
|
interface ClankerConfig {
|
|
32
41
|
wallet: WalletClient;
|
|
33
42
|
publicClient: PublicClient;
|
|
@@ -42,46 +51,13 @@ interface SimpleTokenConfig {
|
|
|
42
51
|
percentage: number;
|
|
43
52
|
durationInDays: number;
|
|
44
53
|
};
|
|
54
|
+
pool?: {
|
|
55
|
+
quoteToken?: Address;
|
|
56
|
+
initialMarketCap?: string;
|
|
57
|
+
};
|
|
45
58
|
metadata?: IClankerMetadata;
|
|
46
59
|
context?: IClankerSocialContext;
|
|
47
60
|
}
|
|
48
|
-
interface DeploymentConfig {
|
|
49
|
-
tokenConfig: TokenConfig;
|
|
50
|
-
vaultConfig?: VaultConfig;
|
|
51
|
-
poolConfig: PoolConfig;
|
|
52
|
-
initialBuyConfig?: InitialBuyConfig;
|
|
53
|
-
rewardsConfig: RewardsConfig;
|
|
54
|
-
}
|
|
55
|
-
interface DeploymentConfig {
|
|
56
|
-
tokenConfig: {
|
|
57
|
-
name: string;
|
|
58
|
-
symbol: string;
|
|
59
|
-
salt: `0x${string}`;
|
|
60
|
-
image: string;
|
|
61
|
-
metadata: IClankerMetadata;
|
|
62
|
-
context: IClankerSocialContext;
|
|
63
|
-
originatingChainId: bigint;
|
|
64
|
-
};
|
|
65
|
-
poolConfig: {
|
|
66
|
-
pairedToken: Address;
|
|
67
|
-
initialMarketCapInPairedToken: bigint;
|
|
68
|
-
};
|
|
69
|
-
vaultConfig?: {
|
|
70
|
-
vaultPercentage: number;
|
|
71
|
-
vaultDuration: bigint;
|
|
72
|
-
};
|
|
73
|
-
initialBuyConfig?: {
|
|
74
|
-
pairedTokenPoolFee: 10000;
|
|
75
|
-
pairedTokenSwapAmountOutMinimum: bigint;
|
|
76
|
-
};
|
|
77
|
-
rewardsConfig: {
|
|
78
|
-
creatorReward: bigint;
|
|
79
|
-
creatorAdmin: Address;
|
|
80
|
-
creatorRewardRecipient: Address;
|
|
81
|
-
interfaceAdmin: Address;
|
|
82
|
-
interfaceRewardRecipient: Address;
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
61
|
interface IClankerMetadata {
|
|
86
62
|
description?: string;
|
|
87
63
|
socialMediaUrls?: {
|
|
@@ -102,7 +78,8 @@ declare class Clanker {
|
|
|
102
78
|
private readonly factoryAddress;
|
|
103
79
|
private readonly publicClient;
|
|
104
80
|
constructor(config: ClankerConfig);
|
|
105
|
-
private
|
|
81
|
+
private getQuoteTokenDecimals;
|
|
82
|
+
private calculateTickForQuoteToken;
|
|
106
83
|
private handleError;
|
|
107
84
|
deploy(config: DeploymentConfig): Promise<Address>;
|
|
108
85
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -16,6 +16,8 @@ interface VaultConfig {
|
|
|
16
16
|
interface PoolConfig {
|
|
17
17
|
pairedToken: Address;
|
|
18
18
|
initialMarketCapInPairedToken: bigint;
|
|
19
|
+
initialMarketCap?: string;
|
|
20
|
+
tickIfToken0IsNewToken: number;
|
|
19
21
|
}
|
|
20
22
|
interface InitialBuyConfig {
|
|
21
23
|
pairedTokenPoolFee: 10000;
|
|
@@ -28,6 +30,13 @@ interface RewardsConfig {
|
|
|
28
30
|
interfaceAdmin: Address;
|
|
29
31
|
interfaceRewardRecipient: Address;
|
|
30
32
|
}
|
|
33
|
+
interface DeploymentConfig {
|
|
34
|
+
tokenConfig: TokenConfig;
|
|
35
|
+
vaultConfig?: VaultConfig;
|
|
36
|
+
poolConfig: PoolConfig;
|
|
37
|
+
initialBuyConfig?: InitialBuyConfig;
|
|
38
|
+
rewardsConfig: RewardsConfig;
|
|
39
|
+
}
|
|
31
40
|
interface ClankerConfig {
|
|
32
41
|
wallet: WalletClient;
|
|
33
42
|
publicClient: PublicClient;
|
|
@@ -42,46 +51,13 @@ interface SimpleTokenConfig {
|
|
|
42
51
|
percentage: number;
|
|
43
52
|
durationInDays: number;
|
|
44
53
|
};
|
|
54
|
+
pool?: {
|
|
55
|
+
quoteToken?: Address;
|
|
56
|
+
initialMarketCap?: string;
|
|
57
|
+
};
|
|
45
58
|
metadata?: IClankerMetadata;
|
|
46
59
|
context?: IClankerSocialContext;
|
|
47
60
|
}
|
|
48
|
-
interface DeploymentConfig {
|
|
49
|
-
tokenConfig: TokenConfig;
|
|
50
|
-
vaultConfig?: VaultConfig;
|
|
51
|
-
poolConfig: PoolConfig;
|
|
52
|
-
initialBuyConfig?: InitialBuyConfig;
|
|
53
|
-
rewardsConfig: RewardsConfig;
|
|
54
|
-
}
|
|
55
|
-
interface DeploymentConfig {
|
|
56
|
-
tokenConfig: {
|
|
57
|
-
name: string;
|
|
58
|
-
symbol: string;
|
|
59
|
-
salt: `0x${string}`;
|
|
60
|
-
image: string;
|
|
61
|
-
metadata: IClankerMetadata;
|
|
62
|
-
context: IClankerSocialContext;
|
|
63
|
-
originatingChainId: bigint;
|
|
64
|
-
};
|
|
65
|
-
poolConfig: {
|
|
66
|
-
pairedToken: Address;
|
|
67
|
-
initialMarketCapInPairedToken: bigint;
|
|
68
|
-
};
|
|
69
|
-
vaultConfig?: {
|
|
70
|
-
vaultPercentage: number;
|
|
71
|
-
vaultDuration: bigint;
|
|
72
|
-
};
|
|
73
|
-
initialBuyConfig?: {
|
|
74
|
-
pairedTokenPoolFee: 10000;
|
|
75
|
-
pairedTokenSwapAmountOutMinimum: bigint;
|
|
76
|
-
};
|
|
77
|
-
rewardsConfig: {
|
|
78
|
-
creatorReward: bigint;
|
|
79
|
-
creatorAdmin: Address;
|
|
80
|
-
creatorRewardRecipient: Address;
|
|
81
|
-
interfaceAdmin: Address;
|
|
82
|
-
interfaceRewardRecipient: Address;
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
61
|
interface IClankerMetadata {
|
|
86
62
|
description?: string;
|
|
87
63
|
socialMediaUrls?: {
|
|
@@ -102,7 +78,8 @@ declare class Clanker {
|
|
|
102
78
|
private readonly factoryAddress;
|
|
103
79
|
private readonly publicClient;
|
|
104
80
|
constructor(config: ClankerConfig);
|
|
105
|
-
private
|
|
81
|
+
private getQuoteTokenDecimals;
|
|
82
|
+
private calculateTickForQuoteToken;
|
|
106
83
|
private handleError;
|
|
107
84
|
deploy(config: DeploymentConfig): Promise<Address>;
|
|
108
85
|
/**
|
package/dist/index.js
CHANGED
|
@@ -524,6 +524,15 @@ var Clanker_v3_1_abi = [
|
|
|
524
524
|
];
|
|
525
525
|
|
|
526
526
|
// src/index.ts
|
|
527
|
+
var ERC20_DECIMALS_ABI = [
|
|
528
|
+
{
|
|
529
|
+
inputs: [],
|
|
530
|
+
name: "decimals",
|
|
531
|
+
outputs: [{ type: "uint8", name: "" }],
|
|
532
|
+
stateMutability: "view",
|
|
533
|
+
type: "function"
|
|
534
|
+
}
|
|
535
|
+
];
|
|
527
536
|
var Clanker = class {
|
|
528
537
|
wallet;
|
|
529
538
|
factoryAddress;
|
|
@@ -533,13 +542,47 @@ var Clanker = class {
|
|
|
533
542
|
this.publicClient = config.publicClient;
|
|
534
543
|
this.factoryAddress = config.factoryAddress ?? CLANKER_FACTORY_V3_1;
|
|
535
544
|
}
|
|
536
|
-
// Get
|
|
537
|
-
|
|
538
|
-
|
|
545
|
+
// Get quote token decimals
|
|
546
|
+
async getQuoteTokenDecimals(quoteToken) {
|
|
547
|
+
try {
|
|
548
|
+
const decimals = await (0, import_actions.readContract)(this.publicClient, {
|
|
549
|
+
address: quoteToken,
|
|
550
|
+
abi: ERC20_DECIMALS_ABI,
|
|
551
|
+
functionName: "decimals"
|
|
552
|
+
});
|
|
553
|
+
return decimals;
|
|
554
|
+
} catch (error) {
|
|
555
|
+
console.warn(`Failed to fetch decimals for quote token ${quoteToken}, defaulting to 18:`, error);
|
|
556
|
+
return 18;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
// Calculate tick based on quote token and token ordering
|
|
560
|
+
async calculateTickForQuoteToken(quoteToken, marketCap) {
|
|
561
|
+
const quoteDecimals = await this.getQuoteTokenDecimals(quoteToken);
|
|
562
|
+
console.log("Quote token decimals:", quoteDecimals);
|
|
563
|
+
const tokenDecimals = 18;
|
|
564
|
+
const totalSupply = BigInt(1e11) * BigInt(10) ** BigInt(tokenDecimals);
|
|
565
|
+
const priceInQuoteToken = Number(marketCap) / Number(totalSupply);
|
|
566
|
+
console.log("Price in quote token:", priceInQuoteToken);
|
|
567
|
+
console.log("Market cap in quote token units:", Number(marketCap) / 10 ** quoteDecimals);
|
|
539
568
|
const logBase = 1.0001;
|
|
540
569
|
const tickSpacing = 200;
|
|
541
|
-
const
|
|
570
|
+
const dummyTokenAddress = "0xffffffffffffffffffffffffffffffffffffffff";
|
|
571
|
+
const isToken0 = dummyTokenAddress.toLowerCase() < quoteToken.toLowerCase();
|
|
572
|
+
console.log("Is new token token0?", isToken0);
|
|
573
|
+
const priceForTick = isToken0 ? priceInQuoteToken : 1 / priceInQuoteToken;
|
|
574
|
+
let rawTick = Math.floor(Math.log(priceForTick) / Math.log(logBase));
|
|
575
|
+
if (!isToken0) {
|
|
576
|
+
rawTick = -rawTick;
|
|
577
|
+
}
|
|
578
|
+
console.log("Raw tick (before spacing):", rawTick);
|
|
542
579
|
const initialTick = Math.floor(rawTick / tickSpacing) * tickSpacing;
|
|
580
|
+
console.log("Final tick (rounded to spacing):", initialTick);
|
|
581
|
+
const actualPrice = Math.pow(logBase, isToken0 ? initialTick : -initialTick);
|
|
582
|
+
console.log("Actual price from tick:", actualPrice);
|
|
583
|
+
const finalPrice = isToken0 ? actualPrice : 1 / actualPrice;
|
|
584
|
+
const actualMarketCap = finalPrice * Number(totalSupply) / Math.pow(10, tokenDecimals);
|
|
585
|
+
console.log("Actual market cap in quote token:", actualMarketCap);
|
|
543
586
|
return initialTick;
|
|
544
587
|
}
|
|
545
588
|
handleError(error) {
|
|
@@ -552,6 +595,10 @@ var Clanker = class {
|
|
|
552
595
|
}
|
|
553
596
|
try {
|
|
554
597
|
const rewardsConfig = config.rewardsConfig;
|
|
598
|
+
const tick = await this.calculateTickForQuoteToken(
|
|
599
|
+
config.poolConfig.pairedToken,
|
|
600
|
+
config.poolConfig.initialMarketCapInPairedToken
|
|
601
|
+
);
|
|
555
602
|
const deploymentData = {
|
|
556
603
|
tokenConfig: {
|
|
557
604
|
name: config.tokenConfig.name,
|
|
@@ -568,7 +615,7 @@ var Clanker = class {
|
|
|
568
615
|
},
|
|
569
616
|
poolConfig: {
|
|
570
617
|
pairedToken: config.poolConfig.pairedToken,
|
|
571
|
-
tickIfToken0IsNewToken:
|
|
618
|
+
tickIfToken0IsNewToken: tick
|
|
572
619
|
},
|
|
573
620
|
initialBuyConfig: {
|
|
574
621
|
pairedTokenPoolFee: config.initialBuyConfig?.pairedTokenPoolFee ?? 1e4,
|
|
@@ -587,7 +634,7 @@ var Clanker = class {
|
|
|
587
634
|
abi: Clanker_v3_1_abi,
|
|
588
635
|
functionName: "deployToken",
|
|
589
636
|
args: [deploymentData],
|
|
590
|
-
value:
|
|
637
|
+
value: BigInt(0),
|
|
591
638
|
chain: this.publicClient.chain,
|
|
592
639
|
account: this.wallet.account
|
|
593
640
|
});
|
|
@@ -618,6 +665,9 @@ var Clanker = class {
|
|
|
618
665
|
throw new Error("Wallet account not configured");
|
|
619
666
|
}
|
|
620
667
|
const deployerAddress = this.wallet.account.address;
|
|
668
|
+
const quoteToken = config.pool?.quoteToken ?? WETH_ADDRESS;
|
|
669
|
+
const quoteDecimals = await this.getQuoteTokenDecimals(quoteToken);
|
|
670
|
+
console.log("Quote token decimals:", quoteDecimals);
|
|
621
671
|
const deploymentConfig = {
|
|
622
672
|
tokenConfig: {
|
|
623
673
|
name: config.name,
|
|
@@ -638,9 +688,10 @@ var Clanker = class {
|
|
|
638
688
|
originatingChainId: BigInt(this.publicClient.chain.id)
|
|
639
689
|
},
|
|
640
690
|
poolConfig: {
|
|
641
|
-
pairedToken:
|
|
642
|
-
|
|
643
|
-
|
|
691
|
+
pairedToken: quoteToken,
|
|
692
|
+
initialMarketCapInPairedToken: (0, import_viem.parseUnits)(config.pool?.initialMarketCap ?? "10", quoteDecimals),
|
|
693
|
+
tickIfToken0IsNewToken: 0
|
|
694
|
+
// Will be calculated in deploy() based on quote token
|
|
644
695
|
},
|
|
645
696
|
vaultConfig: config.vault ? {
|
|
646
697
|
vaultPercentage: config.vault.percentage,
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
parseUnits,
|
|
4
4
|
stringify,
|
|
5
5
|
parseEventLogs
|
|
6
6
|
} from "viem";
|
|
7
|
-
import { simulateContract, writeContract } from "viem/actions";
|
|
7
|
+
import { simulateContract, writeContract, readContract } from "viem/actions";
|
|
8
8
|
|
|
9
9
|
// src/constants.ts
|
|
10
10
|
var WETH_ADDRESS = "0x4200000000000000000000000000000000000006";
|
|
@@ -504,6 +504,15 @@ var Clanker_v3_1_abi = [
|
|
|
504
504
|
];
|
|
505
505
|
|
|
506
506
|
// src/index.ts
|
|
507
|
+
var ERC20_DECIMALS_ABI = [
|
|
508
|
+
{
|
|
509
|
+
inputs: [],
|
|
510
|
+
name: "decimals",
|
|
511
|
+
outputs: [{ type: "uint8", name: "" }],
|
|
512
|
+
stateMutability: "view",
|
|
513
|
+
type: "function"
|
|
514
|
+
}
|
|
515
|
+
];
|
|
507
516
|
var Clanker = class {
|
|
508
517
|
wallet;
|
|
509
518
|
factoryAddress;
|
|
@@ -513,13 +522,47 @@ var Clanker = class {
|
|
|
513
522
|
this.publicClient = config.publicClient;
|
|
514
523
|
this.factoryAddress = config.factoryAddress ?? CLANKER_FACTORY_V3_1;
|
|
515
524
|
}
|
|
516
|
-
// Get
|
|
517
|
-
|
|
518
|
-
|
|
525
|
+
// Get quote token decimals
|
|
526
|
+
async getQuoteTokenDecimals(quoteToken) {
|
|
527
|
+
try {
|
|
528
|
+
const decimals = await readContract(this.publicClient, {
|
|
529
|
+
address: quoteToken,
|
|
530
|
+
abi: ERC20_DECIMALS_ABI,
|
|
531
|
+
functionName: "decimals"
|
|
532
|
+
});
|
|
533
|
+
return decimals;
|
|
534
|
+
} catch (error) {
|
|
535
|
+
console.warn(`Failed to fetch decimals for quote token ${quoteToken}, defaulting to 18:`, error);
|
|
536
|
+
return 18;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
// Calculate tick based on quote token and token ordering
|
|
540
|
+
async calculateTickForQuoteToken(quoteToken, marketCap) {
|
|
541
|
+
const quoteDecimals = await this.getQuoteTokenDecimals(quoteToken);
|
|
542
|
+
console.log("Quote token decimals:", quoteDecimals);
|
|
543
|
+
const tokenDecimals = 18;
|
|
544
|
+
const totalSupply = BigInt(1e11) * BigInt(10) ** BigInt(tokenDecimals);
|
|
545
|
+
const priceInQuoteToken = Number(marketCap) / Number(totalSupply);
|
|
546
|
+
console.log("Price in quote token:", priceInQuoteToken);
|
|
547
|
+
console.log("Market cap in quote token units:", Number(marketCap) / 10 ** quoteDecimals);
|
|
519
548
|
const logBase = 1.0001;
|
|
520
549
|
const tickSpacing = 200;
|
|
521
|
-
const
|
|
550
|
+
const dummyTokenAddress = "0xffffffffffffffffffffffffffffffffffffffff";
|
|
551
|
+
const isToken0 = dummyTokenAddress.toLowerCase() < quoteToken.toLowerCase();
|
|
552
|
+
console.log("Is new token token0?", isToken0);
|
|
553
|
+
const priceForTick = isToken0 ? priceInQuoteToken : 1 / priceInQuoteToken;
|
|
554
|
+
let rawTick = Math.floor(Math.log(priceForTick) / Math.log(logBase));
|
|
555
|
+
if (!isToken0) {
|
|
556
|
+
rawTick = -rawTick;
|
|
557
|
+
}
|
|
558
|
+
console.log("Raw tick (before spacing):", rawTick);
|
|
522
559
|
const initialTick = Math.floor(rawTick / tickSpacing) * tickSpacing;
|
|
560
|
+
console.log("Final tick (rounded to spacing):", initialTick);
|
|
561
|
+
const actualPrice = Math.pow(logBase, isToken0 ? initialTick : -initialTick);
|
|
562
|
+
console.log("Actual price from tick:", actualPrice);
|
|
563
|
+
const finalPrice = isToken0 ? actualPrice : 1 / actualPrice;
|
|
564
|
+
const actualMarketCap = finalPrice * Number(totalSupply) / Math.pow(10, tokenDecimals);
|
|
565
|
+
console.log("Actual market cap in quote token:", actualMarketCap);
|
|
523
566
|
return initialTick;
|
|
524
567
|
}
|
|
525
568
|
handleError(error) {
|
|
@@ -532,6 +575,10 @@ var Clanker = class {
|
|
|
532
575
|
}
|
|
533
576
|
try {
|
|
534
577
|
const rewardsConfig = config.rewardsConfig;
|
|
578
|
+
const tick = await this.calculateTickForQuoteToken(
|
|
579
|
+
config.poolConfig.pairedToken,
|
|
580
|
+
config.poolConfig.initialMarketCapInPairedToken
|
|
581
|
+
);
|
|
535
582
|
const deploymentData = {
|
|
536
583
|
tokenConfig: {
|
|
537
584
|
name: config.tokenConfig.name,
|
|
@@ -548,7 +595,7 @@ var Clanker = class {
|
|
|
548
595
|
},
|
|
549
596
|
poolConfig: {
|
|
550
597
|
pairedToken: config.poolConfig.pairedToken,
|
|
551
|
-
tickIfToken0IsNewToken:
|
|
598
|
+
tickIfToken0IsNewToken: tick
|
|
552
599
|
},
|
|
553
600
|
initialBuyConfig: {
|
|
554
601
|
pairedTokenPoolFee: config.initialBuyConfig?.pairedTokenPoolFee ?? 1e4,
|
|
@@ -567,7 +614,7 @@ var Clanker = class {
|
|
|
567
614
|
abi: Clanker_v3_1_abi,
|
|
568
615
|
functionName: "deployToken",
|
|
569
616
|
args: [deploymentData],
|
|
570
|
-
value:
|
|
617
|
+
value: BigInt(0),
|
|
571
618
|
chain: this.publicClient.chain,
|
|
572
619
|
account: this.wallet.account
|
|
573
620
|
});
|
|
@@ -598,6 +645,9 @@ var Clanker = class {
|
|
|
598
645
|
throw new Error("Wallet account not configured");
|
|
599
646
|
}
|
|
600
647
|
const deployerAddress = this.wallet.account.address;
|
|
648
|
+
const quoteToken = config.pool?.quoteToken ?? WETH_ADDRESS;
|
|
649
|
+
const quoteDecimals = await this.getQuoteTokenDecimals(quoteToken);
|
|
650
|
+
console.log("Quote token decimals:", quoteDecimals);
|
|
601
651
|
const deploymentConfig = {
|
|
602
652
|
tokenConfig: {
|
|
603
653
|
name: config.name,
|
|
@@ -618,9 +668,10 @@ var Clanker = class {
|
|
|
618
668
|
originatingChainId: BigInt(this.publicClient.chain.id)
|
|
619
669
|
},
|
|
620
670
|
poolConfig: {
|
|
621
|
-
pairedToken:
|
|
622
|
-
|
|
623
|
-
|
|
671
|
+
pairedToken: quoteToken,
|
|
672
|
+
initialMarketCapInPairedToken: parseUnits(config.pool?.initialMarketCap ?? "10", quoteDecimals),
|
|
673
|
+
tickIfToken0IsNewToken: 0
|
|
674
|
+
// Will be calculated in deploy() based on quote token
|
|
624
675
|
},
|
|
625
676
|
vaultConfig: config.vault ? {
|
|
626
677
|
vaultPercentage: config.vault.percentage,
|