Skip to content

Commit

Permalink
feat: sync solana endpoints with api
Browse files Browse the repository at this point in the history
  • Loading branch information
ErnoW committed Mar 24, 2023
1 parent 9575877 commit ff40a18
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 42 deletions.
6 changes: 6 additions & 0 deletions .changeset/violet-falcons-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@moralisweb3/common-sol-utils': patch
'@moralisweb3/sol-api': patch
---

Sync SolApi with the api, adding name and symbol properties
1 change: 1 addition & 0 deletions packages/common/solUtils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"test": "jest --runInBand --detectOpenHandles --forceExit --ci",
"test:coverage": "yarn run test --coverage --coverageReporters json-summary",
"test:watch": "yarn run test --watch",
"gen:api-types": "openapi-typescript https://solana-gateway.moralis.io/api-json --output src/operations/openapi.ts",
"lint": "eslint . --ext .js,.ts,.tsx,jsx",
"clean": "rm -rf lib && rm -rf ./node_modules/.cache/nx",
"build": "rollup -c",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ function deserializeResponse(jsonResponse: GetNFTsJSONResponse) {
return {
associatedTokenAddress: SolAddress.create(item.associatedTokenAddress),
mint: SolAddress.create(item.mint),
name: item.name,
symbol: item.symbol,
};
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,17 @@ function deserializeResponse(jsonResponse: GetPortfolioJSONResponse) {
return {
associatedTokenAddress: SolAddress.create(nft.associatedTokenAddress),
mint: SolAddress.create(nft.mint),
name: nft.name,
symbol: nft.symbol,
};
}),
tokens: jsonResponse.tokens.map((token) => {
return {
associatedTokenAddress: SolAddress.create(token.associatedTokenAddress),
mint: SolAddress.create(token.mint),
amount: SolNative.create(token.amountRaw, 'lamports'),
name: token.name,
symbol: token.symbol,
};
}),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ function deserializeResponse(jsonResponse: GetSPLJSONResponse) {
associatedTokenAddress: SolAddress.create(token.associatedTokenAddress),
mint: SolAddress.create(token.mint),
amount: SolNative.create(token.amountRaw, 'lamports'),
name: token.name,
symbol: token.symbol,
};
});
}
Expand Down
22 changes: 19 additions & 3 deletions packages/common/solUtils/src/operations/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@ export interface components {
SPLTokenBalance: {
associatedTokenAddress: string;
mint: string;
name: string;
symbol: string;
amount: string;
amountRaw: string;
decimals: number;
};
SPLNFT: {
associatedTokenAddress: string;
mint: string;
name: string;
symbol: string;
};
Portfolio: {
nativeBalance: components["schemas"]["NativeBalance"];
Expand Down Expand Up @@ -87,7 +91,9 @@ export interface operations {
balance: {
parameters: {
path: {
/** The network to query */
network: "mainnet" | "devnet";
/** The address for which the native balance will be checked */
address: string;
};
};
Expand All @@ -108,7 +114,9 @@ export interface operations {
getSPL: {
parameters: {
path: {
/** The network to query */
network: "mainnet" | "devnet";
/** The address for which token balances will be checked */
address: string;
};
};
Expand All @@ -129,7 +137,9 @@ export interface operations {
getNFTs: {
parameters: {
path: {
/** The network to query */
network: "mainnet" | "devnet";
/** The address of the contract */
address: string;
};
};
Expand All @@ -150,8 +160,10 @@ export interface operations {
getPortfolio: {
parameters: {
path: {
address: string;
/** The network to query */
network: "mainnet" | "devnet";
/** The address of the token contract */
address: string;
};
};
responses: {
Expand All @@ -171,8 +183,10 @@ export interface operations {
getNFTMetadata: {
parameters: {
path: {
address: string;
/** The network to query */
network: "mainnet" | "devnet";
/** The address of the contract */
address: string;
};
};
responses: {
Expand All @@ -192,8 +206,10 @@ export interface operations {
getTokenPrice: {
parameters: {
path: {
address: string;
/** The network to query */
network: "mainnet";
/** The address of the token contract */
address: string;
};
};
responses: {
Expand Down
18 changes: 10 additions & 8 deletions packages/solApi/integration/mocks/endpoints/getNFT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,22 @@ export const mockGetNFTSol = MockScenarios.create(
{
condition: {
network: 'mainnet',
address: '5xoBq7f7CDgZwqHrDBdRWM84ExRetg4gZq93dyJtoSwp',
address: 'EJpLyTeE8XHG9CeREeHd6pr6hNhaRnTRJx4Z5DPhEJJ6',
},
response: [
{
associatedTokenAddress: 'DU1MLkMBperU2nmjjZSwhaSDQxxg3Jtu8XPyroM6fkmu',
mint: '9spQWuJozohLUK1ReyhsWUrkgDfDMS2U8cMwMoxifkxM',
associatedTokenAddress: 'Aymvy5sNtxRpUBFT19nNetsGb4VBpmb6qyPs2ybGPUcr',
mint: '9PN8gNqJy5mVnr8PJSaiKULG2inbTZxm4Xwgc2LM6x5Z',
name: 'Nug 5585',
symbol: 'METAWANA',
},
{
associatedTokenAddress: 'GyxpmbNDAfkQ1VF5bAVkx4mu7C6T9jY3aQjAavFrJRei',
mint: 'D1Uo5XbWz75TszVLaH7GSttN4x7H4jUEtbmGSEfG3SRz',
associatedTokenAddress: 'Gshsqnk1qWDy1PcryceyjQQnSvUzqFnmiE9LLwvFPZdx',
mint: '5E56nvwdbFSyT52Wp4Kw3FBHpxdh5szVpvS8ASUX7nn8',
name: 'Centaur #105',
symbol: 'CREATURE',
},
// TODO: 'any' should be deleted
// eslint-disable-next-line @typescript-eslint/no-explicit-any
] as any,
],
},
],
);
58 changes: 54 additions & 4 deletions packages/solApi/integration/mocks/endpoints/getPortfolio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,62 @@ export const mockGetPortfolioSol = MockScenarios.create(
{
condition: {
network: 'mainnet',
address: '5xoBq7f7CDgZwqHrDBdRWM84ExRetg4gZq93dyJtoSwp',
address: 'EJpLyTeE8XHG9CeREeHd6pr6hNhaRnTRJx4Z5DPhEJJ6',
},
response: {
tokens: [],
nfts: [],
nativeBalance: { lamports: '1461600', solana: '0.0014616' },
tokens: [
{
associatedTokenAddress: 'FaygwmWV2RGQVABXdvaPoa4Kar8EcjpaQcB4czcy4pUJ',
mint: 'EL4YBAq2vnh2oQe454x64f4WJGxrywtUtxhJpv4cx2ks',
amountRaw: '2',
amount: '2',
decimals: '0',
name: 'Cets Ears',
symbol: 'goons',
},
{
associatedTokenAddress: 'J3sQDCWQQuZRCSgW7BWZ8s8Zoz16mprPxoCuryo6YXUX',
mint: 'VVWAy5U2KFd1p8AdchjUxqaJbZPBeP5vUQRZtAy8hyc',
amountRaw: '7777000000000',
amount: '7777',
decimals: '9',
name: "Flip.gg | Code:'MARCH23'",
symbol: 'Free $0.33',
},
],
nfts: [
{
associatedTokenAddress: 'Aymvy5sNtxRpUBFT19nNetsGb4VBpmb6qyPs2ybGPUcr',
mint: '9PN8gNqJy5mVnr8PJSaiKULG2inbTZxm4Xwgc2LM6x5Z',
amountRaw: '1',
amount: '1',
decimals: '0',
name: 'Nug 5585',
symbol: 'METAWANA',
},
{
associatedTokenAddress: 'Gshsqnk1qWDy1PcryceyjQQnSvUzqFnmiE9LLwvFPZdx',
mint: '5E56nvwdbFSyT52Wp4Kw3FBHpxdh5szVpvS8ASUX7nn8',
amountRaw: '1',
amount: '1',
decimals: '0',
name: 'Centaur #105',
symbol: 'CREATURE',
},
{
associatedTokenAddress: 'BBbk2gueQr8zDVf6whMD7snPZnJ8B8GedeQQo3qnLq3y',
mint: '5J3wusYQsCDqBsapYoajGUQwiSJN4CTPXAL4P5QwejvN',
amountRaw: '1',
amount: '1',
decimals: '0',
name: 'Goonie #365',
symbol: 'GOON',
},
],
nativeBalance: {
lamports: '902329912',
solana: '0.902329912',
},
},
},
],
Expand Down
30 changes: 16 additions & 14 deletions packages/solApi/integration/mocks/endpoints/getSPL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,28 @@ export const mockGetSPLSol = MockScenarios.create(
{
condition: {
network: 'mainnet',
address: '5xoBq7f7CDgZwqHrDBdRWM84ExRetg4gZq93dyJtoSwp',
address: 'EJpLyTeE8XHG9CeREeHd6pr6hNhaRnTRJx4Z5DPhEJJ6',
},
response: [
{
associatedTokenAddress: 'BBsN4yXTFQkmCqiDDUA9VZfsv2xc4BMTan2uk4V9AVvG',
mint: 'DRQBDBEWmwWGK13fRTLhSPzjbvMSUavhV6nW4RUH8W6T',
amountRaw: '10000000000',
amount: '100',
decimals: '8',
associatedTokenAddress: 'FaygwmWV2RGQVABXdvaPoa4Kar8EcjpaQcB4czcy4pUJ',
mint: 'EL4YBAq2vnh2oQe454x64f4WJGxrywtUtxhJpv4cx2ks',
amountRaw: '2',
amount: '2',
decimals: '0',
name: 'Cets Ears',
symbol: 'goons',
},
{
associatedTokenAddress: 'ETWQorqbccyF5c9cL94yG6aywB3TLi948VoCxg5ug9eb',
mint: '4hpngEp1v3CXpeKB81Gw4sv7YvwUVRKvY3SGag9ND8Q4',
amountRaw: '2009990',
amount: '2009990',
decimals: '0',
associatedTokenAddress: 'J3sQDCWQQuZRCSgW7BWZ8s8Zoz16mprPxoCuryo6YXUX',
mint: 'VVWAy5U2KFd1p8AdchjUxqaJbZPBeP5vUQRZtAy8hyc',
amountRaw: '7777000000000',
amount: '7777',
decimals: '9',
name: "Flip.gg | Code:'MARCH23'",
symbol: 'Free $0.33',
},
// TODO: 'any' should be deleted
// eslint-disable-next-line @typescript-eslint/no-explicit-any
] as any,
],
},
],
);
10 changes: 7 additions & 3 deletions packages/solApi/integration/test/getNFT.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ describe('Moralis SolApi', () => {
it('should get the NFTs of an account ', async () => {
const result = await SolApi.account.getNFTs({
network: 'mainnet',
address: '5xoBq7f7CDgZwqHrDBdRWM84ExRetg4gZq93dyJtoSwp',
address: 'EJpLyTeE8XHG9CeREeHd6pr6hNhaRnTRJx4Z5DPhEJJ6',
});
const nfts = result.result;

expect(nfts.length).toBe(2);
expect(nfts[0].mint.toString()).toBe('9spQWuJozohLUK1ReyhsWUrkgDfDMS2U8cMwMoxifkxM');
expect(nfts[0].associatedTokenAddress.toString()).toBe('DU1MLkMBperU2nmjjZSwhaSDQxxg3Jtu8XPyroM6fkmu');
const nft = nfts[0];

expect(nft.mint.toString()).toBe('9PN8gNqJy5mVnr8PJSaiKULG2inbTZxm4Xwgc2LM6x5Z');
expect(nft.associatedTokenAddress.toString()).toBe('Aymvy5sNtxRpUBFT19nNetsGb4VBpmb6qyPs2ybGPUcr');
expect(nft.name).toBe('Nug 5585');
expect(nft.symbol).toBe('METAWANA');
});
});
21 changes: 18 additions & 3 deletions packages/solApi/integration/test/getPortfolio.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,26 @@ describe('Moralis SolApi', () => {
});

it('should get the portfolio of an account ', async () => {
const result = await SolApi.account.getPortfolio({
const { result } = await SolApi.account.getPortfolio({
network: 'mainnet',
address: '5xoBq7f7CDgZwqHrDBdRWM84ExRetg4gZq93dyJtoSwp',
address: 'EJpLyTeE8XHG9CeREeHd6pr6hNhaRnTRJx4Z5DPhEJJ6',
});

expect(result.result.nativeBalance.toString()).toBe('1461600');
expect(result.nativeBalance.toString()).toBe('902329912');
expect(result.tokens.length).toBe(2);
expect(result.tokens.length).toBe(2);

const token = result.tokens[0];
expect(token.associatedTokenAddress.toString()).toBe('FaygwmWV2RGQVABXdvaPoa4Kar8EcjpaQcB4czcy4pUJ');
expect(token.mint.toString()).toBe('EL4YBAq2vnh2oQe454x64f4WJGxrywtUtxhJpv4cx2ks');
expect(token.amount.toString()).toBe('2');
expect(token.name).toBe('Cets Ears');
expect(token.symbol).toBe('goons');

const nft = result.nfts[0];
expect(nft.associatedTokenAddress.toString()).toBe('Aymvy5sNtxRpUBFT19nNetsGb4VBpmb6qyPs2ybGPUcr');
expect(nft.mint.toString()).toBe('9PN8gNqJy5mVnr8PJSaiKULG2inbTZxm4Xwgc2LM6x5Z');
expect(nft.name).toBe('Nug 5585');
expect(nft.symbol).toBe('METAWANA');
});
});
17 changes: 10 additions & 7 deletions packages/solApi/integration/test/getSPL.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ describe('Moralis SolApi', () => {
});

it('returns SPL', async () => {
const result = await SolApi.account.getSPL({
const { result } = await SolApi.account.getSPL({
network: 'mainnet',
address: '5xoBq7f7CDgZwqHrDBdRWM84ExRetg4gZq93dyJtoSwp',
address: 'EJpLyTeE8XHG9CeREeHd6pr6hNhaRnTRJx4Z5DPhEJJ6',
});
const spl = result.result;

expect(spl.length).toBe(2);
expect(spl[0].associatedTokenAddress.toString()).toBe('BBsN4yXTFQkmCqiDDUA9VZfsv2xc4BMTan2uk4V9AVvG');
expect(spl[0].mint.toString()).toBe('DRQBDBEWmwWGK13fRTLhSPzjbvMSUavhV6nW4RUH8W6T');
expect(spl[0].amount.toString()).toBe('10000000000');
expect(result.length).toBe(2);

const token = result[0];
expect(token.associatedTokenAddress.toString()).toBe('FaygwmWV2RGQVABXdvaPoa4Kar8EcjpaQcB4czcy4pUJ');
expect(token.mint.toString()).toBe('EL4YBAq2vnh2oQe454x64f4WJGxrywtUtxhJpv4cx2ks');
expect(token.amount.toString()).toBe('2');
expect(token.name).toBe('Cets Ears');
expect(token.symbol).toBe('goons');
});
});

0 comments on commit ff40a18

Please sign in to comment.