@waterx/sdk 3.0.3 → 3.1.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/cjs/src/prediction/client.d.ts +11 -0
- package/dist/cjs/src/prediction/client.js +16 -0
- package/dist/cjs/src/prediction/gift.d.ts +19 -0
- package/dist/cjs/src/prediction/gift.js +26 -1
- package/dist/src/prediction/client.d.ts +11 -0
- package/dist/src/prediction/client.js +16 -0
- package/dist/src/prediction/gift.d.ts +19 -0
- package/dist/src/prediction/gift.js +26 -1
- package/package.json +1 -1
|
@@ -40,6 +40,17 @@ export declare class PredictClient extends BaseLineClient<WaterxPredictionConfig
|
|
|
40
40
|
waterxAccountAdminCap(): string;
|
|
41
41
|
waterxPredictionGiftPackageId(): string;
|
|
42
42
|
claimableLinkConfigId(): string;
|
|
43
|
+
/**
|
|
44
|
+
* Original (first-published) id of the gift package. Used ONLY for the
|
|
45
|
+
* `GiftKey` type tag in derived-object address computation
|
|
46
|
+
* (`deriveGiftAddress`). Sui pins a struct's type identity to its
|
|
47
|
+
* defining package's *original* id — it never advances across upgrades,
|
|
48
|
+
* unlike `published_at`. So the off-chain `gift_id` derivation must key
|
|
49
|
+
* on this, or it diverges from the on-chain `derive_gift_address` after
|
|
50
|
+
* the first upgrade. Falls back to `published_at` when `original_id` is
|
|
51
|
+
* absent (fresh deployments where the two are equal).
|
|
52
|
+
*/
|
|
53
|
+
waterxPredictionGiftTypeOriginId(): string;
|
|
43
54
|
waterxReferralPackageId(): string;
|
|
44
55
|
referralTableId(): string;
|
|
45
56
|
}
|
|
@@ -71,6 +71,22 @@ class PredictClient extends base_client_ts_1.BaseLineClient {
|
|
|
71
71
|
claimableLinkConfigId() {
|
|
72
72
|
return requireConfigValue(this.config.packages.waterx_prediction_gift, "claimable_link_config", "packages.waterx_prediction_gift.claimable_link_config");
|
|
73
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Original (first-published) id of the gift package. Used ONLY for the
|
|
76
|
+
* `GiftKey` type tag in derived-object address computation
|
|
77
|
+
* (`deriveGiftAddress`). Sui pins a struct's type identity to its
|
|
78
|
+
* defining package's *original* id — it never advances across upgrades,
|
|
79
|
+
* unlike `published_at`. So the off-chain `gift_id` derivation must key
|
|
80
|
+
* on this, or it diverges from the on-chain `derive_gift_address` after
|
|
81
|
+
* the first upgrade. Falls back to `published_at` when `original_id` is
|
|
82
|
+
* absent (fresh deployments where the two are equal).
|
|
83
|
+
*/
|
|
84
|
+
waterxPredictionGiftTypeOriginId() {
|
|
85
|
+
const origin = this.config.packages.waterx_prediction_gift?.original_id;
|
|
86
|
+
return typeof origin === "string" && origin.length > 0
|
|
87
|
+
? origin
|
|
88
|
+
: this.waterxPredictionGiftPackageId();
|
|
89
|
+
}
|
|
74
90
|
waterxReferralPackageId() {
|
|
75
91
|
return requireConfigValue(this.config.packages.waterx_referral, "published_at", "packages.waterx_referral.published_at");
|
|
76
92
|
}
|
|
@@ -25,6 +25,16 @@ import type { AccountIdentityParams, IdArgument, Selection } from "./types.ts";
|
|
|
25
25
|
export interface GiftBaseParams {
|
|
26
26
|
/** `waterx_prediction_gift` package id. Defaults to `client.waterxPredictionGiftPackageId()`. */
|
|
27
27
|
giftPackageId?: string;
|
|
28
|
+
/**
|
|
29
|
+
* `waterx_prediction_gift` *original* (first-published) package id, used
|
|
30
|
+
* ONLY for the `GiftKey` type tag in {@link deriveGiftAddress}. Defaults to
|
|
31
|
+
* `client.waterxPredictionGiftTypeOriginId()` (config `original_id`, falling
|
|
32
|
+
* back to `giftPackageId`/`published_at`). Distinct from `giftPackageId`,
|
|
33
|
+
* which selects the *runtime* package for moveCall targets — after a package
|
|
34
|
+
* upgrade the two diverge, and only the original id reproduces the on-chain
|
|
35
|
+
* `gift_id`. Override only for offline derivation against a custom deploy.
|
|
36
|
+
*/
|
|
37
|
+
giftTypeOriginId?: string;
|
|
28
38
|
/** `ClaimableLinkConfig` object id. Defaults to `client.claimableLinkConfigId()`. */
|
|
29
39
|
claimableLinkConfig?: string;
|
|
30
40
|
/** Collateral / settlement coin type for the position's `Gift<T>`. Defaults to `client.settlementCoinType()`. */
|
|
@@ -72,6 +82,15 @@ export declare function signGiftClaim(giftKeypair: Ed25519Keypair, giftId: strin
|
|
|
72
82
|
/**
|
|
73
83
|
* Compute the `gift_id` that `create_gift` will produce for the given
|
|
74
84
|
* pubkey, offline. No RPC. Mirrors `claimable_link::derive_gift_address`.
|
|
85
|
+
*
|
|
86
|
+
* The `GiftKey` type tag is keyed on the gift package's *original* id
|
|
87
|
+
* (via {@link resolveGiftTypeOriginId}), NOT `published_at`. On Sui a
|
|
88
|
+
* struct's type identity stays pinned to its defining package's original
|
|
89
|
+
* id and never advances across upgrades, so `derive_gift_address`
|
|
90
|
+
* hashes `GiftKey` under that original id. Using `published_at` here would
|
|
91
|
+
* silently diverge from the chain after the first package upgrade, yielding
|
|
92
|
+
* the wrong `gift_id` for every gift. The moveCall targets elsewhere in
|
|
93
|
+
* this module correctly stay on `published_at` (latest code).
|
|
75
94
|
*/
|
|
76
95
|
export declare function deriveGiftAddress(client: PredictClient, pubkey: Uint8Array, params?: GiftBaseParams): string;
|
|
77
96
|
export interface CreateGiftParams extends GiftBaseParams, GiftReferralParams, AccountIdentityParams {
|
|
@@ -54,6 +54,22 @@ function resolveGiftPackageId(client, override) {
|
|
|
54
54
|
? client.waterxPredictionGiftPackageId()
|
|
55
55
|
: override;
|
|
56
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Resolve the package id for the `GiftKey` type tag in
|
|
59
|
+
* {@link deriveGiftAddress}. Precedence: explicit `giftTypeOriginId`, then
|
|
60
|
+
* the runtime `giftPackageId` override (a self-contained deploy where
|
|
61
|
+
* original == published), then the client's config `original_id` (falling
|
|
62
|
+
* back to `published_at`). This must key on the *original* id so the
|
|
63
|
+
* off-chain derivation matches the on-chain type identity, which never
|
|
64
|
+
* advances across package upgrades.
|
|
65
|
+
*/
|
|
66
|
+
function resolveGiftTypeOriginId(client, originOverride, pkgOverride) {
|
|
67
|
+
if (originOverride !== undefined && originOverride !== "")
|
|
68
|
+
return originOverride;
|
|
69
|
+
if (pkgOverride !== undefined && pkgOverride !== "")
|
|
70
|
+
return pkgOverride;
|
|
71
|
+
return client.waterxPredictionGiftTypeOriginId();
|
|
72
|
+
}
|
|
57
73
|
function resolveClaimableLinkConfig(client, override) {
|
|
58
74
|
return override === undefined || override === "" ? client.claimableLinkConfigId() : override;
|
|
59
75
|
}
|
|
@@ -167,12 +183,21 @@ const GiftKeyBcs = bcs_1.bcs.struct("GiftKey", {
|
|
|
167
183
|
/**
|
|
168
184
|
* Compute the `gift_id` that `create_gift` will produce for the given
|
|
169
185
|
* pubkey, offline. No RPC. Mirrors `claimable_link::derive_gift_address`.
|
|
186
|
+
*
|
|
187
|
+
* The `GiftKey` type tag is keyed on the gift package's *original* id
|
|
188
|
+
* (via {@link resolveGiftTypeOriginId}), NOT `published_at`. On Sui a
|
|
189
|
+
* struct's type identity stays pinned to its defining package's original
|
|
190
|
+
* id and never advances across upgrades, so `derive_gift_address`
|
|
191
|
+
* hashes `GiftKey` under that original id. Using `published_at` here would
|
|
192
|
+
* silently diverge from the chain after the first package upgrade, yielding
|
|
193
|
+
* the wrong `gift_id` for every gift. The moveCall targets elsewhere in
|
|
194
|
+
* this module correctly stay on `published_at` (latest code).
|
|
170
195
|
*/
|
|
171
196
|
function deriveGiftAddress(client, pubkey, params = {}) {
|
|
172
197
|
if (pubkey.length !== constants_ts_1.GIFT_PUBKEY_LEN) {
|
|
173
198
|
throw new Error(`Gift pubkey must be ${constants_ts_1.GIFT_PUBKEY_LEN} bytes, got ${pubkey.length}`);
|
|
174
199
|
}
|
|
175
|
-
const giftPkg =
|
|
200
|
+
const giftPkg = resolveGiftTypeOriginId(client, params.giftTypeOriginId, params.giftPackageId);
|
|
176
201
|
const configId = resolveClaimableLinkConfig(client, params.claimableLinkConfig);
|
|
177
202
|
const keyBytes = GiftKeyBcs.serialize({ pubkey: Array.from(pubkey) }).toBytes();
|
|
178
203
|
return (0, utils_1.deriveObjectID)(configId, `${giftPkg}::claimable_link::GiftKey`, keyBytes);
|
|
@@ -40,6 +40,17 @@ export declare class PredictClient extends BaseLineClient<WaterxPredictionConfig
|
|
|
40
40
|
waterxAccountAdminCap(): string;
|
|
41
41
|
waterxPredictionGiftPackageId(): string;
|
|
42
42
|
claimableLinkConfigId(): string;
|
|
43
|
+
/**
|
|
44
|
+
* Original (first-published) id of the gift package. Used ONLY for the
|
|
45
|
+
* `GiftKey` type tag in derived-object address computation
|
|
46
|
+
* (`deriveGiftAddress`). Sui pins a struct's type identity to its
|
|
47
|
+
* defining package's *original* id — it never advances across upgrades,
|
|
48
|
+
* unlike `published_at`. So the off-chain `gift_id` derivation must key
|
|
49
|
+
* on this, or it diverges from the on-chain `derive_gift_address` after
|
|
50
|
+
* the first upgrade. Falls back to `published_at` when `original_id` is
|
|
51
|
+
* absent (fresh deployments where the two are equal).
|
|
52
|
+
*/
|
|
53
|
+
waterxPredictionGiftTypeOriginId(): string;
|
|
43
54
|
waterxReferralPackageId(): string;
|
|
44
55
|
referralTableId(): string;
|
|
45
56
|
}
|
|
@@ -68,6 +68,22 @@ export class PredictClient extends BaseLineClient {
|
|
|
68
68
|
claimableLinkConfigId() {
|
|
69
69
|
return requireConfigValue(this.config.packages.waterx_prediction_gift, "claimable_link_config", "packages.waterx_prediction_gift.claimable_link_config");
|
|
70
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Original (first-published) id of the gift package. Used ONLY for the
|
|
73
|
+
* `GiftKey` type tag in derived-object address computation
|
|
74
|
+
* (`deriveGiftAddress`). Sui pins a struct's type identity to its
|
|
75
|
+
* defining package's *original* id — it never advances across upgrades,
|
|
76
|
+
* unlike `published_at`. So the off-chain `gift_id` derivation must key
|
|
77
|
+
* on this, or it diverges from the on-chain `derive_gift_address` after
|
|
78
|
+
* the first upgrade. Falls back to `published_at` when `original_id` is
|
|
79
|
+
* absent (fresh deployments where the two are equal).
|
|
80
|
+
*/
|
|
81
|
+
waterxPredictionGiftTypeOriginId() {
|
|
82
|
+
const origin = this.config.packages.waterx_prediction_gift?.original_id;
|
|
83
|
+
return typeof origin === "string" && origin.length > 0
|
|
84
|
+
? origin
|
|
85
|
+
: this.waterxPredictionGiftPackageId();
|
|
86
|
+
}
|
|
71
87
|
waterxReferralPackageId() {
|
|
72
88
|
return requireConfigValue(this.config.packages.waterx_referral, "published_at", "packages.waterx_referral.published_at");
|
|
73
89
|
}
|
|
@@ -25,6 +25,16 @@ import type { AccountIdentityParams, IdArgument, Selection } from "./types.ts";
|
|
|
25
25
|
export interface GiftBaseParams {
|
|
26
26
|
/** `waterx_prediction_gift` package id. Defaults to `client.waterxPredictionGiftPackageId()`. */
|
|
27
27
|
giftPackageId?: string;
|
|
28
|
+
/**
|
|
29
|
+
* `waterx_prediction_gift` *original* (first-published) package id, used
|
|
30
|
+
* ONLY for the `GiftKey` type tag in {@link deriveGiftAddress}. Defaults to
|
|
31
|
+
* `client.waterxPredictionGiftTypeOriginId()` (config `original_id`, falling
|
|
32
|
+
* back to `giftPackageId`/`published_at`). Distinct from `giftPackageId`,
|
|
33
|
+
* which selects the *runtime* package for moveCall targets — after a package
|
|
34
|
+
* upgrade the two diverge, and only the original id reproduces the on-chain
|
|
35
|
+
* `gift_id`. Override only for offline derivation against a custom deploy.
|
|
36
|
+
*/
|
|
37
|
+
giftTypeOriginId?: string;
|
|
28
38
|
/** `ClaimableLinkConfig` object id. Defaults to `client.claimableLinkConfigId()`. */
|
|
29
39
|
claimableLinkConfig?: string;
|
|
30
40
|
/** Collateral / settlement coin type for the position's `Gift<T>`. Defaults to `client.settlementCoinType()`. */
|
|
@@ -72,6 +82,15 @@ export declare function signGiftClaim(giftKeypair: Ed25519Keypair, giftId: strin
|
|
|
72
82
|
/**
|
|
73
83
|
* Compute the `gift_id` that `create_gift` will produce for the given
|
|
74
84
|
* pubkey, offline. No RPC. Mirrors `claimable_link::derive_gift_address`.
|
|
85
|
+
*
|
|
86
|
+
* The `GiftKey` type tag is keyed on the gift package's *original* id
|
|
87
|
+
* (via {@link resolveGiftTypeOriginId}), NOT `published_at`. On Sui a
|
|
88
|
+
* struct's type identity stays pinned to its defining package's original
|
|
89
|
+
* id and never advances across upgrades, so `derive_gift_address`
|
|
90
|
+
* hashes `GiftKey` under that original id. Using `published_at` here would
|
|
91
|
+
* silently diverge from the chain after the first package upgrade, yielding
|
|
92
|
+
* the wrong `gift_id` for every gift. The moveCall targets elsewhere in
|
|
93
|
+
* this module correctly stay on `published_at` (latest code).
|
|
75
94
|
*/
|
|
76
95
|
export declare function deriveGiftAddress(client: PredictClient, pubkey: Uint8Array, params?: GiftBaseParams): string;
|
|
77
96
|
export interface CreateGiftParams extends GiftBaseParams, GiftReferralParams, AccountIdentityParams {
|
|
@@ -32,6 +32,22 @@ function resolveGiftPackageId(client, override) {
|
|
|
32
32
|
? client.waterxPredictionGiftPackageId()
|
|
33
33
|
: override;
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Resolve the package id for the `GiftKey` type tag in
|
|
37
|
+
* {@link deriveGiftAddress}. Precedence: explicit `giftTypeOriginId`, then
|
|
38
|
+
* the runtime `giftPackageId` override (a self-contained deploy where
|
|
39
|
+
* original == published), then the client's config `original_id` (falling
|
|
40
|
+
* back to `published_at`). This must key on the *original* id so the
|
|
41
|
+
* off-chain derivation matches the on-chain type identity, which never
|
|
42
|
+
* advances across package upgrades.
|
|
43
|
+
*/
|
|
44
|
+
function resolveGiftTypeOriginId(client, originOverride, pkgOverride) {
|
|
45
|
+
if (originOverride !== undefined && originOverride !== "")
|
|
46
|
+
return originOverride;
|
|
47
|
+
if (pkgOverride !== undefined && pkgOverride !== "")
|
|
48
|
+
return pkgOverride;
|
|
49
|
+
return client.waterxPredictionGiftTypeOriginId();
|
|
50
|
+
}
|
|
35
51
|
function resolveClaimableLinkConfig(client, override) {
|
|
36
52
|
return override === undefined || override === "" ? client.claimableLinkConfigId() : override;
|
|
37
53
|
}
|
|
@@ -145,12 +161,21 @@ const GiftKeyBcs = bcs.struct("GiftKey", {
|
|
|
145
161
|
/**
|
|
146
162
|
* Compute the `gift_id` that `create_gift` will produce for the given
|
|
147
163
|
* pubkey, offline. No RPC. Mirrors `claimable_link::derive_gift_address`.
|
|
164
|
+
*
|
|
165
|
+
* The `GiftKey` type tag is keyed on the gift package's *original* id
|
|
166
|
+
* (via {@link resolveGiftTypeOriginId}), NOT `published_at`. On Sui a
|
|
167
|
+
* struct's type identity stays pinned to its defining package's original
|
|
168
|
+
* id and never advances across upgrades, so `derive_gift_address`
|
|
169
|
+
* hashes `GiftKey` under that original id. Using `published_at` here would
|
|
170
|
+
* silently diverge from the chain after the first package upgrade, yielding
|
|
171
|
+
* the wrong `gift_id` for every gift. The moveCall targets elsewhere in
|
|
172
|
+
* this module correctly stay on `published_at` (latest code).
|
|
148
173
|
*/
|
|
149
174
|
export function deriveGiftAddress(client, pubkey, params = {}) {
|
|
150
175
|
if (pubkey.length !== GIFT_PUBKEY_LEN) {
|
|
151
176
|
throw new Error(`Gift pubkey must be ${GIFT_PUBKEY_LEN} bytes, got ${pubkey.length}`);
|
|
152
177
|
}
|
|
153
|
-
const giftPkg =
|
|
178
|
+
const giftPkg = resolveGiftTypeOriginId(client, params.giftTypeOriginId, params.giftPackageId);
|
|
154
179
|
const configId = resolveClaimableLinkConfig(client, params.claimableLinkConfig);
|
|
155
180
|
const keyBytes = GiftKeyBcs.serialize({ pubkey: Array.from(pubkey) }).toBytes();
|
|
156
181
|
return deriveObjectID(configId, `${giftPkg}::claimable_link::GiftKey`, keyBytes);
|