Skip to content

Commit 27cd5e7

Browse files
authored
Merge pull request #4 from Attestto-com/feature/spl-token
Feature/spl token
2 parents 7d562c1 + bacb51f commit 27cd5e7

26 files changed

+713
-50
lines changed

.DS_Store

0 Bytes
Binary file not shown.

.run/tests.run.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="tests" type="PHPUnitRunConfigurationType" factoryName="PHPUnit" editBeforeRun="true">
3+
<TestRunner configuration_file="$PROJECT_DIR$/phpunit.xml" directory="$PROJECT_DIR$/tests" use_alternative_configuration_file="true" />
4+
<method v="2" />
5+
</configuration>
6+
</component>

LICENSE

Lines changed: 0 additions & 21 deletions
This file was deleted.

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,20 @@ example usage _**(This will be improved, WIP)**_:
195195

196196
1. Borsh serialize and deserialize. [Done](https://github.com/Attestto-com/solana-php-sdk/tree/master/src/Borsh) - [Test(s)](https://github.com/Attestto-com/solana-php-sdk/blob/master/tests/Unit/BorshTest.php) - [Coverage](https://app.codecov.io/github/Attestto-com/solana-php-sdk/tree/master/src%2FBorsh)
197197
2. Improved documentation. [WIP](#) - This document + [Documentation Index](https://github.com/Attestto-com/solana-php-sdk/tree/master/docs) (https://github.com/Attestto-com/solana-php-sdk/tree/master/docs)
198-
3. Build out more of the Connection, SystemProgram, TokenProgram, MetaplexProgram classes. [WIP](https://github.com/Attestto-com/solana-php-sdk/tree/master/src) - [Tests](https://github.com/Attestto-com/solana-php-sdk/tree/master/tests/Unit) - [Coverage](https://app.codecov.io/github/Attestto-com/solana-php-sdk/tree/master/src)
198+
3. Build out more of the Connection, Message, SystemProgram, TokenProgram, MetaplexProgram classes. [WIP](https://github.com/Attestto-com/solana-php-sdk/tree/master/src) - [Tests](https://github.com/Attestto-com/solana-php-sdk/tree/master/tests/Unit) - [Coverage](https://app.codecov.io/github/Attestto-com/solana-php-sdk/tree/master/src)
199+
4. [ ] Connection::class
200+
5. [x] getLatestBlokchash::class [Source] - [Test] - [Coverage]
201+
6. [ ] getMinimumBalanceForRentExemption()
202+
7. [ ] getTokenAccountBalance()
203+
6. [ ] TransactionMessage::class
204+
7. [ ] compileToV0Message()
205+
8. [ ] VersionedTransaction::class
206+
9. [ ] SPL-TOKEN Program
207+
10. [ ] getOrCreateAssociatedTokenAccount()
208+
11. [ ] getAssociatedTokenAddressSync()
209+
12. [ ] createAssociatedTokenAccountInstruction()
210+
11. [ ] createSyncNativeInstruction() - [Test][Coverage]
211+
199212
4. Improve abstractions around working with binary data. [Done?](https://github.com/Attestto-com/solana-php-sdk/tree/master/src/Borsh) - [Test(s)](https://github.com/Attestto-com/solana-php-sdk/blob/master/tests/Unit/BorshTest.php) - [Coverage](https://app.codecov.io/github/Attestto-com/solana-php-sdk/tree/master/src%2FBorsh)
200213
5. Optimizations:
201214
1. Leverage PHP more.

config/solana-sdk.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
return [
4+
5+
'TOKEN_PROGRAM_ID' => env('TOKEN_PROGRAM_ID') ?? 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA',
6+
//-------
7+
'devnet' => [
8+
'mints' => [
9+
'usdc' => env('USDC_MINT_DEVNET'),
10+
'helium' => env('MAINNET_HELIUM_MINT'),
11+
'solana' => env('MAINNET_SOLANA_MINT'),
12+
],
13+
'network' => [
14+
'type' => env('NETWORK'),
15+
'attesto_rpc' => env('ATTESTO_RPC'),
16+
'fallback_rpc_1' => env('FALLBACK_RPC_1'),
17+
'fallback_rpc_2' => env('FALLBACK_RPC_2'),
18+
],
19+
'api_keys' => [
20+
'helius' => env('HELIUS_API_KEY'),
21+
],
22+
'data_source' => env('DATA_SOURCE'),
23+
'keys' => [
24+
'dapp_pk' => env('DAPP_PK'), // Signer
25+
'burn_address' => env('SOLANA_BURN_ADDRESS'), // Not in use
26+
'treasury_pk' => env('TREASURY_PK'), // Not in use
27+
'fees_pk' => env('FEES_PK'), // Fee Taker
28+
],
29+
],
30+
'network' => [
31+
'type' => env('NETWORK'),
32+
'attesto_rpc' => env('ATTESTO_RPC'),
33+
'fallback_rpc_1' => env('FALLBACK_RPC_1'),
34+
'fallback_rpc_2' => env('FALLBACK_RPC_2'),
35+
],
36+
'api_keys' => [
37+
'helius' => env('HELIUS_API_KEY'),
38+
],
39+
'data_source' => env('DATA_SOURCE'),
40+
'keys' => [
41+
'dapp_pk' => env('DAPP_PK'), // Signer
42+
'burn_address' => env('SOLANA_BURN_ADDRESS'), // Not in use
43+
'treasury_pk' => env('TREASURY_PK'), // Not in use
44+
'fees_pk' => env('FEES_PK'), // Fee Taker
45+
],
46+
'fees' => [
47+
'key_registration' => env('KEY_REGISTRATION_FEE'),
48+
'did_registration' => env('DID_REGISTRATION_FEE'),
49+
'did_update' => env('DID_UPDATE_FEE'),
50+
'vc_issuing' => env('VC_ISSUING_FEE'),
51+
'vc_proofing' => env('VC_PROOFING_FEE'),
52+
'vc_verifying' => env('VC_VERIFYING_FEE'),
53+
'vc_revoking' => env('VC_REVOKING_FEE'),
54+
],
55+
'subscription_prices' => [
56+
'monthly' => env('KEY_REGISTRATION_FEE', 0.01),
57+
'anual' => env('DID_REGISTRATION_FEE', 0.1),
58+
],
59+
60+
];

deprecated.png

-51 KB
Binary file not shown.

docs/Connection.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Connection Class
2+
3+
The `Connection` class is part of the `Attestto\SolanaPhpSdk` namespace and extends the `Program` class. It provides methods to interact with the Solana network.
4+
5+
## Methods
6+
7+
### `getAccountInfo(string $pubKey): array`
8+
9+
This method retrieves the account information for a given public key. It throws an `AccountNotFoundException` if the account is not found.
10+
11+
### `getBalance(string $pubKey): float`
12+
13+
This method retrieves the balance for a given public key.
14+
15+
### `getConfirmedTransaction(string $transactionSignature): array|null`
16+
17+
This method retrieves a confirmed transaction using the transaction signature.
18+
19+
### `getTransaction(string $transactionSignature): array|null`
20+
21+
This method retrieves a transaction using the transaction signature. This method is only available in solana-core v1.7 or newer.
22+
23+
### `getLatestBlockhash(?Commitment $commitment): array`
24+
25+
This method retrieves the latest blockhash.
26+
27+
### `sendTransaction(Transaction $transaction, array $signers, array $params = []): array|Response`
28+
29+
This method sends a transaction. It signs the transaction with the provided signers and serializes it to a binary string.
30+
31+
### `simulateTransaction(Transaction $transaction, array $signers, array $params = []): array|Response`
32+
33+
This method simulates a transaction. It signs the transaction with the provided signers and serializes it to a binary string.
34+

docs/SplToken/SplTokenTest.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
namespace SplToken;
4+
5+
use Attestto\SolanaPhpSdk\Programs\SplTokenProgram;
6+
use Attestto\SolanaPhpSdk\Tests\TestCase;
7+
8+
class SPLTokenTest extends TestCase
9+
{
10+
private $splTokenProgram;
11+
12+
public function setUp(): void
13+
{
14+
$client = $this->assembleClient('POST', []);
15+
$this->splTokenProgram = new SplTokenProgram($client);
16+
}
17+
18+
// public function testGetAssociatedTokenAddressSync()
19+
// {
20+
// $mockMint = $this->createMock(PublicKey::class);
21+
// $mockOwner = $this->createMock(PublicKey::class);
22+
// $mockOwner->method('toBuffer')->willReturn('buffer');
23+
// $mockOwner->method('isOnCurve')->willReturn(true);
24+
//
25+
// $mockProgramId = 'programId';
26+
// $mockAssociatedTokenProgramId = 'associatedTokenProgramId';
27+
//
28+
// $result = $this->splToken->getAssociatedTokenAddressSync(
29+
// $mockMint,
30+
// $mockOwner,
31+
// false,
32+
// $mockProgramId,
33+
// $mockAssociatedTokenProgramId
34+
// );
35+
//
36+
// $this->assertInstanceOf(PublicKey::class, $result);
37+
// }
38+
//
39+
// public function testGetAssociatedTokenAddressSyncThrowsException()
40+
// {
41+
// $this->expectException(TokenOwnerOffCurveError::class);
42+
//
43+
// $mockMint = $this->createMock(PublicKey::class);
44+
// $mockOwner = $this->createMock(PublicKey::class);
45+
// $mockOwner->method('toBuffer')->willReturn('buffer');
46+
// $mockOwner->method('isOnCurve')->willReturn(false);
47+
//
48+
// $mockProgramId = 'programId';
49+
// $mockAssociatedTokenProgramId = 'associatedTokenProgramId';
50+
//
51+
// $this->splToken->getAssociatedTokenAddressSync(
52+
// $mockMint,
53+
// $mockOwner,
54+
// false,
55+
// $mockProgramId,
56+
// $mockAssociatedTokenProgramId
57+
// );
58+
// }
59+
}

phpUnit.xml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd"
44
bootstrap="vendor/autoload.php"
5-
65
executionOrder="depends,defects"
7-
8-
96
beStrictAboutOutputDuringTests="true"
107
failOnRisky="true"
118
failOnWarning="true">
129
<testsuites>
13-
<testsuite name="default">
14-
<directory>tests</directory>
10+
<testsuite name="Unit">
11+
<directory suffix="Test.php">./tests/Unit</directory>
12+
</testsuite>
13+
<testsuite name="Feature">
14+
<directory suffix="Test.php">./tests/Feature</directory>
1515
</testsuite>
1616
</testsuites>
1717
<coverage>
18-
<!-- <include>-->
19-
<!-- <directory suffix=".php">src</directory>-->
20-
<!-- </include>-->
21-
<!-- <report>-->
22-
<!-- <html output="coverage" />-->
23-
<!-- </report>-->
18+
<include>
19+
<directory suffix=".php">src</directory>
20+
</include>
21+
<report>
22+
<html output="coverage" />
23+
</report>
2424
</coverage>
2525
<source restrictDeprecations="true" restrictNotices="true" restrictWarnings="true">
2626
<include>

src/Connection.php

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,19 @@
33
namespace Attestto\SolanaPhpSdk;
44

55
use Attestto\SolanaPhpSdk\Exceptions\AccountNotFoundException;
6+
use Attestto\SolanaPhpSdk\Exceptions\GenericException;
7+
use Attestto\SolanaPhpSdk\Exceptions\InvalidIdResponseException;
8+
use Attestto\SolanaPhpSdk\Exceptions\MethodNotFoundException;
69
use Attestto\SolanaPhpSdk\Util\Commitment;
10+
use Illuminate\Http\Client\Response;
11+
use Psr\Http\Client\ClientExceptionInterface;
12+
use SodiumException;
713

14+
/**
15+
* Class Connection
16+
* @package Attestto\SolanaPhpSdk
17+
* https://solana-labs.github.io/solana-web3.js/classes/Connection.html
18+
*/
819
class Connection extends Program
920
{
1021
/**
@@ -55,27 +66,40 @@ public function getTransaction(string $transactionSignature): array|null
5566
* @param Commitment|null $commitment
5667
* @return array
5768
* @throws Exceptions\GenericException|Exceptions\MethodNotFoundException|Exceptions\InvalidIdResponseException
69+
* Deprecated: Use getLatestBlockhash instead
5870
*/
5971
public function getRecentBlockhash(?Commitment $commitment = null): array
6072
{
6173
return $this->client->call('getRecentBlockhash', array_filter([$commitment]))['value'];
6274
}
6375

76+
/**
77+
* @param Commitment|null $commitment CONFIRMED | 'finalized'
78+
* @return array
79+
* @throws Exceptions\GenericException|Exceptions\MethodNotFoundException|Exceptions\InvalidIdResponseException|\Psr\Http\Client\ClientExceptionInterface
80+
*/
81+
public function getLatestBlockhash(?Commitment $commitment): array
82+
{
83+
return $this->client->call('getLatestBlockhash', array_filter([$commitment]))['value'];
84+
}
85+
6486
/**
6587
* @param Transaction $transaction
6688
* @param Keypair[] $signers
6789
* @param array $params
68-
* @return array|\Illuminate\Http\Client\Response
69-
* @throws Exceptions\GenericException
70-
* @throws Exceptions\InvalidIdResponseException
71-
* @throws Exceptions\MethodNotFoundException
90+
* @return array|Response
91+
* @throws GenericException
92+
* @throws InvalidIdResponseException
93+
* @throws MethodNotFoundException
94+
* @throws ClientExceptionInterface
95+
* @throws SodiumException
96+
* TODO Add Support for Versiones TXns
7297
*/
73-
public function sendTransaction(Transaction $transaction, array $signers, array $params = [])
98+
public function sendTransaction(Transaction $transaction, array $signers, array $params = []): array|Response
7499
{
75100
if (! $transaction->recentBlockhash) {
76-
$transaction->recentBlockhash = $this->getRecentBlockhash()['blockhash'];
101+
$transaction->recentBlockhash = $this->getLatestBlockhash()['blockhash'];
77102
}
78-
79103
$transaction->sign(...$signers);
80104

81105
$rawBinaryString = $transaction->serialize(false);
@@ -90,13 +114,12 @@ public function sendTransaction(Transaction $transaction, array $signers, array
90114

91115
return $this->client->call('sendTransaction', [$hashString, $send_params]);
92116
}
93-
94-
117+
95118
/**
96119
* @param Transaction $transaction
97120
* @param Keypair[] $signers
98121
* @param array $params
99-
* @return array|\Illuminate\Http\Client\Response
122+
* @return array|Response
100123
* @throws Exceptions\GenericException
101124
* @throws Exceptions\InvalidIdResponseException
102125
* @throws Exceptions\MethodNotFoundException

0 commit comments

Comments
 (0)