-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e62c330
commit 61fde17
Showing
75 changed files
with
8,471 additions
and
1,685 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { PublicKey } from '@solana/web3.js'; | ||
|
||
type Networks = { [label: string]: Network }; | ||
|
||
export type Network = { | ||
label: string; | ||
// Cluster. | ||
url: string; | ||
explorerClusterSuffix: string; | ||
|
||
// Mints and god accounts. | ||
srm: PublicKey; | ||
msrm: PublicKey; | ||
god: PublicKey; | ||
megaGod: PublicKey; | ||
|
||
// Programs. | ||
registryProgramId: PublicKey; | ||
stakeProgramId: PublicKey; | ||
lockupProgramId: PublicKey; | ||
retbufProgramId: PublicKey; | ||
metaEntityProgramId: PublicKey; | ||
|
||
// Program accounts. | ||
safe: PublicKey; | ||
registrar: PublicKey; | ||
rewardEventQueue: PublicKey; | ||
retbuf: PublicKey; | ||
|
||
// Misc. | ||
defaultEntity: PublicKey; | ||
}; | ||
|
||
export const networks: Networks = { | ||
devnet: { | ||
// Cluster. | ||
label: 'Devnet', | ||
url: 'https://devnet.solana.com', | ||
explorerClusterSuffix: 'devnet', | ||
|
||
srm: new PublicKey('DLRk8GWo1YF4Kc5DrVQkaMDQti27VVGzR3Y1Tm8Frpyj'), | ||
msrm: new PublicKey('CrtnNeZg3tnRKnxxYxjsnkYNk1xRjhEci8ZJhuRAU7WX'), | ||
god: new PublicKey('HtbxQ8ZfenVhw5G8GSVK5nymbNXXo37fwwp9sjAjaBEx'), | ||
megaGod: new PublicKey('DKmDLZUUkfaFEQ3PWYezmoL3BwaEt1QHHYrLGPWuCMiV'), | ||
registryProgramId: new PublicKey( | ||
'G5W9X8gjf2v8QH3D7aQrFhHSxMK7sxB1wQQpKPue2Nnv', | ||
), | ||
stakeProgramId: new PublicKey( | ||
'APU8W2tEUhiAAeaiEtYKdaMtB3KrBQXqyiinvjGurvBf', | ||
), | ||
lockupProgramId: new PublicKey( | ||
'Bk9M7yycNZiKkFtKDzzLQAhvQjWMqxYSFJzxFspL9uJ', | ||
), | ||
retbufProgramId: new PublicKey( | ||
'3w2Q6XjS2BDpxHVRzs8oWbNuH7ivZp1mVo3mbq318oyG', | ||
), | ||
metaEntityProgramId: new PublicKey( | ||
'H6PGzjRWMBd2dajxL5ZjDc9LU4onSB5PbrqHS94Hgoed', | ||
), | ||
registrar: new PublicKey('2w6i8FLi7DJ2UrTTGeKwkotgvM2k9FtfcP7vLfzT5pnx'), | ||
rewardEventQueue: new PublicKey( | ||
'ozD1sY1rdizmPkr29PCyrWVrUC73HLQurTnvtsFmC6P', | ||
), | ||
safe: new PublicKey('2u8tjVJuz8P7EYa4WL3x2oHndjZLZNfA4vkWaa3SP75f'), | ||
retbuf: new PublicKey('8PUeeTe22fHJqTVB5wahQmqZjaHzDPC7arYhWSnTLqZA'), | ||
defaultEntity: new PublicKey( | ||
'GQmf9Ag2EHC6RyJuxyEkUMMRzB8zhhSEq8Bmae7Wxyhi', | ||
), | ||
}, | ||
|
||
// Fill in with your local cluster addresses. | ||
localhost: { | ||
// Cluster. | ||
label: 'Localhost', | ||
url: 'http://localhost:8899', | ||
explorerClusterSuffix: 'localhost', | ||
|
||
srm: new PublicKey('49uPApDJo81q2ruSV7QGcKbWvrvidwkuwiBdNGqNLEDj'), | ||
msrm: new PublicKey('5WzVn4fzZwL1pHp3o1SnQwNhB6YjfinhQNZMRtv4PDRV'), | ||
god: new PublicKey('8WmKCQiuBo97cGE7NTo6Gvfec8fi9sMCwbdyToXk99eS'), | ||
megaGod: new PublicKey('4L6KRfJ2G1Gp59Cmav3Wux6wuyArvuhXx1R3ozCDF7Zy'), | ||
registryProgramId: new PublicKey( | ||
'7VA5eMqGwEvkkRsgrz28uFeqAKAMQ32TBHpTakKpWSBT', | ||
), | ||
stakeProgramId: new PublicKey( | ||
'FcznkS6Yo6mfhG6Rp49A5GTiag9AE9g8sZdfb5tUV271', | ||
), | ||
lockupProgramId: new PublicKey( | ||
'9quusFhQuZPHTCWRNAiZspJtei639KNgmaJNFYUxbPwZ', | ||
), | ||
retbufProgramId: new PublicKey( | ||
'shmem4EWT2sPdVGvTZCzXXRAURL9G5vpPxNwSeKhHUL', | ||
), | ||
metaEntityProgramId: new PublicKey( | ||
'Ftm99ezozbjdSZJBU3raB316jdijGDWx1uSxRDwK2UUZ', | ||
), | ||
registrar: new PublicKey('C8kZJRjMfQAC6Gjn8s25oHsDwQegMebWafDUBacmKCxR'), | ||
rewardEventQueue: new PublicKey( | ||
'5a4WCYb4bPWJE7e8VGdr5ntUsapE6z9RBpc4Ci5CYfWn', | ||
), | ||
safe: new PublicKey('Gqhc69ywiiWTaLEJArC6pqHwzPCqGRmNMaiLUbsD5jqU'), | ||
retbuf: new PublicKey('7XxFAvQ9HoHch1jH1tJerPcAJ4zg65ZhusdMWeK5ZPx'), | ||
defaultEntity: new PublicKey( | ||
'AX1XPYdcgiSrkKupNr8ywWFE1sNe6Ln79c5qyHGsRvju', | ||
), | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { | ||
Commitment, | ||
Connection, | ||
RpcResponseAndContext, | ||
SimulatedTransactionResponse, | ||
Transaction, | ||
} from '@solana/web3.js'; | ||
|
||
/** Copy of Connection.simulateTransaction that takes a commitment parameter. */ | ||
export async function simulateTransaction( | ||
connection: Connection, | ||
transaction: Transaction, | ||
commitment: Commitment, | ||
): Promise<RpcResponseAndContext<SimulatedTransactionResponse>> { | ||
// @ts-ignore | ||
transaction.recentBlockhash = await connection._recentBlockhash( | ||
// @ts-ignore | ||
connection._disableBlockhashCaching, | ||
); | ||
|
||
const signData = transaction.serializeMessage(); | ||
// @ts-ignore | ||
const wireTransaction = transaction._serialize(signData); | ||
const encodedTransaction = wireTransaction.toString('base64'); | ||
const config: any = { encoding: 'base64', commitment }; | ||
const args = [encodedTransaction, config]; | ||
|
||
// @ts-ignore | ||
const res = await connection._rpcRequest('simulateTransaction', args); | ||
if (res.error) { | ||
throw new Error('failed to simulate transaction: ' + res.error.message); | ||
} | ||
return res.result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { Connection, PublicKey } from '@solana/web3.js'; | ||
import { ProgramAccount } from './'; | ||
import { AccountInfo as TokenAccount } from '@solana/spl-token'; | ||
import { TokenInstructions } from '@project-serum/serum'; | ||
import * as bs58 from 'bs58'; | ||
import * as BufferLayout from 'buffer-layout'; | ||
|
||
export async function getOwnedTokenAccounts( | ||
connection: Connection, | ||
publicKey: PublicKey, | ||
): Promise<ProgramAccount<TokenAccount>[]> { | ||
let filters = getOwnedAccountsFilters(publicKey); | ||
// @ts-ignore | ||
let resp = await connection._rpcRequest('getProgramAccounts', [ | ||
TokenInstructions.TOKEN_PROGRAM_ID.toBase58(), | ||
{ | ||
commitment: connection.commitment, | ||
filters, | ||
}, | ||
]); | ||
if (resp.error) { | ||
throw new Error( | ||
'failed to get token accounts owned by ' + | ||
publicKey.toBase58() + | ||
': ' + | ||
resp.error.message, | ||
); | ||
} | ||
return ( | ||
resp.result | ||
// @ts-ignore | ||
.map(({ pubkey, account: { data } }) => { | ||
data = bs58.decode(data); | ||
return { | ||
publicKey: new PublicKey(pubkey), | ||
account: parseTokenAccountData(data), | ||
}; | ||
}) | ||
); | ||
} | ||
|
||
// todo: remove | ||
export const ACCOUNT_LAYOUT = BufferLayout.struct([ | ||
BufferLayout.blob(32, 'mint'), | ||
BufferLayout.blob(32, 'owner'), | ||
BufferLayout.nu64('amount'), | ||
BufferLayout.blob(93), | ||
]); | ||
export const MINT_LAYOUT = BufferLayout.struct([ | ||
BufferLayout.blob(44), | ||
BufferLayout.u8('decimals'), | ||
BufferLayout.blob(37), | ||
]); | ||
|
||
export function parseTokenAccountData(data: any) { | ||
// @ts-ignore | ||
let { mint, owner, amount } = ACCOUNT_LAYOUT.decode(data); | ||
return { | ||
mint: new PublicKey(mint), | ||
owner: new PublicKey(owner), | ||
amount, | ||
}; | ||
} | ||
|
||
// @ts-ignore | ||
export function parseMintData(data) { | ||
// @ts-ignore | ||
let { decimals } = MINT_LAYOUT.decode(data); | ||
return { decimals }; | ||
} | ||
|
||
// @ts-ignore | ||
export function getOwnedAccountsFilters(publicKey: PublicKey) { | ||
return [ | ||
{ | ||
memcmp: { | ||
// @ts-ignore | ||
offset: ACCOUNT_LAYOUT.offsetOf('owner'), | ||
bytes: publicKey.toBase58(), | ||
}, | ||
}, | ||
{ | ||
dataSize: ACCOUNT_LAYOUT.span, | ||
}, | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.