@mysten-incubation/suipay 0.2.0-dev.5 → 0.2.0-dev.6

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 (2) hide show
  1. package/dist/index.js +64 -0
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -4083,6 +4083,70 @@ function createSpendAccountChain(options) {
4083
4083
  });
4084
4084
  return kindBytes(tx);
4085
4085
  },
4086
+ async buildCreatePolicyAndGrantKind(input) {
4087
+ if (!input.policy.targets?.length) {
4088
+ throw new Error("create_spend_policy requires at least one target");
4089
+ }
4090
+ if (!input.policy.totalCap || BigInt(input.policy.totalCap) <= 0n) {
4091
+ throw new Error("create_spend_policy requires a non-zero total_cap");
4092
+ }
4093
+ if (!input.policy.maxPerPayment || BigInt(input.policy.maxPerPayment) <= 0n) {
4094
+ throw new Error("create_spend_policy requires a non-zero max_per_payment");
4095
+ }
4096
+ if (!input.grant.sessionCap || BigInt(input.grant.sessionCap) <= 0n) {
4097
+ throw new Error("create_grant requires a non-zero session_cap");
4098
+ }
4099
+ if (!input.grant.maxPerPayment || BigInt(input.grant.maxPerPayment) <= 0n) {
4100
+ throw new Error("create_grant requires a non-zero max_per_payment");
4101
+ }
4102
+ const tx = new Transaction2();
4103
+ tx.setSender(input.owner);
4104
+ const targetResults = input.policy.targets.map((t) => {
4105
+ const hash = targetHashBytes(t.targetHash);
4106
+ return tx.moveCall({
4107
+ target: target("new_policy_target"),
4108
+ arguments: [
4109
+ tx.pure.vector("u8", Array.from(hash)),
4110
+ tx.pure.address(t.recipient),
4111
+ tx.pure.u64(BigInt(t.maxPerPayment))
4112
+ ]
4113
+ });
4114
+ });
4115
+ const targetsVec = tx.makeMoveVec({
4116
+ type: `${packageId}::${MODULE}::PolicyTarget`,
4117
+ elements: targetResults
4118
+ });
4119
+ const policyExpires = input.policy.expiresAtMs === void 0 || input.policy.expiresAtMs === null ? 0n : BigInt(input.policy.expiresAtMs);
4120
+ const policyIdResult = tx.moveCall({
4121
+ target: target("create_spend_policy"),
4122
+ typeArguments: [input.coinType],
4123
+ arguments: [
4124
+ tx.object(input.poolObjectId),
4125
+ targetsVec,
4126
+ tx.pure.u64(BigInt(input.policy.totalCap)),
4127
+ tx.pure.u64(BigInt(input.policy.maxPerPayment)),
4128
+ tx.pure.u64(policyExpires)
4129
+ ]
4130
+ });
4131
+ const policyIdsVec = tx.makeMoveVec({
4132
+ type: "u64",
4133
+ elements: [policyIdResult]
4134
+ });
4135
+ const grantExpires = input.grant.expiresAtMs === void 0 || input.grant.expiresAtMs === null ? 0n : BigInt(input.grant.expiresAtMs);
4136
+ tx.moveCall({
4137
+ target: target("create_policy_grant"),
4138
+ typeArguments: [input.coinType],
4139
+ arguments: [
4140
+ tx.object(input.poolObjectId),
4141
+ tx.pure.address(input.delegate),
4142
+ tx.pure.option("u64", BigInt(input.grant.sessionCap)),
4143
+ tx.pure.option("u64", BigInt(input.grant.maxPerPayment)),
4144
+ tx.pure.u64(grantExpires),
4145
+ policyIdsVec
4146
+ ]
4147
+ });
4148
+ return kindBytes(tx);
4149
+ },
4086
4150
  async buildPausePolicyKind(input) {
4087
4151
  const tx = new Transaction2();
4088
4152
  tx.setSender(input.owner);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mysten-incubation/suipay",
3
- "version": "0.2.0-dev.5",
3
+ "version": "0.2.0-dev.6",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "SuiPay embeddable client — quote and pay a 402 from a spend-account grant.",
@@ -37,8 +37,8 @@
37
37
  "tsup": "^8.0.0",
38
38
  "typescript": "^6.0.3",
39
39
  "vitest": "^4.1.10",
40
- "@cmdoss/suipay-core": "0.1.0",
41
- "@cmdoss/suipay-sdk": "0.1.0"
40
+ "@cmdoss/suipay-sdk": "0.1.0",
41
+ "@cmdoss/suipay-core": "0.1.0"
42
42
  },
43
43
  "scripts": {
44
44
  "build": "tsup",