@strobelabs/perpcity-sdk 0.1.0 → 0.1.1
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 +29 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +71 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +42 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +1 -1
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { PublicClient, WalletClient, Address, Abi } from 'viem';
|
|
2
|
+
|
|
3
|
+
type PerpCityContext = {
|
|
4
|
+
publicClient: PublicClient;
|
|
5
|
+
walletClient: WalletClient;
|
|
6
|
+
addresses: {
|
|
7
|
+
perpManager: Address;
|
|
8
|
+
};
|
|
9
|
+
abis: {
|
|
10
|
+
perpManager: Abi;
|
|
11
|
+
beacon: Abi;
|
|
12
|
+
};
|
|
13
|
+
endpoints: {
|
|
14
|
+
goldsky: URL;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
declare class PerpManager {
|
|
19
|
+
readonly context: PerpCityContext;
|
|
20
|
+
constructor(context: PerpCityContext);
|
|
21
|
+
createPerp(startingPrice: number, beacon: Address): Promise<`0x${string}`>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare class Perp {
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
declare function priceToSqrtPriceX96(price: number): bigint;
|
|
28
|
+
|
|
29
|
+
export { Perp, type PerpCityContext, PerpManager, priceToSqrtPriceX96 };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { PublicClient, WalletClient, Address, Abi } from 'viem';
|
|
2
|
+
|
|
3
|
+
type PerpCityContext = {
|
|
4
|
+
publicClient: PublicClient;
|
|
5
|
+
walletClient: WalletClient;
|
|
6
|
+
addresses: {
|
|
7
|
+
perpManager: Address;
|
|
8
|
+
};
|
|
9
|
+
abis: {
|
|
10
|
+
perpManager: Abi;
|
|
11
|
+
beacon: Abi;
|
|
12
|
+
};
|
|
13
|
+
endpoints: {
|
|
14
|
+
goldsky: URL;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
declare class PerpManager {
|
|
19
|
+
readonly context: PerpCityContext;
|
|
20
|
+
constructor(context: PerpCityContext);
|
|
21
|
+
createPerp(startingPrice: number, beacon: Address): Promise<`0x${string}`>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare class Perp {
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
declare function priceToSqrtPriceX96(price: number): bigint;
|
|
28
|
+
|
|
29
|
+
export { Perp, type PerpCityContext, PerpManager, priceToSqrtPriceX96 };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
Perp: () => Perp,
|
|
24
|
+
PerpManager: () => PerpManager,
|
|
25
|
+
priceToSqrtPriceX96: () => priceToSqrtPriceX96
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
|
|
29
|
+
// src/utils/constants.ts
|
|
30
|
+
var DECIMAL_PRECISION_6 = 1e6;
|
|
31
|
+
var Q96 = 79228162514264337593543950336n;
|
|
32
|
+
|
|
33
|
+
// src/utils/conversions.ts
|
|
34
|
+
function priceToSqrtPriceX96(price) {
|
|
35
|
+
if (price > Number.MAX_SAFE_INTEGER) {
|
|
36
|
+
throw new Error("Price too large");
|
|
37
|
+
}
|
|
38
|
+
const scaledSqrtPrice = Math.sqrt(price) * DECIMAL_PRECISION_6;
|
|
39
|
+
return BigInt(Math.floor(scaledSqrtPrice)) * Q96;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// src/entities/perp-manager.ts
|
|
43
|
+
var PerpManager = class {
|
|
44
|
+
constructor(context) {
|
|
45
|
+
this.context = context;
|
|
46
|
+
}
|
|
47
|
+
// TODO: retuen a Promise<Perp> instead of the transaction hash
|
|
48
|
+
async createPerp(startingPrice, beacon) {
|
|
49
|
+
const sqrtPriceX96 = priceToSqrtPriceX96(startingPrice);
|
|
50
|
+
const { request } = await this.context.publicClient.simulateContract({
|
|
51
|
+
address: this.context.addresses.perpManager,
|
|
52
|
+
abi: this.context.abis.perpManager,
|
|
53
|
+
functionName: "createPerp",
|
|
54
|
+
args: [sqrtPriceX96, beacon],
|
|
55
|
+
account: this.context.walletClient.account
|
|
56
|
+
});
|
|
57
|
+
const hash = await this.context.walletClient.writeContract(request);
|
|
58
|
+
return hash;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// src/entities/perp.ts
|
|
63
|
+
var Perp = class {
|
|
64
|
+
};
|
|
65
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
+
0 && (module.exports = {
|
|
67
|
+
Perp,
|
|
68
|
+
PerpManager,
|
|
69
|
+
priceToSqrtPriceX96
|
|
70
|
+
});
|
|
71
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/utils/constants.ts","../src/utils/conversions.ts","../src/entities/perp-manager.ts","../src/entities/perp.ts"],"sourcesContent":["export * from './context';\nexport * from './entities';\nexport * from './utils';","export const DECIMAL_PRECISION_6: number = 1000000; // 1e6\n\nexport const Q96: bigint = 79228162514264337593543950336n; // 2^96\n","import { DECIMAL_PRECISION_6, Q96 } from \"./constants\";\n\nexport function priceToSqrtPriceX96(price: number): bigint {\n if (price > Number.MAX_SAFE_INTEGER) {\n throw new Error('Price too large');\n }\n\n const scaledSqrtPrice: number = Math.sqrt(price) * DECIMAL_PRECISION_6;\n return BigInt(Math.floor(scaledSqrtPrice)) * Q96;\n}","import { PerpCityContext } from \"../context\";\nimport { Perp } from \"./perp\";\nimport { priceToSqrtPriceX96 } from \"../utils\";\nimport type { Address } from \"viem\";\n\nexport class PerpManager {\n public readonly context: PerpCityContext;\n \n constructor(context: PerpCityContext) {\n this.context = context;\n }\n\n // TODO: retuen a Promise<Perp> instead of the transaction hash\n async createPerp(startingPrice: number, beacon: Address): Promise<`0x${string}`> {\n const sqrtPriceX96: bigint = priceToSqrtPriceX96(startingPrice);\n\n const { request } = await this.context.publicClient.simulateContract({\n address: this.context.addresses.perpManager,\n abi: this.context.abis.perpManager,\n functionName: 'createPerp',\n args: [sqrtPriceX96, beacon],\n account: this.context.walletClient.account,\n });\n\n const hash: `0x${string}` = await this.context.walletClient.writeContract(request);\n\n return hash;\n }\n}","\n\nexport class Perp {\n \n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,sBAA8B;AAEpC,IAAM,MAAc;;;ACApB,SAAS,oBAAoB,OAAuB;AACzD,MAAI,QAAQ,OAAO,kBAAkB;AACnC,UAAM,IAAI,MAAM,iBAAiB;AAAA,EACnC;AAEA,QAAM,kBAA0B,KAAK,KAAK,KAAK,IAAI;AACnD,SAAO,OAAO,KAAK,MAAM,eAAe,CAAC,IAAI;AAC/C;;;ACJO,IAAM,cAAN,MAAkB;AAAA,EAGvB,YAAY,SAA0B;AACpC,SAAK,UAAU;AAAA,EACjB;AAAA;AAAA,EAGA,MAAM,WAAW,eAAuB,QAAyC;AAC/E,UAAM,eAAuB,oBAAoB,aAAa;AAE9D,UAAM,EAAE,QAAQ,IAAI,MAAM,KAAK,QAAQ,aAAa,iBAAiB;AAAA,MACnE,SAAS,KAAK,QAAQ,UAAU;AAAA,MAChC,KAAK,KAAK,QAAQ,KAAK;AAAA,MACvB,cAAc;AAAA,MACd,MAAM,CAAC,cAAc,MAAM;AAAA,MAC3B,SAAS,KAAK,QAAQ,aAAa;AAAA,IACrC,CAAC;AAED,UAAM,OAAsB,MAAM,KAAK,QAAQ,aAAa,cAAc,OAAO;AAEjF,WAAO;AAAA,EACT;AACF;;;AC1BO,IAAM,OAAN,MAAW;AAElB;","names":[]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// src/utils/constants.ts
|
|
2
|
+
var DECIMAL_PRECISION_6 = 1e6;
|
|
3
|
+
var Q96 = 79228162514264337593543950336n;
|
|
4
|
+
|
|
5
|
+
// src/utils/conversions.ts
|
|
6
|
+
function priceToSqrtPriceX96(price) {
|
|
7
|
+
if (price > Number.MAX_SAFE_INTEGER) {
|
|
8
|
+
throw new Error("Price too large");
|
|
9
|
+
}
|
|
10
|
+
const scaledSqrtPrice = Math.sqrt(price) * DECIMAL_PRECISION_6;
|
|
11
|
+
return BigInt(Math.floor(scaledSqrtPrice)) * Q96;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// src/entities/perp-manager.ts
|
|
15
|
+
var PerpManager = class {
|
|
16
|
+
constructor(context) {
|
|
17
|
+
this.context = context;
|
|
18
|
+
}
|
|
19
|
+
// TODO: retuen a Promise<Perp> instead of the transaction hash
|
|
20
|
+
async createPerp(startingPrice, beacon) {
|
|
21
|
+
const sqrtPriceX96 = priceToSqrtPriceX96(startingPrice);
|
|
22
|
+
const { request } = await this.context.publicClient.simulateContract({
|
|
23
|
+
address: this.context.addresses.perpManager,
|
|
24
|
+
abi: this.context.abis.perpManager,
|
|
25
|
+
functionName: "createPerp",
|
|
26
|
+
args: [sqrtPriceX96, beacon],
|
|
27
|
+
account: this.context.walletClient.account
|
|
28
|
+
});
|
|
29
|
+
const hash = await this.context.walletClient.writeContract(request);
|
|
30
|
+
return hash;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// src/entities/perp.ts
|
|
35
|
+
var Perp = class {
|
|
36
|
+
};
|
|
37
|
+
export {
|
|
38
|
+
Perp,
|
|
39
|
+
PerpManager,
|
|
40
|
+
priceToSqrtPriceX96
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/constants.ts","../src/utils/conversions.ts","../src/entities/perp-manager.ts","../src/entities/perp.ts"],"sourcesContent":["export const DECIMAL_PRECISION_6: number = 1000000; // 1e6\n\nexport const Q96: bigint = 79228162514264337593543950336n; // 2^96\n","import { DECIMAL_PRECISION_6, Q96 } from \"./constants\";\n\nexport function priceToSqrtPriceX96(price: number): bigint {\n if (price > Number.MAX_SAFE_INTEGER) {\n throw new Error('Price too large');\n }\n\n const scaledSqrtPrice: number = Math.sqrt(price) * DECIMAL_PRECISION_6;\n return BigInt(Math.floor(scaledSqrtPrice)) * Q96;\n}","import { PerpCityContext } from \"../context\";\nimport { Perp } from \"./perp\";\nimport { priceToSqrtPriceX96 } from \"../utils\";\nimport type { Address } from \"viem\";\n\nexport class PerpManager {\n public readonly context: PerpCityContext;\n \n constructor(context: PerpCityContext) {\n this.context = context;\n }\n\n // TODO: retuen a Promise<Perp> instead of the transaction hash\n async createPerp(startingPrice: number, beacon: Address): Promise<`0x${string}`> {\n const sqrtPriceX96: bigint = priceToSqrtPriceX96(startingPrice);\n\n const { request } = await this.context.publicClient.simulateContract({\n address: this.context.addresses.perpManager,\n abi: this.context.abis.perpManager,\n functionName: 'createPerp',\n args: [sqrtPriceX96, beacon],\n account: this.context.walletClient.account,\n });\n\n const hash: `0x${string}` = await this.context.walletClient.writeContract(request);\n\n return hash;\n }\n}","\n\nexport class Perp {\n \n}"],"mappings":";AAAO,IAAM,sBAA8B;AAEpC,IAAM,MAAc;;;ACApB,SAAS,oBAAoB,OAAuB;AACzD,MAAI,QAAQ,OAAO,kBAAkB;AACnC,UAAM,IAAI,MAAM,iBAAiB;AAAA,EACnC;AAEA,QAAM,kBAA0B,KAAK,KAAK,KAAK,IAAI;AACnD,SAAO,OAAO,KAAK,MAAM,eAAe,CAAC,IAAI;AAC/C;;;ACJO,IAAM,cAAN,MAAkB;AAAA,EAGvB,YAAY,SAA0B;AACpC,SAAK,UAAU;AAAA,EACjB;AAAA;AAAA,EAGA,MAAM,WAAW,eAAuB,QAAyC;AAC/E,UAAM,eAAuB,oBAAoB,aAAa;AAE9D,UAAM,EAAE,QAAQ,IAAI,MAAM,KAAK,QAAQ,aAAa,iBAAiB;AAAA,MACnE,SAAS,KAAK,QAAQ,UAAU;AAAA,MAChC,KAAK,KAAK,QAAQ,KAAK;AAAA,MACvB,cAAc;AAAA,MACd,MAAM,CAAC,cAAc,MAAM;AAAA,MAC3B,SAAS,KAAK,QAAQ,aAAa;AAAA,IACrC,CAAC;AAED,UAAM,OAAsB,MAAM,KAAK,QAAQ,aAAa,cAAc,OAAO;AAEjF,WAAO;AAAA,EACT;AACF;;;AC1BO,IAAM,OAAN,MAAW;AAElB;","names":[]}
|
package/package.json
CHANGED