From d52f92e8c0fb6d98001ca4d281d1cd5d6437abe4 Mon Sep 17 00:00:00 2001 From: cotemper Date: Sun, 11 Jun 2023 22:47:20 +0800 Subject: [PATCH 1/4] update the sdk --- app/.solitarc.js | 3 +- app/idl/splitwave.json | 40 +++---- app/src/generated/accounts/Splitwave.ts | 5 + app/src/generated/errors/index.ts | 101 +++++++++--------- .../generated/instructions/paySplitwave.ts | 4 +- 5 files changed, 80 insertions(+), 73 deletions(-) diff --git a/app/.solitarc.js b/app/.solitarc.js index 7fcfc94..d36e790 100644 --- a/app/.solitarc.js +++ b/app/.solitarc.js @@ -2,7 +2,8 @@ const path = require('path'); const programDir = path.join(__dirname, '..', 'programs/splitwave'); const idlDir = path.join(__dirname, 'idl'); const sdkDir = path.join(__dirname, 'src', 'generated'); -const binaryInstallDir = path.join(__dirname, '.crates'); +// const binaryInstallDir = path.join(__dirname, '.crates'); +const binaryInstallDir = '/home/dantes/.cargo'; module.exports = { idlGenerator: 'anchor', diff --git a/app/idl/splitwave.json b/app/idl/splitwave.json index bddaa5c..3fd3e9e 100644 --- a/app/idl/splitwave.json +++ b/app/idl/splitwave.json @@ -132,7 +132,7 @@ "accounts": [ { "name": "authority", - "isMut": false, + "isMut": true, "isSigner": false }, { @@ -296,6 +296,10 @@ "name": "authority", "type": "publicKey" }, + { + "name": "recipient", + "type": "publicKey" + }, { "name": "recipientTokenAccount", "type": "publicKey" @@ -486,73 +490,73 @@ }, { "code": 6026, - "name": "AmountAlreadyDisbursedToRecipient", - "msg": "Amount Already Disbursed to Recipient" - }, - { - "code": 6027, "name": "DuplicateParticipants", "msg": "Duplicate Participants" }, { - "code": 6028, + "code": 6027, "name": "InvalidAccounts", "msg": "Invalid Accounts" }, { - "code": 6029, + "code": 6028, "name": "ParticipantNotFound", "msg": "Participant not found" }, { - "code": 6030, + "code": 6029, "name": "ParticipantAlreadyPaid", "msg": "Participant already paid" }, { - "code": 6031, + "code": 6030, "name": "ParticipantPaidIncorrectAmount", "msg": "Participant paid incorrect amount" }, { - "code": 6032, + "code": 6031, "name": "InvalidTokenAccountOwner", "msg": "Invalid Token Account Owner" }, { - "code": 6033, + "code": 6032, "name": "TokenTransferFailed", "msg": "Token transfer failed" }, { - "code": 6034, + "code": 6033, "name": "PublicKeyMismatch", "msg": "Public key mismatch" }, { - "code": 6035, + "code": 6034, "name": "UninitializedAccount", "msg": "Uninitialized account" }, { - "code": 6036, + "code": 6035, "name": "IncorrectOwner", "msg": "Invalid account owner" }, { - "code": 6037, + "code": 6036, "name": "DerivedKeyInvalid", "msg": "Derived Key is not a signer" }, { - "code": 6038, + "code": 6037, "name": "BumpSeedNotInHashMap", "msg": "Invalid bump seed" }, { - "code": 6039, + "code": 6038, "name": "InvalidAssociatedTokenAccount", "msg": "Invalid Associated Token Account" + }, + { + "code": 6039, + "name": "NumericalOverflow", + "msg": "Numerical Overflow error" } ], "metadata": { diff --git a/app/src/generated/accounts/Splitwave.ts b/app/src/generated/accounts/Splitwave.ts index bb35633..3fd0a87 100644 --- a/app/src/generated/accounts/Splitwave.ts +++ b/app/src/generated/accounts/Splitwave.ts @@ -27,6 +27,7 @@ export type SplitwaveArgs = { totalParticipants: beet.bignum participantsPaidToSplitwave: beet.bignum authority: web3.PublicKey + recipient: web3.PublicKey recipientTokenAccount: web3.PublicKey splitwaveMint: web3.PublicKey splitwaveTreasury: web3.PublicKey @@ -52,6 +53,7 @@ export class Splitwave implements SplitwaveArgs { readonly totalParticipants: beet.bignum, readonly participantsPaidToSplitwave: beet.bignum, readonly authority: web3.PublicKey, + readonly recipient: web3.PublicKey, readonly recipientTokenAccount: web3.PublicKey, readonly splitwaveMint: web3.PublicKey, readonly splitwaveTreasury: web3.PublicKey, @@ -72,6 +74,7 @@ export class Splitwave implements SplitwaveArgs { args.totalParticipants, args.participantsPaidToSplitwave, args.authority, + args.recipient, args.recipientTokenAccount, args.splitwaveMint, args.splitwaveTreasury, @@ -243,6 +246,7 @@ export class Splitwave implements SplitwaveArgs { return x })(), authority: this.authority.toBase58(), + recipient: this.recipient.toBase58(), recipientTokenAccount: this.recipientTokenAccount.toBase58(), splitwaveMint: this.splitwaveMint.toBase58(), splitwaveTreasury: this.splitwaveTreasury.toBase58(), @@ -272,6 +276,7 @@ export const splitwaveBeet = new beet.FixableBeetStruct< ['totalParticipants', beet.u64], ['participantsPaidToSplitwave', beet.u64], ['authority', beetSolana.publicKey], + ['recipient', beetSolana.publicKey], ['recipientTokenAccount', beetSolana.publicKey], ['splitwaveMint', beetSolana.publicKey], ['splitwaveTreasury', beetSolana.publicKey], diff --git a/app/src/generated/errors/index.ts b/app/src/generated/errors/index.ts index daddad8..77c1517 100644 --- a/app/src/generated/errors/index.ts +++ b/app/src/generated/errors/index.ts @@ -642,32 +642,6 @@ export class InvalidMintError extends Error { createErrorFromCodeLookup.set(0x1789, () => new InvalidMintError()) createErrorFromNameLookup.set('InvalidMint', () => new InvalidMintError()) -/** - * AmountAlreadyDisbursedToRecipient: 'Amount Already Disbursed to Recipient' - * - * @category Errors - * @category generated - */ -export class AmountAlreadyDisbursedToRecipientError extends Error { - readonly code: number = 0x178a - readonly name: string = 'AmountAlreadyDisbursedToRecipient' - constructor() { - super('Amount Already Disbursed to Recipient') - if (typeof Error.captureStackTrace === 'function') { - Error.captureStackTrace(this, AmountAlreadyDisbursedToRecipientError) - } - } -} - -createErrorFromCodeLookup.set( - 0x178a, - () => new AmountAlreadyDisbursedToRecipientError() -) -createErrorFromNameLookup.set( - 'AmountAlreadyDisbursedToRecipient', - () => new AmountAlreadyDisbursedToRecipientError() -) - /** * DuplicateParticipants: 'Duplicate Participants' * @@ -675,7 +649,7 @@ createErrorFromNameLookup.set( * @category generated */ export class DuplicateParticipantsError extends Error { - readonly code: number = 0x178b + readonly code: number = 0x178a readonly name: string = 'DuplicateParticipants' constructor() { super('Duplicate Participants') @@ -685,7 +659,7 @@ export class DuplicateParticipantsError extends Error { } } -createErrorFromCodeLookup.set(0x178b, () => new DuplicateParticipantsError()) +createErrorFromCodeLookup.set(0x178a, () => new DuplicateParticipantsError()) createErrorFromNameLookup.set( 'DuplicateParticipants', () => new DuplicateParticipantsError() @@ -698,7 +672,7 @@ createErrorFromNameLookup.set( * @category generated */ export class InvalidAccountsError extends Error { - readonly code: number = 0x178c + readonly code: number = 0x178b readonly name: string = 'InvalidAccounts' constructor() { super('Invalid Accounts') @@ -708,7 +682,7 @@ export class InvalidAccountsError extends Error { } } -createErrorFromCodeLookup.set(0x178c, () => new InvalidAccountsError()) +createErrorFromCodeLookup.set(0x178b, () => new InvalidAccountsError()) createErrorFromNameLookup.set( 'InvalidAccounts', () => new InvalidAccountsError() @@ -721,7 +695,7 @@ createErrorFromNameLookup.set( * @category generated */ export class ParticipantNotFoundError extends Error { - readonly code: number = 0x178d + readonly code: number = 0x178c readonly name: string = 'ParticipantNotFound' constructor() { super('Participant not found') @@ -731,7 +705,7 @@ export class ParticipantNotFoundError extends Error { } } -createErrorFromCodeLookup.set(0x178d, () => new ParticipantNotFoundError()) +createErrorFromCodeLookup.set(0x178c, () => new ParticipantNotFoundError()) createErrorFromNameLookup.set( 'ParticipantNotFound', () => new ParticipantNotFoundError() @@ -744,7 +718,7 @@ createErrorFromNameLookup.set( * @category generated */ export class ParticipantAlreadyPaidError extends Error { - readonly code: number = 0x178e + readonly code: number = 0x178d readonly name: string = 'ParticipantAlreadyPaid' constructor() { super('Participant already paid') @@ -754,7 +728,7 @@ export class ParticipantAlreadyPaidError extends Error { } } -createErrorFromCodeLookup.set(0x178e, () => new ParticipantAlreadyPaidError()) +createErrorFromCodeLookup.set(0x178d, () => new ParticipantAlreadyPaidError()) createErrorFromNameLookup.set( 'ParticipantAlreadyPaid', () => new ParticipantAlreadyPaidError() @@ -767,7 +741,7 @@ createErrorFromNameLookup.set( * @category generated */ export class ParticipantPaidIncorrectAmountError extends Error { - readonly code: number = 0x178f + readonly code: number = 0x178e readonly name: string = 'ParticipantPaidIncorrectAmount' constructor() { super('Participant paid incorrect amount') @@ -778,7 +752,7 @@ export class ParticipantPaidIncorrectAmountError extends Error { } createErrorFromCodeLookup.set( - 0x178f, + 0x178e, () => new ParticipantPaidIncorrectAmountError() ) createErrorFromNameLookup.set( @@ -793,7 +767,7 @@ createErrorFromNameLookup.set( * @category generated */ export class InvalidTokenAccountOwnerError extends Error { - readonly code: number = 0x1790 + readonly code: number = 0x178f readonly name: string = 'InvalidTokenAccountOwner' constructor() { super('Invalid Token Account Owner') @@ -803,7 +777,7 @@ export class InvalidTokenAccountOwnerError extends Error { } } -createErrorFromCodeLookup.set(0x1790, () => new InvalidTokenAccountOwnerError()) +createErrorFromCodeLookup.set(0x178f, () => new InvalidTokenAccountOwnerError()) createErrorFromNameLookup.set( 'InvalidTokenAccountOwner', () => new InvalidTokenAccountOwnerError() @@ -816,7 +790,7 @@ createErrorFromNameLookup.set( * @category generated */ export class TokenTransferFailedError extends Error { - readonly code: number = 0x1791 + readonly code: number = 0x1790 readonly name: string = 'TokenTransferFailed' constructor() { super('Token transfer failed') @@ -826,7 +800,7 @@ export class TokenTransferFailedError extends Error { } } -createErrorFromCodeLookup.set(0x1791, () => new TokenTransferFailedError()) +createErrorFromCodeLookup.set(0x1790, () => new TokenTransferFailedError()) createErrorFromNameLookup.set( 'TokenTransferFailed', () => new TokenTransferFailedError() @@ -839,7 +813,7 @@ createErrorFromNameLookup.set( * @category generated */ export class PublicKeyMismatchError extends Error { - readonly code: number = 0x1792 + readonly code: number = 0x1791 readonly name: string = 'PublicKeyMismatch' constructor() { super('Public key mismatch') @@ -849,7 +823,7 @@ export class PublicKeyMismatchError extends Error { } } -createErrorFromCodeLookup.set(0x1792, () => new PublicKeyMismatchError()) +createErrorFromCodeLookup.set(0x1791, () => new PublicKeyMismatchError()) createErrorFromNameLookup.set( 'PublicKeyMismatch', () => new PublicKeyMismatchError() @@ -862,7 +836,7 @@ createErrorFromNameLookup.set( * @category generated */ export class UninitializedAccountError extends Error { - readonly code: number = 0x1793 + readonly code: number = 0x1792 readonly name: string = 'UninitializedAccount' constructor() { super('Uninitialized account') @@ -872,7 +846,7 @@ export class UninitializedAccountError extends Error { } } -createErrorFromCodeLookup.set(0x1793, () => new UninitializedAccountError()) +createErrorFromCodeLookup.set(0x1792, () => new UninitializedAccountError()) createErrorFromNameLookup.set( 'UninitializedAccount', () => new UninitializedAccountError() @@ -885,7 +859,7 @@ createErrorFromNameLookup.set( * @category generated */ export class IncorrectOwnerError extends Error { - readonly code: number = 0x1794 + readonly code: number = 0x1793 readonly name: string = 'IncorrectOwner' constructor() { super('Invalid account owner') @@ -895,7 +869,7 @@ export class IncorrectOwnerError extends Error { } } -createErrorFromCodeLookup.set(0x1794, () => new IncorrectOwnerError()) +createErrorFromCodeLookup.set(0x1793, () => new IncorrectOwnerError()) createErrorFromNameLookup.set('IncorrectOwner', () => new IncorrectOwnerError()) /** @@ -905,7 +879,7 @@ createErrorFromNameLookup.set('IncorrectOwner', () => new IncorrectOwnerError()) * @category generated */ export class DerivedKeyInvalidError extends Error { - readonly code: number = 0x1795 + readonly code: number = 0x1794 readonly name: string = 'DerivedKeyInvalid' constructor() { super('Derived Key is not a signer') @@ -915,7 +889,7 @@ export class DerivedKeyInvalidError extends Error { } } -createErrorFromCodeLookup.set(0x1795, () => new DerivedKeyInvalidError()) +createErrorFromCodeLookup.set(0x1794, () => new DerivedKeyInvalidError()) createErrorFromNameLookup.set( 'DerivedKeyInvalid', () => new DerivedKeyInvalidError() @@ -928,7 +902,7 @@ createErrorFromNameLookup.set( * @category generated */ export class BumpSeedNotInHashMapError extends Error { - readonly code: number = 0x1796 + readonly code: number = 0x1795 readonly name: string = 'BumpSeedNotInHashMap' constructor() { super('Invalid bump seed') @@ -938,7 +912,7 @@ export class BumpSeedNotInHashMapError extends Error { } } -createErrorFromCodeLookup.set(0x1796, () => new BumpSeedNotInHashMapError()) +createErrorFromCodeLookup.set(0x1795, () => new BumpSeedNotInHashMapError()) createErrorFromNameLookup.set( 'BumpSeedNotInHashMap', () => new BumpSeedNotInHashMapError() @@ -951,7 +925,7 @@ createErrorFromNameLookup.set( * @category generated */ export class InvalidAssociatedTokenAccountError extends Error { - readonly code: number = 0x1797 + readonly code: number = 0x1796 readonly name: string = 'InvalidAssociatedTokenAccount' constructor() { super('Invalid Associated Token Account') @@ -962,7 +936,7 @@ export class InvalidAssociatedTokenAccountError extends Error { } createErrorFromCodeLookup.set( - 0x1797, + 0x1796, () => new InvalidAssociatedTokenAccountError() ) createErrorFromNameLookup.set( @@ -970,6 +944,29 @@ createErrorFromNameLookup.set( () => new InvalidAssociatedTokenAccountError() ) +/** + * NumericalOverflow: 'Numerical Overflow error' + * + * @category Errors + * @category generated + */ +export class NumericalOverflowError extends Error { + readonly code: number = 0x1797 + readonly name: string = 'NumericalOverflow' + constructor() { + super('Numerical Overflow error') + if (typeof Error.captureStackTrace === 'function') { + Error.captureStackTrace(this, NumericalOverflowError) + } + } +} + +createErrorFromCodeLookup.set(0x1797, () => new NumericalOverflowError()) +createErrorFromNameLookup.set( + 'NumericalOverflow', + () => new NumericalOverflowError() +) + /** * Attempts to resolve a custom program error from the provided error code. * @category Errors diff --git a/app/src/generated/instructions/paySplitwave.ts b/app/src/generated/instructions/paySplitwave.ts index d84e3e6..f73132b 100644 --- a/app/src/generated/instructions/paySplitwave.ts +++ b/app/src/generated/instructions/paySplitwave.ts @@ -36,7 +36,7 @@ export const paySplitwaveStruct = new beet.BeetArgsStruct< /** * Accounts required by the _paySplitwave_ instruction * - * @property [] authority + * @property [_writable_] authority * @property [_writable_] recipientTokenAccount * @property [_writable_] splitwave * @property [_writable_] splitwaveTreasury @@ -86,7 +86,7 @@ export function createPaySplitwaveInstruction( const keys: web3.AccountMeta[] = [ { pubkey: accounts.authority, - isWritable: false, + isWritable: true, isSigner: false, }, { From 01379e55383a9d96d90501d4f40425764dddaaf8 Mon Sep 17 00:00:00 2001 From: cotemper Date: Sun, 11 Jun 2023 22:48:50 +0800 Subject: [PATCH 2/4] upgrade the sdk version --- app/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/package.json b/app/package.json index 2278591..3757429 100644 --- a/app/package.json +++ b/app/package.json @@ -1,6 +1,6 @@ { "name": "@splitwave/js", - "version": "0.1.1", + "version": "0.1.2", "description": "Splitwave JavaScript API.", "main": "dist/src/generated/index.js", "types": "dist/src/generated/index.d.ts", From 2e1e3086c05659c7b66417bb7e7af17ebf5dd25e Mon Sep 17 00:00:00 2001 From: cotemper Date: Sun, 11 Jun 2023 23:00:21 +0800 Subject: [PATCH 3/4] upgrade the SDK version --- app/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/package.json b/app/package.json index 3757429..e4671c4 100644 --- a/app/package.json +++ b/app/package.json @@ -1,6 +1,6 @@ { "name": "@splitwave/js", - "version": "0.1.2", + "version": "0.1.3", "description": "Splitwave JavaScript API.", "main": "dist/src/generated/index.js", "types": "dist/src/generated/index.d.ts", From be8d7645d724058136710d8bb8fb577560985064 Mon Sep 17 00:00:00 2001 From: cotemper Date: Mon, 12 Jun 2023 00:51:32 +0800 Subject: [PATCH 4/4] add a test code to create the splitwave id --- Anchor.toml | 2 +- package-lock.json | 170 +++++++++------------------------------------ package.json | 1 + tests/constants.ts | 3 + tests/lib.ts | 5 ++ tests/splitwave.ts | 163 +++++-------------------------------------- 6 files changed, 63 insertions(+), 281 deletions(-) create mode 100644 tests/constants.ts create mode 100644 tests/lib.ts diff --git a/Anchor.toml b/Anchor.toml index 7eb97ae..62730b4 100644 --- a/Anchor.toml +++ b/Anchor.toml @@ -9,7 +9,7 @@ url = "https://api.apr.dev" [provider] cluster = "devnet" -wallet = "/root/.config/solana/id.json" +wallet = "/home/dantes/.config/solana/wallets/core.json" [scripts] test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts" diff --git a/package-lock.json b/package-lock.json index b7fc177..e34753c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { - "name": "splitwave", + "name": "program", "lockfileVersion": 3, "requires": true, "packages": { "": { "dependencies": { "@project-serum/anchor": "^0.26.0", - "@solana/spl-token": "^0.3.7", + "@solana/web3.js": "^1.77.3", "anchor-lang": "^0.0.1-security" }, "devDependencies": { @@ -104,38 +104,27 @@ "solita": "dist/src/cli/solita.js" } }, - "node_modules/@noble/ed25519": { - "version": "1.7.3", - "resolved": "https://registry.npmjs.org/@noble/ed25519/-/ed25519-1.7.3.tgz", - "integrity": "sha512-iR8GBkDt0Q3GyaVcIu7mSsVIqnFbkbRzGLWlvhwunacoLwt4J3swfKhfaM6rN6WY+TBGoYT1GtT1mIh2/jGbRQ==", - "funding": [ - { - "type": "individual", - "url": "https://paulmillr.com/funding/" - } - ] + "node_modules/@noble/curves": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.1.0.tgz", + "integrity": "sha512-091oBExgENk/kGj3AZmtBDMpxQPDtxQABR2B9lb1JbVTs6ytdzZNwvhxQ4MWasRNEzlbEH8jCWFCwhF/Obj5AA==", + "dependencies": { + "@noble/hashes": "1.3.1" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } }, "node_modules/@noble/hashes": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.0.tgz", - "integrity": "sha512-ilHEACi9DwqJB0pw7kv+Apvh50jiiSyR/cQ3y4W7lOR5mhvn/50FLUfsnfJz0BDZtl/RR16kXvptiv6q1msYZg==", - "funding": [ - { - "type": "individual", - "url": "https://paulmillr.com/funding/" - } - ] - }, - "node_modules/@noble/secp256k1": { - "version": "1.7.1", - "resolved": "https://registry.npmjs.org/@noble/secp256k1/-/secp256k1-1.7.1.tgz", - "integrity": "sha512-hOUk6AyBFmqVrv7k5WAw/LpszxVbj9gGN4JRkIX52fdFAj1UA61KXmZDvqVEm+pOyec3+fIeZB02LYa/pWOArw==", - "funding": [ - { - "type": "individual", - "url": "https://paulmillr.com/funding/" - } - ] + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.1.tgz", + "integrity": "sha512-EbqwksQwz9xDRGfDST86whPBgM65E0OH/pCgqW0GBVzO22bNE+NuIbeTb714+IfSjU3aRk47EUvXIb5bTsenKA==", + "engines": { + "node": ">= 16" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } }, "node_modules/@project-serum/anchor": { "version": "0.26.0", @@ -189,100 +178,23 @@ "node": ">=5.10" } }, - "node_modules/@solana/buffer-layout-utils": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/@solana/buffer-layout-utils/-/buffer-layout-utils-0.2.0.tgz", - "integrity": "sha512-szG4sxgJGktbuZYDg2FfNmkMi0DYQoVjN2h7ta1W1hPrwzarcFLBq9UpX1UjNXsNpT9dn+chgprtWGioUAr4/g==", - "dependencies": { - "@solana/buffer-layout": "^4.0.0", - "@solana/web3.js": "^1.32.0", - "bigint-buffer": "^1.1.5", - "bignumber.js": "^9.0.1" - }, - "engines": { - "node": ">= 10" - } - }, - "node_modules/@solana/buffer-layout/node_modules/buffer": { - "version": "6.0.3", - "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", - "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "dependencies": { - "base64-js": "^1.3.1", - "ieee754": "^1.2.1" - } - }, - "node_modules/@solana/spl-token": { - "version": "0.3.7", - "resolved": "https://registry.npmjs.org/@solana/spl-token/-/spl-token-0.3.7.tgz", - "integrity": "sha512-bKGxWTtIw6VDdCBngjtsGlKGLSmiu/8ghSt/IOYJV24BsymRbgq7r12GToeetpxmPaZYLddKwAz7+EwprLfkfg==", - "dependencies": { - "@solana/buffer-layout": "^4.0.0", - "@solana/buffer-layout-utils": "^0.2.0", - "buffer": "^6.0.3" - }, - "engines": { - "node": ">=16" - }, - "peerDependencies": { - "@solana/web3.js": "^1.47.4" - } - }, - "node_modules/@solana/spl-token/node_modules/buffer": { - "version": "6.0.3", - "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", - "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "dependencies": { - "base64-js": "^1.3.1", - "ieee754": "^1.2.1" - } - }, "node_modules/@solana/web3.js": { - "version": "1.74.0", - "resolved": "https://registry.npmjs.org/@solana/web3.js/-/web3.js-1.74.0.tgz", - "integrity": "sha512-RKZyPqizPCxmpMGfpu4fuplNZEWCrhRBjjVstv5QnAJvgln1jgOfgui+rjl1ExnqDnWKg9uaZ5jtGROH/cwabg==", + "version": "1.77.3", + "resolved": "https://registry.npmjs.org/@solana/web3.js/-/web3.js-1.77.3.tgz", + "integrity": "sha512-PHaO0BdoiQRPpieC1p31wJsBaxwIOWLh8j2ocXNKX8boCQVldt26Jqm2tZE4KlrvnCIV78owPLv1pEUgqhxZ3w==", "dependencies": { "@babel/runtime": "^7.12.5", - "@noble/ed25519": "^1.7.0", - "@noble/hashes": "^1.1.2", - "@noble/secp256k1": "^1.6.3", + "@noble/curves": "^1.0.0", + "@noble/hashes": "^1.3.0", "@solana/buffer-layout": "^4.0.0", "agentkeepalive": "^4.2.1", "bigint-buffer": "^1.1.5", "bn.js": "^5.0.0", "borsh": "^0.7.0", "bs58": "^4.0.1", - "buffer": "6.0.1", + "buffer": "6.0.3", "fast-stable-stringify": "^1.0.0", - "jayson": "^3.4.4", + "jayson": "^4.1.0", "node-fetch": "^2.6.7", "rpc-websockets": "^7.5.1", "superstruct": "^0.14.2" @@ -501,14 +413,6 @@ "node": ">= 10.0.0" } }, - "node_modules/bignumber.js": { - "version": "9.1.1", - "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.1.1.tgz", - "integrity": "sha512-pHm4LsMJ6lzgNGVfZHjMoO8sdoRhOzOH4MLmY65Jg70bpxCKu5iOHNJyfF6OyvYw7t8Fpf35RuzUyqnQsj8Vig==", - "engines": { - "node": "*" - } - }, "node_modules/binary-extensions": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", @@ -595,9 +499,9 @@ } }, "node_modules/buffer": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.1.tgz", - "integrity": "sha512-rVAXBwEcEoYtxnHSO5iWyhzV/O1WMtkUYWlfdLS7FjU4PnSJJHEfHXi/uHPI5EwltmOA794gN3bm3/pzuctWjQ==", + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", "funding": [ { "type": "github", @@ -1254,9 +1158,9 @@ } }, "node_modules/jayson": { - "version": "3.7.0", - "resolved": "https://registry.npmjs.org/jayson/-/jayson-3.7.0.tgz", - "integrity": "sha512-tfy39KJMrrXJ+mFcMpxwBvFDetS8LAID93+rycFglIQM4kl3uNR3W4lBLE/FFhsoUCEox5Dt2adVpDm/XtebbQ==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/jayson/-/jayson-4.1.0.tgz", + "integrity": "sha512-R6JlbyLN53Mjku329XoRT2zJAE6ZgOQ8f91ucYdMCD4nkGCF9kZSrcGXpHIU4jeKj58zUZke2p+cdQchU7Ly7A==", "dependencies": { "@types/connect": "^3.4.33", "@types/node": "^12.12.54", @@ -1268,7 +1172,6 @@ "isomorphic-ws": "^4.0.1", "json-stringify-safe": "^5.0.1", "JSONStream": "^1.3.5", - "lodash": "^4.17.20", "uuid": "^8.3.2", "ws": "^7.4.5" }, @@ -1357,11 +1260,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/lodash": { - "version": "4.17.21", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" - }, "node_modules/log-symbols": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz", diff --git a/package.json b/package.json index b72d8f3..41cef0b 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ }, "dependencies": { "@project-serum/anchor": "^0.26.0", + "@solana/web3.js": "^1.77.3", "anchor-lang": "^0.0.1-security" }, "devDependencies": { diff --git a/tests/constants.ts b/tests/constants.ts new file mode 100644 index 0000000..519ae0a --- /dev/null +++ b/tests/constants.ts @@ -0,0 +1,3 @@ +export const SEED_SPLITWAVE_ID = 'splitwave-id'; +export const SEED_SPLITWAVE = 'splitwave'; +export const SEED_SPLITWAVE_TREASURY = 'splitwave-treasury'; diff --git a/tests/lib.ts b/tests/lib.ts new file mode 100644 index 0000000..d3f2818 --- /dev/null +++ b/tests/lib.ts @@ -0,0 +1,5 @@ +export const wait = async (seconds: number): Promise => { + await new Promise((resolve) => setTimeout(resolve, seconds * 1000)); + return; + } + \ No newline at end of file diff --git a/tests/splitwave.ts b/tests/splitwave.ts index 2bd0e19..3d5e39d 100644 --- a/tests/splitwave.ts +++ b/tests/splitwave.ts @@ -1,23 +1,17 @@ -import * as assert from "assert"; import * as anchor from "@project-serum/anchor"; -import { Program, Wallet, BN, getProvider } from "@project-serum/anchor"; +import { BN, Program } from "@project-serum/anchor"; import * as fs from "fs"; import { - SystemProgram, - Transaction, Keypair, - SYSVAR_RENT_PUBKEY, PublicKey, } from "@solana/web3.js"; -import { - ASSOCIATED_TOKEN_PROGRAM_ID, - getAssociatedTokenAddressSync, - TOKEN_PROGRAM_ID, -} from "@solana/spl-token"; import { IDL, Splitwave } from "../target/types/splitwave"; +import { SEED_SPLITWAVE_ID } from "./constants"; +import { wait } from "./lib"; +import { assert } from "chai"; const SPLITWAVE_PROGRAM_ID = new PublicKey( "pP24ZPhQLvSSri8hB5DdoUxRGRLCiYxdf5MH1s93dfd" @@ -42,146 +36,27 @@ describe("splitwave", async () => { const program = anchor.workspace.Splitwave as Program; - const SEED_SPLITWAVE = Buffer.from("splitwave"); - - const ZzZ1KPPath = - "./Keypairs/DHywTRDpPWiyxXfgdaaPPXeBsvU6Lmofkk8SAU7kZzZ1.json"; - const ZzZ2KPPath = - "./Keypairs/BfnRc8FyxxTcdGEfsokkuLPR2RiE6xbL8nM56EQ7ZzZ2.json"; - const zzz3KPPath = - "./Keypairs/2get7zBCcjqLLsgHCYTTFABQUGzXfksq7RNHQZgWzzz3.json"; - const Zzz4KPPath = - "./Keypairs/GHaeX7RnfxZEtRcYrUBNFzNeJPjK3kXKi9jyGQfpZzz4.json"; - const zzZ5KPPath = - "./Keypairs/4QLiMNTLG1r4S1C8eQdzWrUBm1qHgtikTZYJyc56zzZ5.json"; - - const ZzZ1KP = await loadWalletKey(ZzZ1KPPath); - const ZzZ2KP = await loadWalletKey(ZzZ2KPPath); - const zzz3KP = await loadWalletKey(zzz3KPPath); - const Zzz4KP = await loadWalletKey(Zzz4KPPath); - const zzZ5KP = await loadWalletKey(zzZ5KPPath); - - const ZzZ1PK = "DHywTRDpPWiyxXfgdaaPPXeBsvU6Lmofkk8SAU7kZzZ1"; - const ZzZ2PK = "BfnRc8FyxxTcdGEfsokkuLPR2RiE6xbL8nM56EQ7ZzZ2"; - const zzz3PK = "2get7zBCcjqLLsgHCYTTFABQUGzXfksq7RNHQZgWzzz3"; - const Zzz4PK = "GHaeX7RnfxZEtRcYrUBNFzNeJPjK3kXKi9jyGQfpZzz4"; - const zzZ5PK = "4QLiMNTLG1r4S1C8eQdzWrUBm1qHgtikTZYJyc56zzZ5"; - - const ZzZ1Wallet = new Wallet(await loadWalletKey(ZzZ1KPPath)); - const ZzZ2Wallet = new Wallet(await loadWalletKey(ZzZ2KPPath)); - const zzz3Wallet = new Wallet(await loadWalletKey(zzz3KPPath)); - const Zzz4Wallet = new Wallet(await loadWalletKey(Zzz4KPPath)); - const zzZ5Wallet = new Wallet(await loadWalletKey(zzZ5KPPath)); - - const findSplitwavePda = async ( - authority: PublicKey, - mint: PublicKey, - recipient: PublicKey - ) => { - const [splitwavePda] = await PublicKey.findProgramAddressSync( - [ - Buffer.from(SEED_SPLITWAVE), - authority.toBuffer(), - mint.toBuffer(), - recipient.toBuffer(), - ], - new PublicKey(SPLITWAVE_PROGRAM_ID) - ); - return splitwavePda; - }; - - it("create Splitwave", async () => { - const splitwavePda = await findSplitwavePda( - ZzZ1KP.publicKey, - NATIVE_SOL_MINT, - zzZ5KP.publicKey + it("create Splitwave id", async () => { + const [splitwaveId] = PublicKey.findProgramAddressSync( + [Buffer.from(SEED_SPLITWAVE_ID)], + program.programId ); - const splitwaveTokenAccount = await getAssociatedTokenAddressSync( - NATIVE_SOL_MINT, - splitwavePda, - true, - TOKEN_PROGRAM_ID, - ASSOCIATED_TOKEN_PROGRAM_ID - ); - - const participants = [ - { - participant_split_amount: new BN(2), - paid: false, - participant: ZzZ2KP.publicKey, - }, - { - participant_split_amount: new BN(5), - paid: false, - participant: zzz3KP.publicKey, - }, - { - participant_split_amount: new BN(3), - paid: false, - participant: Zzz4KP.publicKey, - }, - ]; - const tx = await program.methods - .createSplitwave(new anchor.BN(10), participants) - .accountsStrict({ - authority: ZzZ1KP.publicKey, - mint: NATIVE_SOL_MINT, - recipient: zzZ5KP.publicKey, - splitwave: splitwavePda, - splitwaveTokenAccount: splitwaveTokenAccount, - rent: anchor.web3.SYSVAR_RENT_PUBKEY, - systemProgram: anchor.web3.SystemProgram.programId, - tokenProgram: TOKEN_PROGRAM_ID, - associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID, + .createSplitwaveId() + .accounts({ + splitwaveId, + payer: (program.provider as anchor.AnchorProvider).wallet.publicKey }) - .signers([ZzZ1KP]); + .rpc(); console.log("Your transaction signature", tx); - }); - // it("pay Splitwave", async () => { - // const splitwavePda = await findSplitwavePda( - // ZzZ1KP.publicKey, - // NATIVE_SOL_MINT, - // zzZ5KP.publicKey - // ); + await wait(1); - // const splitwaveTokenAccount = await getAssociatedTokenAddressSync( - // NATIVE_SOL_MINT, - // splitwavePda, - // true, - // TOKEN_PROGRAM_ID, - // ASSOCIATED_TOKEN_PROGRAM_ID - // ); - - // let participantTokenAccount = await getAssociatedTokenAddressSync( - // NATIVE_SOL_MINT, - // ZzZ2KP.publicKey, - // false, - // TOKEN_PROGRAM_ID, - // ASSOCIATED_TOKEN_PROGRAM_ID - // ); - - // const tx = await program.methods - // .paySplitwave(new anchor.BN(2)) - // .accountsStrict({ - // authority: ZzZ1KP.publicKey, - // mint: NATIVE_SOL_MINT, - // recipient: zzZ5KP.publicKey, - // splitwave: splitwavePda, - // splitwaveTokenAccount: splitwaveTokenAccount, - // participant: ZzZ2KP.publicKey, - // participantTokenAccount: participantTokenAccount, - // rent: anchor.web3.SYSVAR_RENT_PUBKEY, - // systemProgram: anchor.web3.SystemProgram.programId, - // tokenProgram: TOKEN_PROGRAM_ID, - // associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID, - // }) - // .signers([ZzZ2KP]) - // .rpc(); - - // console.log("Your transaction signature", tx); - // }); + const splitwaveID = await program.account.splitwaveId.fetchNullable(splitwaveId, "confirmed"); + + assert.isTrue(splitwaveID.splitwaveId.eq(new BN("1"))); + }); + });