@zga/client 0.0.0-stage → 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.
Files changed (71) hide show
  1. package/LICENSE +21 -0
  2. package/dist/addresses.d.ts +29 -0
  3. package/dist/addresses.js +43 -0
  4. package/dist/billing.d.ts +41 -0
  5. package/dist/billing.js +141 -0
  6. package/dist/bin/crank.d.ts +2 -0
  7. package/dist/bin/crank.js +34 -0
  8. package/dist/bin/relayer.d.ts +2 -0
  9. package/dist/bin/relayer.js +37 -0
  10. package/dist/chain.d.ts +14 -0
  11. package/dist/chain.js +48 -0
  12. package/dist/config.d.ts +11 -0
  13. package/dist/config.js +61 -0
  14. package/dist/crank/gate.d.ts +2 -0
  15. package/dist/crank/gate.js +26 -0
  16. package/dist/crank/lending.d.ts +16 -0
  17. package/dist/crank/lending.js +144 -0
  18. package/dist/crank/prices.d.ts +11 -0
  19. package/dist/crank/prices.js +177 -0
  20. package/dist/crank/runner.d.ts +15 -0
  21. package/dist/crank/runner.js +30 -0
  22. package/dist/crank/shieldFees.d.ts +15 -0
  23. package/dist/crank/shieldFees.js +161 -0
  24. package/dist/epoch-root.d.ts +23 -0
  25. package/dist/epoch-root.js +98 -0
  26. package/dist/explorer.d.ts +41 -0
  27. package/dist/explorer.js +222 -0
  28. package/dist/gossip.d.ts +4 -0
  29. package/dist/gossip.js +77 -0
  30. package/dist/idl.d.ts +2 -0
  31. package/dist/idl.js +52 -0
  32. package/dist/index.d.ts +31 -0
  33. package/dist/index.js +47 -0
  34. package/dist/lending.d.ts +82 -0
  35. package/dist/lending.js +164 -0
  36. package/dist/log.d.ts +27 -0
  37. package/dist/log.js +173 -0
  38. package/dist/lookupTable.d.ts +2 -0
  39. package/dist/lookupTable.js +47 -0
  40. package/dist/observer.d.ts +59 -0
  41. package/dist/observer.js +255 -0
  42. package/dist/receipt.d.ts +30 -0
  43. package/dist/receipt.js +27 -0
  44. package/dist/relayer/chain.d.ts +35 -0
  45. package/dist/relayer/chain.js +171 -0
  46. package/dist/relayer/errors.d.ts +8 -0
  47. package/dist/relayer/errors.js +29 -0
  48. package/dist/relayer/limits.d.ts +15 -0
  49. package/dist/relayer/limits.js +47 -0
  50. package/dist/relayer/relayer.d.ts +25 -0
  51. package/dist/relayer/relayer.js +54 -0
  52. package/dist/relayer/server.d.ts +8 -0
  53. package/dist/relayer/server.js +101 -0
  54. package/dist/relayer/settings.d.ts +23 -0
  55. package/dist/relayer/settings.js +69 -0
  56. package/dist/replay.d.ts +13 -0
  57. package/dist/replay.js +118 -0
  58. package/dist/session.d.ts +29 -0
  59. package/dist/session.js +31 -0
  60. package/dist/settlement.d.ts +17 -0
  61. package/dist/settlement.js +96 -0
  62. package/dist/sha256.d.ts +3 -0
  63. package/dist/sha256.js +83 -0
  64. package/dist/shieldLimits.d.ts +15 -0
  65. package/dist/shieldLimits.js +24 -0
  66. package/dist/signer.d.ts +5 -0
  67. package/dist/signer.js +43 -0
  68. package/dist/token.d.ts +6 -0
  69. package/dist/token.js +33 -0
  70. package/package.json +36 -4
  71. package/README.md +0 -3
