-
Notifications
You must be signed in to change notification settings - Fork 69
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
af5d176
commit 0be4b86
Showing
12 changed files
with
594 additions
and
9 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
Binary file not shown.
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
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,34 @@ | ||
import { Program, web3 } from "@coral-xyz/anchor"; | ||
import { TransferHookCounter } from "./transfer_hook_counter"; | ||
import { getExtraAccountMetaAddress } from "@solana/spl-token"; | ||
|
||
export async function createExtraAccountMetaListAndCounter( | ||
program: Program<TransferHookCounter>, | ||
mint: web3.PublicKey | ||
) { | ||
const extraAccountMetaList = getExtraAccountMetaAddress( | ||
mint, | ||
program.programId | ||
); | ||
const counterAccount = deriveCounter(mint, program.programId); | ||
|
||
await program.methods | ||
.initializeExtraAccountMetaList() | ||
.accounts({ | ||
mint, | ||
counterAccount, | ||
extraAccountMetaList, | ||
}) | ||
.rpc(); | ||
|
||
return [extraAccountMetaList, counterAccount]; | ||
} | ||
|
||
export function deriveCounter(mint: web3.PublicKey, programId: web3.PublicKey) { | ||
const [counter] = web3.PublicKey.findProgramAddressSync( | ||
[Buffer.from("counter"), mint.toBuffer()], | ||
programId | ||
); | ||
|
||
return counter; | ||
} |
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,28 @@ | ||
import { AnchorProvider, Program, Wallet, web3 } from "@coral-xyz/anchor"; | ||
import { | ||
TransferHookCounter, | ||
IDL as TransferHookCounterIDL, | ||
} from "./transfer_hook_counter"; | ||
import { Connection } from "@solana/web3.js"; | ||
|
||
export const TRANSFER_HOOK_COUNTER_PROGRAM_ID = new web3.PublicKey( | ||
"EBZDYx7599krFc4m2govwBdZcicr4GgepqC78m71nsHS" | ||
); | ||
|
||
export function createTransferHookCounterProgram( | ||
wallet: Wallet, | ||
programId: web3.PublicKey, | ||
connection: Connection | ||
): Program<TransferHookCounter> { | ||
const provider = new AnchorProvider(connection, wallet, { | ||
maxRetries: 3, | ||
}); | ||
|
||
const program = new Program<TransferHookCounter>( | ||
TransferHookCounterIDL, | ||
programId, | ||
provider | ||
); | ||
|
||
return program; | ||
} |
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,219 @@ | ||
export type TransferHookCounter = { | ||
"version": "0.1.0", | ||
"name": "transfer_hook_counter", | ||
"instructions": [ | ||
{ | ||
"name": "initializeExtraAccountMetaList", | ||
"accounts": [ | ||
{ | ||
"name": "payer", | ||
"isMut": true, | ||
"isSigner": true | ||
}, | ||
{ | ||
"name": "extraAccountMetaList", | ||
"isMut": true, | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "mint", | ||
"isMut": false, | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "counterAccount", | ||
"isMut": true, | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "tokenProgram", | ||
"isMut": false, | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "associatedTokenProgram", | ||
"isMut": false, | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "systemProgram", | ||
"isMut": false, | ||
"isSigner": false | ||
} | ||
], | ||
"args": [] | ||
}, | ||
{ | ||
"name": "transferHook", | ||
"accounts": [ | ||
{ | ||
"name": "sourceToken", | ||
"isMut": false, | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "mint", | ||
"isMut": false, | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "destinationToken", | ||
"isMut": false, | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "owner", | ||
"isMut": false, | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "extraAccountMetaList", | ||
"isMut": false, | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "counterAccount", | ||
"isMut": true, | ||
"isSigner": false | ||
} | ||
], | ||
"args": [ | ||
{ | ||
"name": "amount", | ||
"type": "u64" | ||
} | ||
] | ||
} | ||
], | ||
"accounts": [ | ||
{ | ||
"name": "counterAccount", | ||
"type": { | ||
"kind": "struct", | ||
"fields": [ | ||
{ | ||
"name": "counter", | ||
"type": "u32" | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"errors": [ | ||
{ | ||
"code": 6000, | ||
"name": "AmountTooBig", | ||
"msg": "The amount is too big" | ||
} | ||
] | ||
}; | ||
|
||
export const IDL: TransferHookCounter = { | ||
"version": "0.1.0", | ||
"name": "transfer_hook_counter", | ||
"instructions": [ | ||
{ | ||
"name": "initializeExtraAccountMetaList", | ||
"accounts": [ | ||
{ | ||
"name": "payer", | ||
"isMut": true, | ||
"isSigner": true | ||
}, | ||
{ | ||
"name": "extraAccountMetaList", | ||
"isMut": true, | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "mint", | ||
"isMut": false, | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "counterAccount", | ||
"isMut": true, | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "tokenProgram", | ||
"isMut": false, | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "associatedTokenProgram", | ||
"isMut": false, | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "systemProgram", | ||
"isMut": false, | ||
"isSigner": false | ||
} | ||
], | ||
"args": [] | ||
}, | ||
{ | ||
"name": "transferHook", | ||
"accounts": [ | ||
{ | ||
"name": "sourceToken", | ||
"isMut": false, | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "mint", | ||
"isMut": false, | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "destinationToken", | ||
"isMut": false, | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "owner", | ||
"isMut": false, | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "extraAccountMetaList", | ||
"isMut": false, | ||
"isSigner": false | ||
}, | ||
{ | ||
"name": "counterAccount", | ||
"isMut": true, | ||
"isSigner": false | ||
} | ||
], | ||
"args": [ | ||
{ | ||
"name": "amount", | ||
"type": "u64" | ||
} | ||
] | ||
} | ||
], | ||
"accounts": [ | ||
{ | ||
"name": "counterAccount", | ||
"type": { | ||
"kind": "struct", | ||
"fields": [ | ||
{ | ||
"name": "counter", | ||
"type": "u32" | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"errors": [ | ||
{ | ||
"code": 6000, | ||
"name": "AmountTooBig", | ||
"msg": "The amount is too big" | ||
} | ||
] | ||
}; |
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
Empty file.
Oops, something went wrong.