clanker-sdk 3.2.0 → 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 +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +53 -40
- package/dist/index.mjs +55 -43
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -17,6 +17,7 @@ interface PoolConfig {
|
|
|
17
17
|
pairedToken: Address;
|
|
18
18
|
initialMarketCapInPairedToken: bigint;
|
|
19
19
|
initialMarketCap?: string;
|
|
20
|
+
tickIfToken0IsNewToken: number;
|
|
20
21
|
}
|
|
21
22
|
interface InitialBuyConfig {
|
|
22
23
|
pairedTokenPoolFee: 10000;
|
|
@@ -77,9 +78,8 @@ declare class Clanker {
|
|
|
77
78
|
private readonly factoryAddress;
|
|
78
79
|
private readonly publicClient;
|
|
79
80
|
constructor(config: ClankerConfig);
|
|
80
|
-
private
|
|
81
|
-
private
|
|
82
|
-
private calculateTickFromMarketCap;
|
|
81
|
+
private getQuoteTokenDecimals;
|
|
82
|
+
private calculateTickForQuoteToken;
|
|
83
83
|
private handleError;
|
|
84
84
|
deploy(config: DeploymentConfig): Promise<Address>;
|
|
85
85
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ interface PoolConfig {
|
|
|
17
17
|
pairedToken: Address;
|
|
18
18
|
initialMarketCapInPairedToken: bigint;
|
|
19
19
|
initialMarketCap?: string;
|
|
20
|
+
tickIfToken0IsNewToken: number;
|
|
20
21
|
}
|
|
21
22
|
interface InitialBuyConfig {
|
|
22
23
|
pairedTokenPoolFee: 10000;
|
|
@@ -77,9 +78,8 @@ declare class Clanker {
|
|
|
77
78
|
private readonly factoryAddress;
|
|
78
79
|
private readonly publicClient;
|
|
79
80
|
constructor(config: ClankerConfig);
|
|
80
|
-
private
|
|
81
|
-
private
|
|
82
|
-
private calculateTickFromMarketCap;
|
|
81
|
+
private getQuoteTokenDecimals;
|
|
82
|
+
private calculateTickForQuoteToken;
|
|
83
83
|
private handleError;
|
|
84
84
|
deploy(config: DeploymentConfig): Promise<Address>;
|
|
85
85
|
/**
|
package/dist/index.js
CHANGED
|
@@ -28,16 +28,7 @@ var import_actions = require("viem/actions");
|
|
|
28
28
|
|
|
29
29
|
// src/constants.ts
|
|
30
30
|
var WETH_ADDRESS = "0x4200000000000000000000000000000000000006";
|
|
31
|
-
var CLANKER_FACTORY_V3_1 = "
|
|
32
|
-
var ERC20_DECIMALS_ABI = [
|
|
33
|
-
{
|
|
34
|
-
"inputs": [],
|
|
35
|
-
"name": "decimals",
|
|
36
|
-
"outputs": [{ "type": "uint8", "name": "" }],
|
|
37
|
-
"stateMutability": "view",
|
|
38
|
-
"type": "function"
|
|
39
|
-
}
|
|
40
|
-
];
|
|
31
|
+
var CLANKER_FACTORY_V3_1 = "0x2A787b2362021cC3eEa3C24C4748a6cD5B687382";
|
|
41
32
|
|
|
42
33
|
// src/abis/Clanker_V3_1.ts
|
|
43
34
|
var Clanker_v3_1_abi = [
|
|
@@ -533,6 +524,15 @@ var Clanker_v3_1_abi = [
|
|
|
533
524
|
];
|
|
534
525
|
|
|
535
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
|
+
];
|
|
536
536
|
var Clanker = class {
|
|
537
537
|
wallet;
|
|
538
538
|
factoryAddress;
|
|
@@ -542,40 +542,47 @@ var Clanker = class {
|
|
|
542
542
|
this.publicClient = config.publicClient;
|
|
543
543
|
this.factoryAddress = config.factoryAddress ?? CLANKER_FACTORY_V3_1;
|
|
544
544
|
}
|
|
545
|
-
//
|
|
546
|
-
async
|
|
545
|
+
// Get quote token decimals
|
|
546
|
+
async getQuoteTokenDecimals(quoteToken) {
|
|
547
547
|
try {
|
|
548
548
|
const decimals = await (0, import_actions.readContract)(this.publicClient, {
|
|
549
|
-
address:
|
|
549
|
+
address: quoteToken,
|
|
550
550
|
abi: ERC20_DECIMALS_ABI,
|
|
551
551
|
functionName: "decimals"
|
|
552
552
|
});
|
|
553
553
|
return decimals;
|
|
554
554
|
} catch (error) {
|
|
555
|
-
console.warn(`Failed to fetch decimals for token ${
|
|
555
|
+
console.warn(`Failed to fetch decimals for quote token ${quoteToken}, defaulting to 18:`, error);
|
|
556
556
|
return 18;
|
|
557
557
|
}
|
|
558
558
|
}
|
|
559
|
-
//
|
|
560
|
-
|
|
561
|
-
const
|
|
562
|
-
|
|
563
|
-
const
|
|
564
|
-
const
|
|
565
|
-
const
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
// Calculate tick based on desired market cap and token decimals
|
|
569
|
-
async calculateTickFromMarketCap(marketCap, quoteToken) {
|
|
570
|
-
const quoteDecimals = await this.getTokenDecimals(quoteToken);
|
|
571
|
-
const marketCapBigInt = (0, import_viem.parseEther)(marketCap);
|
|
572
|
-
const adjustedMarketCap = Number((0, import_viem.formatUnits)(marketCapBigInt, quoteDecimals));
|
|
573
|
-
const totalSupply = 1e6;
|
|
574
|
-
const desiredPrice = adjustedMarketCap / totalSupply;
|
|
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);
|
|
575
568
|
const logBase = 1.0001;
|
|
576
569
|
const tickSpacing = 200;
|
|
577
|
-
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);
|
|
578
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);
|
|
579
586
|
return initialTick;
|
|
580
587
|
}
|
|
581
588
|
handleError(error) {
|
|
@@ -588,6 +595,10 @@ var Clanker = class {
|
|
|
588
595
|
}
|
|
589
596
|
try {
|
|
590
597
|
const rewardsConfig = config.rewardsConfig;
|
|
598
|
+
const tick = await this.calculateTickForQuoteToken(
|
|
599
|
+
config.poolConfig.pairedToken,
|
|
600
|
+
config.poolConfig.initialMarketCapInPairedToken
|
|
601
|
+
);
|
|
591
602
|
const deploymentData = {
|
|
592
603
|
tokenConfig: {
|
|
593
604
|
name: config.tokenConfig.name,
|
|
@@ -604,7 +615,7 @@ var Clanker = class {
|
|
|
604
615
|
},
|
|
605
616
|
poolConfig: {
|
|
606
617
|
pairedToken: config.poolConfig.pairedToken,
|
|
607
|
-
tickIfToken0IsNewToken:
|
|
618
|
+
tickIfToken0IsNewToken: tick
|
|
608
619
|
},
|
|
609
620
|
initialBuyConfig: {
|
|
610
621
|
pairedTokenPoolFee: config.initialBuyConfig?.pairedTokenPoolFee ?? 1e4,
|
|
@@ -623,7 +634,7 @@ var Clanker = class {
|
|
|
623
634
|
abi: Clanker_v3_1_abi,
|
|
624
635
|
functionName: "deployToken",
|
|
625
636
|
args: [deploymentData],
|
|
626
|
-
value:
|
|
637
|
+
value: BigInt(0),
|
|
627
638
|
chain: this.publicClient.chain,
|
|
628
639
|
account: this.wallet.account
|
|
629
640
|
});
|
|
@@ -655,19 +666,20 @@ var Clanker = class {
|
|
|
655
666
|
}
|
|
656
667
|
const deployerAddress = this.wallet.account.address;
|
|
657
668
|
const quoteToken = config.pool?.quoteToken ?? WETH_ADDRESS;
|
|
658
|
-
const
|
|
669
|
+
const quoteDecimals = await this.getQuoteTokenDecimals(quoteToken);
|
|
670
|
+
console.log("Quote token decimals:", quoteDecimals);
|
|
659
671
|
const deploymentConfig = {
|
|
660
672
|
tokenConfig: {
|
|
661
673
|
name: config.name,
|
|
662
674
|
symbol: config.symbol,
|
|
663
|
-
salt: config.salt
|
|
664
|
-
image: config.image
|
|
665
|
-
metadata: config.metadata
|
|
675
|
+
salt: config.salt || "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
676
|
+
image: config.image || "https://ipfs.io/ipfs/QmcjfTeK3tpK3MVCQuvEaXvSscrqbL3MwsEo8LdBTWabY4",
|
|
677
|
+
metadata: config.metadata || {
|
|
666
678
|
description: "Clanker Token",
|
|
667
679
|
socialMediaUrls: [],
|
|
668
680
|
auditUrls: []
|
|
669
681
|
},
|
|
670
|
-
context: config.context
|
|
682
|
+
context: config.context || {
|
|
671
683
|
interface: "Clanker SDK",
|
|
672
684
|
platform: "Clanker",
|
|
673
685
|
messageId: "Clanker SDK",
|
|
@@ -677,8 +689,9 @@ var Clanker = class {
|
|
|
677
689
|
},
|
|
678
690
|
poolConfig: {
|
|
679
691
|
pairedToken: quoteToken,
|
|
680
|
-
initialMarketCapInPairedToken: (0, import_viem.
|
|
681
|
-
|
|
692
|
+
initialMarketCapInPairedToken: (0, import_viem.parseUnits)(config.pool?.initialMarketCap ?? "10", quoteDecimals),
|
|
693
|
+
tickIfToken0IsNewToken: 0
|
|
694
|
+
// Will be calculated in deploy() based on quote token
|
|
682
695
|
},
|
|
683
696
|
vaultConfig: config.vault ? {
|
|
684
697
|
vaultPercentage: config.vault.percentage,
|
package/dist/index.mjs
CHANGED
|
@@ -1,24 +1,14 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
parseUnits,
|
|
4
4
|
stringify,
|
|
5
|
-
parseEventLogs
|
|
6
|
-
formatUnits
|
|
5
|
+
parseEventLogs
|
|
7
6
|
} from "viem";
|
|
8
7
|
import { simulateContract, writeContract, readContract } from "viem/actions";
|
|
9
8
|
|
|
10
9
|
// src/constants.ts
|
|
11
10
|
var WETH_ADDRESS = "0x4200000000000000000000000000000000000006";
|
|
12
|
-
var CLANKER_FACTORY_V3_1 = "
|
|
13
|
-
var ERC20_DECIMALS_ABI = [
|
|
14
|
-
{
|
|
15
|
-
"inputs": [],
|
|
16
|
-
"name": "decimals",
|
|
17
|
-
"outputs": [{ "type": "uint8", "name": "" }],
|
|
18
|
-
"stateMutability": "view",
|
|
19
|
-
"type": "function"
|
|
20
|
-
}
|
|
21
|
-
];
|
|
11
|
+
var CLANKER_FACTORY_V3_1 = "0x2A787b2362021cC3eEa3C24C4748a6cD5B687382";
|
|
22
12
|
|
|
23
13
|
// src/abis/Clanker_V3_1.ts
|
|
24
14
|
var Clanker_v3_1_abi = [
|
|
@@ -514,6 +504,15 @@ var Clanker_v3_1_abi = [
|
|
|
514
504
|
];
|
|
515
505
|
|
|
516
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
|
+
];
|
|
517
516
|
var Clanker = class {
|
|
518
517
|
wallet;
|
|
519
518
|
factoryAddress;
|
|
@@ -523,40 +522,47 @@ var Clanker = class {
|
|
|
523
522
|
this.publicClient = config.publicClient;
|
|
524
523
|
this.factoryAddress = config.factoryAddress ?? CLANKER_FACTORY_V3_1;
|
|
525
524
|
}
|
|
526
|
-
//
|
|
527
|
-
async
|
|
525
|
+
// Get quote token decimals
|
|
526
|
+
async getQuoteTokenDecimals(quoteToken) {
|
|
528
527
|
try {
|
|
529
528
|
const decimals = await readContract(this.publicClient, {
|
|
530
|
-
address:
|
|
529
|
+
address: quoteToken,
|
|
531
530
|
abi: ERC20_DECIMALS_ABI,
|
|
532
531
|
functionName: "decimals"
|
|
533
532
|
});
|
|
534
533
|
return decimals;
|
|
535
534
|
} catch (error) {
|
|
536
|
-
console.warn(`Failed to fetch decimals for token ${
|
|
535
|
+
console.warn(`Failed to fetch decimals for quote token ${quoteToken}, defaulting to 18:`, error);
|
|
537
536
|
return 18;
|
|
538
537
|
}
|
|
539
538
|
}
|
|
540
|
-
//
|
|
541
|
-
|
|
542
|
-
const
|
|
543
|
-
|
|
544
|
-
const
|
|
545
|
-
const
|
|
546
|
-
const
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
// Calculate tick based on desired market cap and token decimals
|
|
550
|
-
async calculateTickFromMarketCap(marketCap, quoteToken) {
|
|
551
|
-
const quoteDecimals = await this.getTokenDecimals(quoteToken);
|
|
552
|
-
const marketCapBigInt = parseEther(marketCap);
|
|
553
|
-
const adjustedMarketCap = Number(formatUnits(marketCapBigInt, quoteDecimals));
|
|
554
|
-
const totalSupply = 1e6;
|
|
555
|
-
const desiredPrice = adjustedMarketCap / totalSupply;
|
|
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);
|
|
556
548
|
const logBase = 1.0001;
|
|
557
549
|
const tickSpacing = 200;
|
|
558
|
-
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);
|
|
559
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);
|
|
560
566
|
return initialTick;
|
|
561
567
|
}
|
|
562
568
|
handleError(error) {
|
|
@@ -569,6 +575,10 @@ var Clanker = class {
|
|
|
569
575
|
}
|
|
570
576
|
try {
|
|
571
577
|
const rewardsConfig = config.rewardsConfig;
|
|
578
|
+
const tick = await this.calculateTickForQuoteToken(
|
|
579
|
+
config.poolConfig.pairedToken,
|
|
580
|
+
config.poolConfig.initialMarketCapInPairedToken
|
|
581
|
+
);
|
|
572
582
|
const deploymentData = {
|
|
573
583
|
tokenConfig: {
|
|
574
584
|
name: config.tokenConfig.name,
|
|
@@ -585,7 +595,7 @@ var Clanker = class {
|
|
|
585
595
|
},
|
|
586
596
|
poolConfig: {
|
|
587
597
|
pairedToken: config.poolConfig.pairedToken,
|
|
588
|
-
tickIfToken0IsNewToken:
|
|
598
|
+
tickIfToken0IsNewToken: tick
|
|
589
599
|
},
|
|
590
600
|
initialBuyConfig: {
|
|
591
601
|
pairedTokenPoolFee: config.initialBuyConfig?.pairedTokenPoolFee ?? 1e4,
|
|
@@ -604,7 +614,7 @@ var Clanker = class {
|
|
|
604
614
|
abi: Clanker_v3_1_abi,
|
|
605
615
|
functionName: "deployToken",
|
|
606
616
|
args: [deploymentData],
|
|
607
|
-
value:
|
|
617
|
+
value: BigInt(0),
|
|
608
618
|
chain: this.publicClient.chain,
|
|
609
619
|
account: this.wallet.account
|
|
610
620
|
});
|
|
@@ -636,19 +646,20 @@ var Clanker = class {
|
|
|
636
646
|
}
|
|
637
647
|
const deployerAddress = this.wallet.account.address;
|
|
638
648
|
const quoteToken = config.pool?.quoteToken ?? WETH_ADDRESS;
|
|
639
|
-
const
|
|
649
|
+
const quoteDecimals = await this.getQuoteTokenDecimals(quoteToken);
|
|
650
|
+
console.log("Quote token decimals:", quoteDecimals);
|
|
640
651
|
const deploymentConfig = {
|
|
641
652
|
tokenConfig: {
|
|
642
653
|
name: config.name,
|
|
643
654
|
symbol: config.symbol,
|
|
644
|
-
salt: config.salt
|
|
645
|
-
image: config.image
|
|
646
|
-
metadata: config.metadata
|
|
655
|
+
salt: config.salt || "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
656
|
+
image: config.image || "https://ipfs.io/ipfs/QmcjfTeK3tpK3MVCQuvEaXvSscrqbL3MwsEo8LdBTWabY4",
|
|
657
|
+
metadata: config.metadata || {
|
|
647
658
|
description: "Clanker Token",
|
|
648
659
|
socialMediaUrls: [],
|
|
649
660
|
auditUrls: []
|
|
650
661
|
},
|
|
651
|
-
context: config.context
|
|
662
|
+
context: config.context || {
|
|
652
663
|
interface: "Clanker SDK",
|
|
653
664
|
platform: "Clanker",
|
|
654
665
|
messageId: "Clanker SDK",
|
|
@@ -658,8 +669,9 @@ var Clanker = class {
|
|
|
658
669
|
},
|
|
659
670
|
poolConfig: {
|
|
660
671
|
pairedToken: quoteToken,
|
|
661
|
-
initialMarketCapInPairedToken:
|
|
662
|
-
|
|
672
|
+
initialMarketCapInPairedToken: parseUnits(config.pool?.initialMarketCap ?? "10", quoteDecimals),
|
|
673
|
+
tickIfToken0IsNewToken: 0
|
|
674
|
+
// Will be calculated in deploy() based on quote token
|
|
663
675
|
},
|
|
664
676
|
vaultConfig: config.vault ? {
|
|
665
677
|
vaultPercentage: config.vault.percentage,
|