clanker-sdk 3.1.2 → 3.1.4
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 +16 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +36 -6
- package/dist/index.mjs +36 -6
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -48,7 +48,23 @@ declare class Clanker {
|
|
|
48
48
|
private readonly factoryAddress;
|
|
49
49
|
private readonly chainId;
|
|
50
50
|
private readonly publicClient;
|
|
51
|
+
private readonly Q96;
|
|
52
|
+
private readonly TICK_BASE;
|
|
53
|
+
private readonly TICK_SPACING;
|
|
54
|
+
private readonly MAX_TICK;
|
|
51
55
|
constructor(config: ClankerConfig);
|
|
56
|
+
/**
|
|
57
|
+
* Helper function to calculate sqrt using binary search with BigInt
|
|
58
|
+
* @param value - The value to calculate sqrt of (scaled by 2^96)
|
|
59
|
+
* @returns The sqrt of the value (scaled by 2^48)
|
|
60
|
+
*/
|
|
61
|
+
private sqrt96;
|
|
62
|
+
/**
|
|
63
|
+
* Helper function to calculate log base 1.0001 using binary search
|
|
64
|
+
* @param value - The value to calculate log of (scaled by 2^96)
|
|
65
|
+
* @returns The log base 1.0001 of the value
|
|
66
|
+
*/
|
|
67
|
+
private log1000196;
|
|
52
68
|
private calculateTick;
|
|
53
69
|
deploy(config: DeploymentConfig): Promise<Address>;
|
|
54
70
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -48,7 +48,23 @@ declare class Clanker {
|
|
|
48
48
|
private readonly factoryAddress;
|
|
49
49
|
private readonly chainId;
|
|
50
50
|
private readonly publicClient;
|
|
51
|
+
private readonly Q96;
|
|
52
|
+
private readonly TICK_BASE;
|
|
53
|
+
private readonly TICK_SPACING;
|
|
54
|
+
private readonly MAX_TICK;
|
|
51
55
|
constructor(config: ClankerConfig);
|
|
56
|
+
/**
|
|
57
|
+
* Helper function to calculate sqrt using binary search with BigInt
|
|
58
|
+
* @param value - The value to calculate sqrt of (scaled by 2^96)
|
|
59
|
+
* @returns The sqrt of the value (scaled by 2^48)
|
|
60
|
+
*/
|
|
61
|
+
private sqrt96;
|
|
62
|
+
/**
|
|
63
|
+
* Helper function to calculate log base 1.0001 using binary search
|
|
64
|
+
* @param value - The value to calculate log of (scaled by 2^96)
|
|
65
|
+
* @returns The log base 1.0001 of the value
|
|
66
|
+
*/
|
|
67
|
+
private log1000196;
|
|
52
68
|
private calculateTick;
|
|
53
69
|
deploy(config: DeploymentConfig): Promise<Address>;
|
|
54
70
|
}
|
package/dist/index.js
CHANGED
|
@@ -53,6 +53,11 @@ var CLANKER_ABI = (0, import_viem.parseAbi)([
|
|
|
53
53
|
]);
|
|
54
54
|
var Clanker = class {
|
|
55
55
|
constructor(config) {
|
|
56
|
+
this.Q96 = BigInt("79228162514264337593543950336");
|
|
57
|
+
// 2^96
|
|
58
|
+
this.TICK_BASE = 1.0001;
|
|
59
|
+
this.TICK_SPACING = 200;
|
|
60
|
+
this.MAX_TICK = 887200;
|
|
56
61
|
this.wallet = config.wallet;
|
|
57
62
|
this.factoryAddress = config.factoryAddress;
|
|
58
63
|
this.chainId = config.chainId;
|
|
@@ -61,6 +66,32 @@ var Clanker = class {
|
|
|
61
66
|
transport: (0, import_viem.http)()
|
|
62
67
|
});
|
|
63
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Helper function to calculate sqrt using binary search with BigInt
|
|
71
|
+
* @param value - The value to calculate sqrt of (scaled by 2^96)
|
|
72
|
+
* @returns The sqrt of the value (scaled by 2^48)
|
|
73
|
+
*/
|
|
74
|
+
sqrt96(value) {
|
|
75
|
+
if (value < BigInt(0)) {
|
|
76
|
+
throw new Error("Cannot calculate sqrt of negative number");
|
|
77
|
+
}
|
|
78
|
+
let z = value;
|
|
79
|
+
let x = value / BigInt(2) + BigInt(1);
|
|
80
|
+
while (x < z) {
|
|
81
|
+
z = x;
|
|
82
|
+
x = (value / x + x) / BigInt(2);
|
|
83
|
+
}
|
|
84
|
+
return z;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Helper function to calculate log base 1.0001 using binary search
|
|
88
|
+
* @param value - The value to calculate log of (scaled by 2^96)
|
|
89
|
+
* @returns The log base 1.0001 of the value
|
|
90
|
+
*/
|
|
91
|
+
log1000196(value) {
|
|
92
|
+
const valueNum = Number(value) / Number(this.Q96);
|
|
93
|
+
return Math.floor(Math.log(valueNum) / Math.log(this.TICK_BASE));
|
|
94
|
+
}
|
|
64
95
|
calculateTick(pairedToken, initialMarketCapInPairedToken) {
|
|
65
96
|
return __async(this, null, function* () {
|
|
66
97
|
try {
|
|
@@ -71,12 +102,11 @@ var Clanker = class {
|
|
|
71
102
|
});
|
|
72
103
|
const decimals = yield tokenContract.read.decimals();
|
|
73
104
|
const TOTAL_SUPPLY = BigInt("100000000000000000000000000000");
|
|
74
|
-
const priceInPairedToken = initialMarketCapInPairedToken * BigInt(10) ** BigInt(decimals)
|
|
75
|
-
const
|
|
76
|
-
const rawTick =
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
return tick;
|
|
105
|
+
const priceInPairedToken = TOTAL_SUPPLY * this.Q96 / (initialMarketCapInPairedToken * BigInt(10) ** BigInt(decimals));
|
|
106
|
+
const sqrtPriceX96 = this.sqrt96(priceInPairedToken);
|
|
107
|
+
const rawTick = this.log1000196(sqrtPriceX96);
|
|
108
|
+
const tick = Math.round(rawTick / this.TICK_SPACING) * this.TICK_SPACING;
|
|
109
|
+
return Math.min(Math.max(tick, -this.MAX_TICK), this.MAX_TICK);
|
|
80
110
|
} catch (error) {
|
|
81
111
|
throw new Error(`Failed to calculate tick: ${error instanceof Error ? error.message : String(error)}`);
|
|
82
112
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -36,6 +36,11 @@ var CLANKER_ABI = parseAbi([
|
|
|
36
36
|
]);
|
|
37
37
|
var Clanker = class {
|
|
38
38
|
constructor(config) {
|
|
39
|
+
this.Q96 = BigInt("79228162514264337593543950336");
|
|
40
|
+
// 2^96
|
|
41
|
+
this.TICK_BASE = 1.0001;
|
|
42
|
+
this.TICK_SPACING = 200;
|
|
43
|
+
this.MAX_TICK = 887200;
|
|
39
44
|
this.wallet = config.wallet;
|
|
40
45
|
this.factoryAddress = config.factoryAddress;
|
|
41
46
|
this.chainId = config.chainId;
|
|
@@ -44,6 +49,32 @@ var Clanker = class {
|
|
|
44
49
|
transport: http()
|
|
45
50
|
});
|
|
46
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Helper function to calculate sqrt using binary search with BigInt
|
|
54
|
+
* @param value - The value to calculate sqrt of (scaled by 2^96)
|
|
55
|
+
* @returns The sqrt of the value (scaled by 2^48)
|
|
56
|
+
*/
|
|
57
|
+
sqrt96(value) {
|
|
58
|
+
if (value < BigInt(0)) {
|
|
59
|
+
throw new Error("Cannot calculate sqrt of negative number");
|
|
60
|
+
}
|
|
61
|
+
let z = value;
|
|
62
|
+
let x = value / BigInt(2) + BigInt(1);
|
|
63
|
+
while (x < z) {
|
|
64
|
+
z = x;
|
|
65
|
+
x = (value / x + x) / BigInt(2);
|
|
66
|
+
}
|
|
67
|
+
return z;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Helper function to calculate log base 1.0001 using binary search
|
|
71
|
+
* @param value - The value to calculate log of (scaled by 2^96)
|
|
72
|
+
* @returns The log base 1.0001 of the value
|
|
73
|
+
*/
|
|
74
|
+
log1000196(value) {
|
|
75
|
+
const valueNum = Number(value) / Number(this.Q96);
|
|
76
|
+
return Math.floor(Math.log(valueNum) / Math.log(this.TICK_BASE));
|
|
77
|
+
}
|
|
47
78
|
calculateTick(pairedToken, initialMarketCapInPairedToken) {
|
|
48
79
|
return __async(this, null, function* () {
|
|
49
80
|
try {
|
|
@@ -54,12 +85,11 @@ var Clanker = class {
|
|
|
54
85
|
});
|
|
55
86
|
const decimals = yield tokenContract.read.decimals();
|
|
56
87
|
const TOTAL_SUPPLY = BigInt("100000000000000000000000000000");
|
|
57
|
-
const priceInPairedToken = initialMarketCapInPairedToken * BigInt(10) ** BigInt(decimals)
|
|
58
|
-
const
|
|
59
|
-
const rawTick =
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
return tick;
|
|
88
|
+
const priceInPairedToken = TOTAL_SUPPLY * this.Q96 / (initialMarketCapInPairedToken * BigInt(10) ** BigInt(decimals));
|
|
89
|
+
const sqrtPriceX96 = this.sqrt96(priceInPairedToken);
|
|
90
|
+
const rawTick = this.log1000196(sqrtPriceX96);
|
|
91
|
+
const tick = Math.round(rawTick / this.TICK_SPACING) * this.TICK_SPACING;
|
|
92
|
+
return Math.min(Math.max(tick, -this.MAX_TICK), this.MAX_TICK);
|
|
63
93
|
} catch (error) {
|
|
64
94
|
throw new Error(`Failed to calculate tick: ${error instanceof Error ? error.message : String(error)}`);
|
|
65
95
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clanker-sdk",
|
|
3
|
-
"version": "3.1.
|
|
4
|
-
"description": "SDK for deploying tokens using Clanker v3.1.
|
|
3
|
+
"version": "3.1.4",
|
|
4
|
+
"description": "SDK for deploying tokens using Clanker v3.1.3",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|