Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create walrus sdk #6

Merged
merged 6 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/witty-ducks-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@mysten/sui': minor
---

expose isArgument util from @mysten/sui/transactions
2 changes: 2 additions & 0 deletions packages/typescript/src/transactions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,5 @@ export {
} from './plugins/NamedPackagesPlugin.js';

export { type NamedPackagesPluginCache } from './plugins/utils.js';

export { isArgument } from './utils.js';
7 changes: 7 additions & 0 deletions packages/typescript/src/transactions/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { is } from 'valibot';

import type { SuiMoveNormalizedType } from '../client/index.js';
import { normalizeSuiAddress } from '../utils/sui-types.js';
import { Argument } from './data/internal.js';
import type { CallArg } from './data/internal.js';

export function extractMutableReference(
Expand Down Expand Up @@ -64,3 +67,7 @@ export function getIdFromCallArg(arg: string | CallArg) {

return undefined;
}

export function isArgument(value: unknown): value is Argument {
return is(Argument, value);
}
2 changes: 2 additions & 0 deletions packages/walrus/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CHANGELOG.md
dist/
1 change: 1 addition & 0 deletions packages/walrus/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# `@mysten/walrus`
52 changes: 52 additions & 0 deletions packages/walrus/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "@mysten/walrus",
"version": "0.0.0",
"private": true,
"description": "Walrus SDK",
"license": "Apache-2.0",
"author": "Mysten Labs <build@mystenlabs.com>",
"type": "commonjs",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/cjs/index.d.ts",
"exports": {
".": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js"
}
},
"sideEffects": false,
"files": [
"CHANGELOG.md",
"dist"
],
"scripts": {
"clean": "rm -rf tsconfig.tsbuildinfo ./dist",
"build": "build-package",
"prepublishOnly": "pnpm build",
"prettier:check": "prettier -c --ignore-unknown .",
"prettier:fix": "prettier -w --ignore-unknown .",
"eslint:check": "eslint --max-warnings=0 .",
"eslint:fix": "pnpm run eslint:check --fix",
"lint": "pnpm run eslint:check && pnpm run prettier:check",
"lint:fix": "pnpm run eslint:fix && pnpm run prettier:fix"
},
"repository": {
"type": "git",
"url": "git+https://github.com/mystenlabs/ts-sdks.git"
},
"bugs": {
"url": "https://github.com/mystenlabs/ts-sdks/issues"
},
"homepage": "https://github.com/mystenlabs/ts-sdks#readme",
"devDependencies": {
"@mysten/build-scripts": "workspace:*",
"@types/node": "^22.10.5",
"typescript": "^5.7.2",
"vitest": "^2.1.8"
},
"dependencies": {
"@mysten/bcs": "workspace:*",
"@mysten/sui": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { bcs } from '@mysten/sui/bcs';

export function String() {
return bcs.struct('String', {
bytes: bcs.vector(bcs.u8()),
});
}
export function Char() {
return bcs.struct('Char', {
byte: bcs.u8(),
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { bcs } from '@mysten/sui/bcs';

export function BitVector() {
return bcs.struct('BitVector', {
length: bcs.u64(),
bit_field: bcs.vector(bcs.bool()),
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { bcs } from '@mysten/sui/bcs';

export function FixedPoint32() {
return bcs.struct('FixedPoint32', {
value: bcs.u64(),
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import { bcs } from '@mysten/sui/bcs';
import type { BcsType } from '@mysten/sui/bcs';

export function Option<T0 extends BcsType<any>>(...typeParameters: [T0]) {
return bcs.struct('Option', {
vec: bcs.vector(typeParameters[0]),
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import { bcs } from '@mysten/sui/bcs';

export function String() {
return bcs.struct('String', {
bytes: bcs.vector(bcs.u8()),
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import { bcs } from '@mysten/sui/bcs';

export function TypeName() {
return bcs.struct('TypeName', {
name: bcs.string(),
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import { bcs } from '@mysten/sui/bcs';

export function UQ32_32() {
return bcs.struct('UQ32_32', {
pos0: bcs.u64(),
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import { bcs } from '@mysten/sui/bcs';

export function UQ64_64() {
return bcs.struct('UQ64_64', {
pos0: bcs.u128(),
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import { bcs } from '@mysten/sui/bcs';

import * as object from './object.js';

export function AuthenticatorState() {
return bcs.struct('AuthenticatorState', {
id: object.UID(),
version: bcs.u64(),
});
}
export function AuthenticatorStateInner() {
return bcs.struct('AuthenticatorStateInner', {
version: bcs.u64(),
active_jwks: bcs.vector(ActiveJwk()),
});
}
export function JWK() {
return bcs.struct('JWK', {
kty: bcs.string(),
e: bcs.string(),
n: bcs.string(),
alg: bcs.string(),
});
}
export function JwkId() {
return bcs.struct('JwkId', {
iss: bcs.string(),
kid: bcs.string(),
});
}
export function ActiveJwk() {
return bcs.struct('ActiveJwk', {
jwk_id: JwkId(),
jwk: JWK(),
epoch: bcs.u64(),
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import { bcs } from '@mysten/sui/bcs';

import * as object from './object.js';

export function Bag() {
return bcs.struct('Bag', {
id: object.UID(),
size: bcs.u64(),
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import { bcs } from '@mysten/sui/bcs';

export function Supply() {
return bcs.struct('Supply', {
value: bcs.u64(),
});
}
export function Balance() {
return bcs.struct('Balance', {
value: bcs.u64(),
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import { bcs } from '@mysten/sui/bcs';

export function BCS() {
return bcs.struct('BCS', {
bytes: bcs.vector(bcs.u8()),
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import { bcs } from '@mysten/sui/bcs';

export function Scalar() {
return bcs.struct('Scalar', {
dummy_field: bcs.bool(),
});
}
export function G1() {
return bcs.struct('G1', {
dummy_field: bcs.bool(),
});
}
export function G2() {
return bcs.struct('G2', {
dummy_field: bcs.bool(),
});
}
export function GT() {
return bcs.struct('GT', {
dummy_field: bcs.bool(),
});
}
export function UncompressedG1() {
return bcs.struct('UncompressedG1', {
dummy_field: bcs.bool(),
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import { bcs } from '@mysten/sui/bcs';
import type { BcsType } from '@mysten/sui/bcs';

export function Referent<T0 extends BcsType<any>>(...typeParameters: [T0]) {
return bcs.struct('Referent', {
id: bcs.Address,
value: bcs.option(typeParameters[0]),
});
}
export function Borrow() {
return bcs.struct('Borrow', {
ref: bcs.Address,
obj: bcs.Address,
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import { bcs } from '@mysten/sui/bcs';

import * as object from './object.js';

export function Clock() {
return bcs.struct('Clock', {
id: object.UID(),
timestamp_ms: bcs.u64(),
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import { bcs } from '@mysten/sui/bcs';

import * as balance from './balance.js';
import * as object from './object.js';
import * as url from './url.js';

export function Coin() {
return bcs.struct('Coin', {
id: object.UID(),
balance: balance.Balance(),
});
}
export function CoinMetadata() {
return bcs.struct('CoinMetadata', {
id: object.UID(),
decimals: bcs.u8(),
name: bcs.string(),
symbol: bcs.string(),
description: bcs.string(),
icon_url: bcs.option(url.Url()),
});
}
export function RegulatedCoinMetadata() {
return bcs.struct('RegulatedCoinMetadata', {
id: object.UID(),
coin_metadata_object: bcs.Address,
deny_cap_object: bcs.Address,
});
}
export function TreasuryCap() {
return bcs.struct('TreasuryCap', {
id: object.UID(),
total_supply: balance.Supply(),
});
}
export function DenyCapV2() {
return bcs.struct('DenyCapV2', {
id: object.UID(),
allow_global_pause: bcs.bool(),
});
}
export function CurrencyCreated() {
return bcs.struct('CurrencyCreated', {
decimals: bcs.u8(),
});
}
export function DenyCap() {
return bcs.struct('DenyCap', {
id: object.UID(),
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import { bcs } from '@mysten/sui/bcs';
import type { BcsType } from '@mysten/sui/bcs';

import * as object from './object.js';

export function Config() {
return bcs.struct('Config', {
id: object.UID(),
});
}
export function Setting<T0 extends BcsType<any>>(...typeParameters: [T0]) {
return bcs.struct('Setting', {
data: bcs.option(SettingData(typeParameters[0])),
});
}
export function SettingData<T0 extends BcsType<any>>(...typeParameters: [T0]) {
return bcs.struct('SettingData', {
newer_value_epoch: bcs.u64(),
newer_value: bcs.option(typeParameters[0]),
older_value_opt: bcs.option(typeParameters[0]),
});
}
Loading
Loading