diff --git a/js/package-lock.json b/js/package-lock.json index c488e5cd..b98d8f4f 100644 --- a/js/package-lock.json +++ b/js/package-lock.json @@ -3474,54 +3474,12 @@ "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "dev": true }, - "node_modules/base-x": { - "version": "3.0.9", - "resolved": "https://registry.npmjs.org/base-x/-/base-x-3.0.9.tgz", - "integrity": "sha512-H7JU6iBHTal1gp56aKoaa//YUxEaAOUiydvrV/pILqIHXTtqxSkATOnDA2u+jZ/61sD+L/412+7kzXRtWukhpQ==", - "peer": true, - "dependencies": { - "safe-buffer": "^5.0.1" - } - }, - "node_modules/base64-js": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", - "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "peer": true - }, "node_modules/bech32": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/bech32/-/bech32-2.0.0.tgz", "integrity": "sha512-LcknSilhIGatDAsY1ak2I8VtGaHNhgMSYVxFrGLXv+xLHytaKZKcaUJJUE7qmBr7h33o5YQwP55pMI0xmkpJwg==", "peer": true }, - "node_modules/bigint-buffer": { - "version": "1.1.5", - "resolved": "https://registry.npmjs.org/bigint-buffer/-/bigint-buffer-1.1.5.tgz", - "integrity": "sha512-trfYco6AoZ+rKhKnxA0hgX0HAbVP/s808/EuDSe2JDzUnCp/xAsli35Orvk67UrTEcwuxZqYZDmfA2RXJgxVvA==", - "hasInstallScript": true, - "peer": true, - "dependencies": { - "bindings": "^1.3.0" - }, - "engines": { - "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", @@ -7117,7 +7075,8 @@ "node_modules/rfdc": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/rfdc/-/rfdc-1.4.1.tgz", - "integrity": "sha512-q1b3N5QkRUWUl7iyylaaj3kOpIT0N2i9MqIEQXP73GVsN9cw3fdx8X63cEmWhJGi2PPCF23Ijp7ktmd39rawIA==" + "integrity": "sha512-q1b3N5QkRUWUl7iyylaaj3kOpIT0N2i9MqIEQXP73GVsN9cw3fdx8X63cEmWhJGi2PPCF23Ijp7ktmd39rawIA==", + "dev": true }, "node_modules/rimraf": { "version": "3.0.2", @@ -8119,7 +8078,6 @@ "peerDependencies": { "@race-foundation/borsh": "*", "merkletreejs": "^0.4.0", - "rfdc": "^1.4.1", "ts-chacha20": "^1.2.0" } }, @@ -10875,36 +10833,12 @@ "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "dev": true }, - "base-x": { - "version": "3.0.9", - "resolved": "https://registry.npmjs.org/base-x/-/base-x-3.0.9.tgz", - "integrity": "sha512-H7JU6iBHTal1gp56aKoaa//YUxEaAOUiydvrV/pILqIHXTtqxSkATOnDA2u+jZ/61sD+L/412+7kzXRtWukhpQ==", - "peer": true, - "requires": { - "safe-buffer": "^5.0.1" - } - }, - "base64-js": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", - "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", - "peer": true - }, "bech32": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/bech32/-/bech32-2.0.0.tgz", "integrity": "sha512-LcknSilhIGatDAsY1ak2I8VtGaHNhgMSYVxFrGLXv+xLHytaKZKcaUJJUE7qmBr7h33o5YQwP55pMI0xmkpJwg==", "peer": true }, - "bigint-buffer": { - "version": "1.1.5", - "resolved": "https://registry.npmjs.org/bigint-buffer/-/bigint-buffer-1.1.5.tgz", - "integrity": "sha512-trfYco6AoZ+rKhKnxA0hgX0HAbVP/s808/EuDSe2JDzUnCp/xAsli35Orvk67UrTEcwuxZqYZDmfA2RXJgxVvA==", - "peer": true, - "requires": { - "bindings": "^1.3.0" - } - }, "bignumber.js": { "version": "9.1.1", "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.1.1.tgz", @@ -13551,7 +13485,8 @@ "rfdc": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/rfdc/-/rfdc-1.4.1.tgz", - "integrity": "sha512-q1b3N5QkRUWUl7iyylaaj3kOpIT0N2i9MqIEQXP73GVsN9cw3fdx8X63cEmWhJGi2PPCF23Ijp7ktmd39rawIA==" + "integrity": "sha512-q1b3N5QkRUWUl7iyylaaj3kOpIT0N2i9MqIEQXP73GVsN9cw3fdx8X63cEmWhJGi2PPCF23Ijp7ktmd39rawIA==", + "dev": true }, "rimraf": { "version": "3.0.2", diff --git a/js/sdk-sui/bin/cli.ts b/js/sdk-sui/bin/cli.ts index 03bb0ae2..b663acff 100755 --- a/js/sdk-sui/bin/cli.ts +++ b/js/sdk-sui/bin/cli.ts @@ -8,12 +8,12 @@ import { CloseGameAccountParams, CreateGameAccountParams, CreatePlayerProfilePar import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519'; const wallet = new LocalSuiWallet('suiprivkey1qqds4vhlnm38pma946w5ke4g2846wpkgfygu88auscspswd5d4hl6fvc4q2'); -const TEST_PACKAGE_ID = "0xf3c857da70fbf7275495e35243e66d628dcac3f7a83a4b094a918811df5b1f99"; +const TEST_PACKAGE_ID = "0xa5698c13cdfc969501fc22982838d227cc83a79cf8810037d4b5e74451b569ea"; const TEST_GAME_ID = "0xe48c698837045e6296c7cd6d14d809f90192d38fb6651940d2adbaae2d700e1d"; -const TEST_SERVER_TABLE_ID = "0x6b42f9a3c1be90700ca3ebca78ae3d65d360f3e17d52f17ca753cf185557b253"; -const TEST_PROFILE_TABLE_ID = "0x0e93925793634d7aa2d6cf3fff73b171c5bf694f7616485cfee1773c58ff6f0e"; -const TEST_RECIPIENT_ID = "0xc3c6277f5c374139e42d6972b5223e4b4bfbd4cabd7a5af6811af79301aefa66"; -const TEST_REGISTRY = "0xc91df1896e7bfac9f288cdcd239c7aaf0e21a37bc38af4a5b006e066b368c0df"; +const TEST_SERVER_TABLE_ID = "0xdac65117edba713a19b37dac5b7b0c6230eb2e16fc0e729d9fb6541282eca2b3"; +const TEST_PROFILE_TABLE_ID = "0x4b4e744f568b7c904e4353f88f7c9a49a46f151493ff25878d9b0e66c2cd1ef3"; +const TEST_RECIPIENT_ID = "0x3bd2cf3a28df3e80779b2e401af54ef24a405fdd7d67f7687145f597d18dbb03"; +const TEST_REGISTRY_ID = "0xcb430f98bd97f8c3697cbdbf0de6b9b59411b2634aeebd07f4434fec30f443c7"; const TEST_GAME_NFT = "0x5ebed419309e71c1cd28a3249bbf792d2f2cc8b94b0e21e45a9873642c0a5cdc"; function testCreatePlayerProfile() { @@ -32,7 +32,7 @@ async function testGetPlayerProfile() { console.log('res', res) } -function testCreateGameAccount() { +async function testCreateGameAccount() { const suiTransport = new SuiTransport('https://fullnode.devnet.sui.io:443'); // console.log(wallet.walletAddr) const params = { @@ -40,7 +40,7 @@ function testCreateGameAccount() { bundleAddr: TEST_GAME_NFT, // bundle_addr address params owner: wallet.walletAddr, // owner address wallet recipientAddr: randomPublicKey(), // recipient_addr address params - tokenAddr: "0x2", // token_addr address params "0x2" + tokenAddr: "0x2::sui::SUI", // token_addr address params "0x2" maxPlayers: 6, // max_players u64 params data_len: 2, // data_len u32 params data: Uint8Array.from([1, 2]), // data vector params @@ -49,22 +49,22 @@ function testCreateGameAccount() { // minDeposit: BigInt(0), // maxDeposit: BigInt(1000000) // }, - // entryType: { - // kind: 'ticket' as const, - // amount: BigInt(1000000) - // }, + entryType: { + kind: 'ticket' as const, + amount: BigInt(100_000_000) + }, // entryType: { // kind: 'gating' as const, // collection: 'abc' // }, - entryType: { - kind: 'disabled' as const, - }, - registrationAddr: '12', + // entryType: { + // kind: 'disabled' as const, + // }, + registrationAddr: TEST_REGISTRY_ID, } let response = new ResponseHandle() - suiTransport.createGameAccount(wallet, params, response); + let result = await suiTransport.createGameAccount(wallet, params, response); console.log(response) } @@ -145,13 +145,13 @@ async function testRegisterGame() { async function testJoinGame() { const suiTransport = new SuiTransport('https://fullnode.devnet.sui.io:443'); - const params: JoinGameParams = { + const params: JoinParams = { gameAddr: TEST_GAME_ID, - amount: 100_000_000, + amount: BigInt(100_000_000), position: 3, verifyKey: 'player3', }; - let response = new ResponseHandle(); + let response = new ResponseHandle(); let res = await suiTransport.join(wallet, params, response); console.log('testJoinGame', response); } diff --git a/js/sdk-sui/src/sui-transport.ts b/js/sdk-sui/src/sui-transport.ts index adc3bebf..8feb3088 100644 --- a/js/sdk-sui/src/sui-transport.ts +++ b/js/sdk-sui/src/sui-transport.ts @@ -45,7 +45,6 @@ export class SuiTransport implements ITransport { transaction.pure.string(params.title), // title string transaction.pure.address(params.bundleAddr), // bundle_addr address params transaction.pure.address(wallet.walletAddr), // owner address wallet - transaction.pure.address(recipientAddr), // recipient_addr address params transaction.pure.string(params.tokenAddr), // token_addr address params "0x2" transaction.pure.u16(params.maxPlayers), // max_players u64 params @@ -88,6 +87,7 @@ export class SuiTransport implements ITransport { transaction.moveCall({ target: `${PACKAGE_ID}::game::create_game`, arguments: [...create_game_args, entry_type_result], + typeArguments: [params.tokenAddr] }); const result = await wallet.send(transaction, suiClient, resp) @@ -193,8 +193,12 @@ export class SuiTransport implements ITransport { createProfileIfNeeded = false } = params; + const suiClient = this.suiClient; + coerceWallet(wallet); + if (createProfileIfNeeded) { - await createPlayerProfile(wallet, { nick: wallet.addr.slice(0,8) }); + let res = new ResponseHandle; + await this.createPlayerProfile(wallet, { nick: 'RacePlayer' }, res); } // get game object for token info and object ref @@ -225,14 +229,12 @@ export class SuiTransport implements ITransport { if (!('initial_shared_version' in shared)) { return resp.transactionFailed('game object is not shared') } - const game_init_version = shared.initial_shared_verison; + const game_init_version = shared.initial_shared_version; const transaction = new Transaction(); - const suiClient = this.suiClient; - coerceWallet(wallet); // split coin for buyin - const [coin] = transaction.splitCoin(transaction.gas, [transaction.pure(params.amount)]); + const [coin] = transaction.splitCoins(transaction.gas, [transaction.pure.u64(params.amount)]); // join the game transaction.moveCall({ target: `${PACKAGE_ID}::game::join_game`, @@ -243,12 +245,11 @@ export class SuiTransport implements ITransport { mutable: false, }), transaction.pure.u16(position), - transaction.pure.u64(access_version), transaction.pure.u64(amount), transaction.pure.u64(verifyKey), coin ], - typeArgument: [game.tokenAddr] + typeArguments: [game.tokenAddr] }); const result = await wallet.send(transaction, suiClient, resp); diff --git a/transport/src/sui.rs b/transport/src/sui.rs index 70ae7aa4..d0101c09 100755 --- a/transport/src/sui.rs +++ b/transport/src/sui.rs @@ -319,7 +319,6 @@ impl TransportT for SuiTransport { mutable: true })?)?, add_input(&mut ptb, new_pure_arg(¶ms.position)?)?, - add_input(&mut ptb, new_pure_arg(¶ms.access_version)?)?, add_input(&mut ptb, new_pure_arg(¶ms.amount)?)?, add_input(&mut ptb, new_pure_arg(¶ms.verify_key)?)?, Argument::NestedResult(0, 0) @@ -1550,10 +1549,10 @@ mod tests { use super::*; // temporary IDs for quick tests - const TEST_PACKAGE_ID: &str = "0xefdf5f95dd6dc87307e10b18abcafb35e0fdc82077c76edec18469064e4a4e99"; + const TEST_PACKAGE_ID: &str = "0xa5698c13cdfc969501fc22982838d227cc83a79cf8810037d4b5e74451b569ea"; const TEST_GAME_ID: &str = "0xca42f1f255ea4d8944ce706bee318d9411d2f2a4ad043f29cc81aadf16f6a061"; const TEST_SERVER_TABLE_ID: &str = "0x302e13fa8331a2c37345ff053d347dd4e19666afa44ff62dcb6ec84fdc13a86e"; - const TEST_PROFILE_TABLE_ID: &str = "0x4b4e744f568b7c904e4353f88f7c9a49a46f151493ff25878d9b0e66c2cd1ef3"; + const TEST_PROFILE_TABLE_ID: &str = "0x302e13fa8331a2c37345ff053d347dd4e19666afa44ff62dcb6ec84fdc13a86e"; const TEST_RECIPIENT_ID: &str = "0x3bd2cf3a28df3e80779b2e401af54ef24a405fdd7d67f7687145f597d18dbb03"; const TEST_REGISTRY: &str = "0xcb430f98bd97f8c3697cbdbf0de6b9b59411b2634aeebd07f4434fec30f443c7"; const TEST_GAME_NFT: &str = "0x5ebed419309e71c1cd28a3249bbf792d2f2cc8b94b0e21e45a9873642c0a5cdc";