@@ -0,0 +1,15 @@
1
+ export declare const SHIELD_EPOCH_SLOTS = 648000n;
2
+ export interface ShieldGateConfig {
3
+ minZgaMarketCapUsd: any;
4
+ marketCapMetSinceEpoch: any;
5
+ marketCapSustainEpochs: any;
6
+ globalZgaEpochInitialized: any;
7
+ globalZgaEpochStartSlot: any;
8
+ }
9
+ export declare function shieldGateOpen(config: ShieldGateConfig, slot: number | bigint): boolean;
10
+ export interface EffectiveShieldLimits {
11
+ effectiveCeiling: string;
12
+ effectiveDailyCap: string;
13
+ limitsScaled: boolean;
14
+ }
15
+ export declare function effectiveShieldLimits(assetId: number, ceiling: any, dailyCap: any, gateOpen: boolean): EffectiveShieldLimits;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SHIELD_EPOCH_SLOTS = void 0;
4
+ exports.shieldGateOpen = shieldGateOpen;
5
+ exports.effectiveShieldLimits = effectiveShieldLimits;
6
+ exports.SHIELD_EPOCH_SLOTS = 648000n;
7
+ const BPS = 10000n;
8
+ const BELOW_GATE_BPS = { 0: 3300n, 1: 2000n };
9
+ const big = (x) => BigInt(x.toString());
10
+ function shieldGateOpen(config, slot) {
11
+ if (big(config.minZgaMarketCapUsd) === 0n)
12
+ return true;
13
+ const start = big(config.globalZgaEpochStartSlot);
14
+ const now = BigInt(slot);
15
+ const epoch = config.globalZgaEpochInitialized ? (now > start ? now - start : 0n) / exports.SHIELD_EPOCH_SLOTS : 0n;
16
+ const since = big(config.marketCapMetSinceEpoch);
17
+ return since !== 0n && epoch >= since + big(config.marketCapSustainEpochs);
18
+ }
19
+ function effectiveShieldLimits(assetId, ceiling, dailyCap, gateOpen) {
20
+ const fraction = BELOW_GATE_BPS[assetId];
21
+ const scaled = !gateOpen && fraction !== undefined;
22
+ const take = (value) => (scaled ? (value * fraction) / BPS : value);
23
+ return { effectiveCeiling: take(big(ceiling)).toString(), effectiveDailyCap: take(big(dailyCap)).toString(), limitsScaled: scaled };
24
+ }
@@ -0,0 +1,5 @@
1
+ export interface EnclaveSigner {
2
+ publicKey: Uint8Array;
3
+ sign(message: Uint8Array): Uint8Array | Promise<Uint8Array>;
4
+ }
5
+ export declare function keypairSigner(seedOrSecret: Uint8Array): EnclaveSigner;
package/dist/signer.js ADDED
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.keypairSigner = keypairSigner;
37
+ const nacl = __importStar(require("tweetnacl"));
38
+ function keypairSigner(seedOrSecret) {
39
+ const kp = seedOrSecret.length === 32
40
+ ? nacl.sign.keyPair.fromSeed(seedOrSecret)
41
+ : nacl.sign.keyPair.fromSecretKey(seedOrSecret);
42
+ return { publicKey: kp.publicKey, sign: (message) => nacl.sign.detached(message, kp.secretKey) };
43
+ }
@@ -0,0 +1,6 @@
1
+ import { Connection, Keypair, PublicKey, TransactionInstruction } from '@solana/web3.js';
2
+ export declare const TOKEN_PROGRAM_ID: PublicKey;
3
+ export declare const ASSOCIATED_TOKEN_PROGRAM_ID: PublicKey;
4
+ export declare function associatedTokenAddress(mint: PublicKey, owner: PublicKey): PublicKey;
5
+ export declare function createAssociatedTokenAccountIdempotent(payer: PublicKey, owner: PublicKey, mint: PublicKey): TransactionInstruction;
6
+ export declare function ensureAssociatedTokenAccount(connection: Connection, payer: Keypair, owner: PublicKey, mint: PublicKey): Promise<PublicKey>;
package/dist/token.js ADDED
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ASSOCIATED_TOKEN_PROGRAM_ID = exports.TOKEN_PROGRAM_ID = void 0;
4
+ exports.associatedTokenAddress = associatedTokenAddress;
5
+ exports.createAssociatedTokenAccountIdempotent = createAssociatedTokenAccountIdempotent;
6
+ exports.ensureAssociatedTokenAccount = ensureAssociatedTokenAccount;
7
+ const web3_js_1 = require("@solana/web3.js");
8
+ exports.TOKEN_PROGRAM_ID = new web3_js_1.PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA');
9
+ exports.ASSOCIATED_TOKEN_PROGRAM_ID = new web3_js_1.PublicKey('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL');
10
+ function associatedTokenAddress(mint, owner) {
11
+ return web3_js_1.PublicKey.findProgramAddressSync([owner.toBytes(), exports.TOKEN_PROGRAM_ID.toBytes(), mint.toBytes()], exports.ASSOCIATED_TOKEN_PROGRAM_ID)[0];
12
+ }
13
+ function createAssociatedTokenAccountIdempotent(payer, owner, mint) {
14
+ return new web3_js_1.TransactionInstruction({
15
+ programId: exports.ASSOCIATED_TOKEN_PROGRAM_ID,
16
+ keys: [
17
+ { pubkey: payer, isSigner: true, isWritable: true },
18
+ { pubkey: associatedTokenAddress(mint, owner), isSigner: false, isWritable: true },
19
+ { pubkey: owner, isSigner: false, isWritable: false },
20
+ { pubkey: mint, isSigner: false, isWritable: false },
21
+ { pubkey: web3_js_1.SystemProgram.programId, isSigner: false, isWritable: false },
22
+ { pubkey: exports.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
23
+ ],
24
+ data: Buffer.from([1]),
25
+ });
26
+ }
27
+ async function ensureAssociatedTokenAccount(connection, payer, owner, mint) {
28
+ const address = associatedTokenAddress(mint, owner);
29
+ if (!(await connection.getAccountInfo(address))) {
30
+ await (0, web3_js_1.sendAndConfirmTransaction)(connection, new web3_js_1.Transaction().add(createAssociatedTokenAccountIdempotent(payer.publicKey, owner, mint)), [payer]);
31
+ }
32
+ return address;
33
+ }
package/package.json CHANGED
@@ -1,6 +1,38 @@
1
1
  {
2
2
  "name": "@zga/client",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "files": [
5
+ "dist"
6
+ ],
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "bin": {
10
+ "zga-crank": "dist/bin/crank.js",
11
+ "zga-relayer": "dist/bin/relayer.js"
12
+ },
13
+ "scripts": {
14
+ "build": "tsc -p tsconfig.json",
15
+ "test": "node --test test/*.test.mjs"
16
+ },
17
+ "dependencies": {
18
+ "@zga/shielded-sdk": "0.1.1",
19
+ "tweetnacl": "^1.0.3"
20
+ },
21
+ "peerDependencies": {
22
+ "@coral-xyz/anchor": ">=0.31.0 <1",
23
+ "@solana/web3.js": "^1.98.0"
24
+ },
25
+ "devDependencies": {
26
+ "@coral-xyz/anchor": "^0.31.0",
27
+ "@solana/web3.js": "^1.98.4",
28
+ "@types/node": "^20.0.0",
29
+ "typescript": "^5.4.0",
30
+ "wabt": "^1.0.39"
31
+ },
32
+ "license": "MIT",
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "https://gitlab.com/zga/zga-network-v2.git",
36
+ "directory": "packages/client"
37
+ }
38
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.