Skip to content

Commit

Permalink
[zksend] Update garphql query, and use getstashed.com as claim api ho…
Browse files Browse the repository at this point in the history
…st (#20237)

## Description 

fixes #20222 

Describe the changes or additions included in this PR.

## Test plan 

How did you test the new or updated feature?

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
  • Loading branch information
hayes-mysten authored Nov 13, 2024
1 parent 364a93a commit 60bdb62
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 41 deletions.
5 changes: 5 additions & 0 deletions .changeset/healthy-horses-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@mysten/zksend': minor
---

Update graphql query and use stashed host for claim api
69 changes: 32 additions & 37 deletions sdk/zksend/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { decodeSuiPrivateKey, Keypair } from '@mysten/sui/cryptography';
import { getFaucetHost, requestSuiFromFaucetV0 } from '@mysten/sui/faucet';
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
import { Transaction } from '@mysten/sui/transactions';
import { toBase64 } from '@mysten/sui/utils';
import { MIST_PER_SUI, toBase64 } from '@mysten/sui/utils';
import { beforeAll, expect, test } from 'vitest';

import { getSentTransactionsWithLinks, ZkSendLink, ZkSendLinkBuilder } from './index.js';
Expand All @@ -17,22 +17,26 @@ export const DEMO_BEAR_CONFIG = {
type: '0xab8ed19f16874f9b8b66b0b6e325ee064848b1a7fdcb1c2f0478b17ad8574e65::demo_bear::DemoBear',
};

export const ZK_BAG_CONFIG = {
packageId: '0x036fee67274d0d85c3532f58296abe0dee86b93864f1b2b9074be6adb388f138',
bagStoreId: '0x5c63e71734c82c48a3cb9124c54001d1a09736cfb1668b3b30cd92a96dd4d0ce',
bagStoreTableId: '0x4e1bc4085d64005e03eb4eab2510d527aeba9548cda431cb8f149ff37451f870',
};

const client = new SuiClient({
url: getFullnodeUrl('testnet'),
});
const keypair = new Ed25519Keypair();

// address: 0x8ab2b2a5cfa538db19062b79622abe28f3171c8b8048c5957b01846d57574630
const keypair = Ed25519Keypair.fromSecretKey(
'suiprivkey1qz3v0pjxalg3z3p9p6lp4x84y74g0qt2y2q36amvkgfh9zzmm4q66y6ccdz',
);

// Automatically get gas from testnet is not working reliably, manually request gas via discord,
// or uncomment the beforeAll and gas function below
beforeAll(async () => {
await getSuiFromFaucet(keypair);
});
const balance = await client.getBalance({
owner: keypair.toSuiAddress(),
});

if (Number(balance.totalBalance) < Number(MIST_PER_SUI) * 0.02) {
await getSuiFromFaucet(keypair);
}
}, 30_000);

async function getSuiFromFaucet(keypair: Keypair) {
const faucetHost = getFaucetHost('testnet');
Expand All @@ -56,7 +60,7 @@ describe('Contract links', () => {
async () => {
const link = new ZkSendLinkBuilder({
client,
contract: ZK_BAG_CONFIG,
network: 'testnet',
sender: keypair.toSuiAddress(),
});

Expand All @@ -76,9 +80,9 @@ describe('Contract links', () => {
});

const claimLink = await ZkSendLink.fromUrl(linkUrl, {
contract: ZK_BAG_CONFIG,
network: 'testnet',
claimApi: 'https://zksend-git-mh-contract-claims-mysten-labs.vercel.app/api',
claimApi: 'https://getstashed.com/api',
client,
});

const claimableAssets = claimLink.assets!;
Expand Down Expand Up @@ -111,9 +115,8 @@ describe('Contract links', () => {
);

const link2 = await ZkSendLink.fromUrl(linkUrl, {
contract: ZK_BAG_CONFIG,
network: 'testnet',
claimApi: 'https://zksend-git-mh-contract-claims-mysten-labs.vercel.app/api',
claimApi: 'https://getstashed.com/api',
});
expect(link2.assets?.balances).toEqual(claimLink.assets?.balances);
expect(link2.assets?.nfts.map((nft) => nft.objectId)).toEqual(
Expand All @@ -134,7 +137,7 @@ describe('Contract links', () => {
const link = new ZkSendLinkBuilder({
keypair: linkKp,
client,
contract: ZK_BAG_CONFIG,
network: 'testnet',
sender: keypair.toSuiAddress(),
});

Expand Down Expand Up @@ -162,7 +165,6 @@ describe('Contract links', () => {
} = await getSentTransactionsWithLinks({
address: keypair.toSuiAddress(),
network: 'testnet',
contract: ZK_BAG_CONFIG,
});

const { url, transaction } = await lostLink.createRegenerateTransaction(
Expand All @@ -181,9 +183,8 @@ describe('Contract links', () => {
await client.waitForTransaction({ digest: result.digest });

const claimLink = await ZkSendLink.fromUrl(url, {
contract: ZK_BAG_CONFIG,
network: 'testnet',
claimApi: 'https://zksend-git-mh-contract-claims-mysten-labs.vercel.app/api',
claimApi: 'https://getstashed.com/api',
});

expect(claimLink.assets?.nfts.length).toEqual(3);
Expand Down Expand Up @@ -212,9 +213,8 @@ describe('Contract links', () => {
1, // bag
);
const link2 = await ZkSendLink.fromUrl(url, {
contract: ZK_BAG_CONFIG,
network: 'testnet',
claimApi: 'https://zksend-git-mh-contract-claims-mysten-labs.vercel.app/api',
claimApi: 'https://getstashed.com/api',
});
expect(link2.assets?.balances).toEqual(claimLink.assets?.balances);
expect(link2.assets?.nfts.map((nft) => nft.objectId)).toEqual(
Expand All @@ -235,7 +235,7 @@ describe('Contract links', () => {
const link = new ZkSendLinkBuilder({
keypair: linkKp,
client,
contract: ZK_BAG_CONFIG,
network: 'testnet',
sender: keypair.toSuiAddress(),
});

Expand Down Expand Up @@ -263,7 +263,6 @@ describe('Contract links', () => {
} = await getSentTransactionsWithLinks({
address: keypair.toSuiAddress(),
network: 'testnet',
contract: ZK_BAG_CONFIG,
});

const { digest: claimDigest } = await lostLink.claimAssets(keypair.toSuiAddress(), {
Expand Down Expand Up @@ -297,7 +296,7 @@ describe('Contract links', () => {
for (const bear of bears) {
const link = new ZkSendLinkBuilder({
client,
contract: ZK_BAG_CONFIG,
network: 'testnet',
sender: keypair.toSuiAddress(),
});

Expand All @@ -310,7 +309,7 @@ describe('Contract links', () => {
const tx = await ZkSendLinkBuilder.createLinks({
links,
client,
contract: ZK_BAG_CONFIG,
network: 'testnet',
});

const result = await client.signAndExecuteTransaction({
Expand All @@ -324,9 +323,8 @@ describe('Contract links', () => {
const linkUrl = link.getLink();

const claimLink = await ZkSendLink.fromUrl(linkUrl, {
contract: ZK_BAG_CONFIG,
network: 'testnet',
claimApi: 'https://zksend-git-mh-contract-claims-mysten-labs.vercel.app/api',
claimApi: 'https://getstashed.com/api',
});

const claimableAssets = claimLink.assets!;
Expand Down Expand Up @@ -372,6 +370,7 @@ describe('Non contract links', () => {
const link = new ZkSendLinkBuilder({
client,
sender: keypair.toSuiAddress(),
network: 'testnet',
contract: null,
});

Expand All @@ -394,7 +393,6 @@ describe('Non contract links', () => {
await new Promise((resolve) => setTimeout(resolve, 3000));

const claimLink = await ZkSendLink.fromUrl(linkUrl, {
contract: ZK_BAG_CONFIG,
network: 'testnet',
});

Expand Down Expand Up @@ -424,9 +422,8 @@ describe('Non contract links', () => {
);

const link2 = await ZkSendLink.fromUrl(linkUrl, {
contract: ZK_BAG_CONFIG,
network: 'testnet',
claimApi: 'https://zksend-git-mh-contract-claims-mysten-labs.vercel.app/api',
claimApi: 'https://getstashed.com/api',
});
expect(link2.assets?.balances).toEqual(claimLink.assets?.balances);
expect(link2.assets?.nfts.map((nft) => nft.objectId)).toEqual(
Expand Down Expand Up @@ -483,9 +480,8 @@ describe('Non contract links', () => {
const link2 = await ZkSendLink.fromUrl(
`https://zksend.con/claim#${toBase64(decodeSuiPrivateKey(linkKp.getSecretKey()).secretKey)}`,
{
contract: ZK_BAG_CONFIG,
network: 'testnet',
claimApi: 'https://zksend-git-mh-contract-claims-mysten-labs.vercel.app/api',
claimApi: 'https://getstashed.com/api',
},
);
expect(link2.assets?.balances).toEqual(claimLink.assets?.balances);
Expand All @@ -505,6 +501,7 @@ describe('Non contract links', () => {
const link = new ZkSendLinkBuilder({
client,
sender: keypair.toSuiAddress(),
network: 'testnet',
contract: null,
});

Expand Down Expand Up @@ -547,7 +544,7 @@ describe('Non contract links', () => {
async () => {
const link = new ZkSendLinkBuilder({
client,
contract: ZK_BAG_CONFIG,
network: 'testnet',
sender: keypair.toSuiAddress(),
});

Expand Down Expand Up @@ -575,9 +572,8 @@ describe('Non contract links', () => {
});

const claimLink = await ZkSendLink.fromUrl(linkUrl, {
contract: ZK_BAG_CONFIG,
network: 'testnet',
claimApi: 'https://zksend-git-mh-contract-claims-mysten-labs.vercel.app/api',
claimApi: 'https://getstashed.com/api',
});

const claimableAssets = claimLink.assets!;
Expand Down Expand Up @@ -610,9 +606,8 @@ describe('Non contract links', () => {
);

const link2 = await ZkSendLink.fromUrl(linkUrl, {
contract: ZK_BAG_CONFIG,
network: 'testnet',
claimApi: 'https://zksend-git-mh-contract-claims-mysten-labs.vercel.app/api',
claimApi: 'https://getstashed.com/api',
});
expect(link2.assets?.balances).toEqual(claimLink.assets?.balances);
expect(link2.assets?.nfts.map((nft) => nft.objectId).sort()).toEqual(
Expand Down
3 changes: 2 additions & 1 deletion sdk/zksend/src/links/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface ZkSendLinkBuilderOptions {
}

const DEFAULT_ZK_SEND_LINK_OPTIONS = {
host: 'https://zksend.com',
host: 'https://getstashed.com',
path: '/claim',
network: 'mainnet' as const,
};
Expand Down Expand Up @@ -163,6 +163,7 @@ export class ZkSendLinkBuilder {

return ZkSendLinkBuilder.createLinks({
transaction,
network: this.network,
client: this.#client,
contract: this.#contract.ids,
links: [this],
Expand Down
10 changes: 8 additions & 2 deletions sdk/zksend/src/links/claim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ export class ZkSendLink {
link = new ZkSendLink({
...options,
keypair,
network: parsed.searchParams.get('network') === 'testnet' ? 'testnet' : 'mainnet',
network:
options.network ?? parsed.searchParams.get('network') === 'testnet'
? 'testnet'
: 'mainnet',
host: `${parsed.protocol}//${parsed.host}`,
path: parsed.pathname,
isContractLink: true,
Expand All @@ -144,7 +147,10 @@ export class ZkSendLink {
link = new ZkSendLink({
...options,
keypair,
network: parsed.searchParams.get('network') === 'testnet' ? 'testnet' : 'mainnet',
network:
options.network ?? parsed.searchParams.get('network') === 'testnet'
? 'testnet'
: 'mainnet',
host: `${parsed.protocol}//${parsed.host}`,
path: parsed.pathname,
isContractLink: false,
Expand Down
2 changes: 1 addition & 1 deletion sdk/zksend/src/links/list-created-links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const ListCreatedLinksQuery = graphql(`
transactionBlocks(
last: 10
before: $cursor
filter: { sentAddress: $address, function: $function, kind: PROGRAMMABLE_TX }
filter: { sentAddress: $address, function: $function }
) {
pageInfo {
startCursor
Expand Down

0 comments on commit 60bdb62

Please sign in to comment.