-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: redpacket history for solana (#12042)
- Loading branch information
1 parent
c6fcd31
commit bfcf95d
Showing
26 changed files
with
340 additions
and
103 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
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
6 changes: 6 additions & 0 deletions
6
packages/plugins/RedPacket/src/SiteAdaptor/helpers/getRedpacket.ts
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,6 @@ | ||
import { getRpProgram } from './getRpProgram.js' | ||
|
||
export async function getRedpacket(id: string) { | ||
const program = await getRpProgram() | ||
return program.account.redPacket.fetch(id) | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/plugins/RedPacket/src/SiteAdaptor/helpers/refundNativeToken.ts
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,18 @@ | ||
import { web3 } from '@coral-xyz/anchor' | ||
import { getRpProgram } from './getRpProgram.js' | ||
import * as SolanaWeb3 from /* webpackDefer: true */ '@solana/web3.js' | ||
|
||
export async function refundNativeToken(id: string, creator: SolanaWeb3.PublicKey) { | ||
const program = await getRpProgram() | ||
return program.methods | ||
.withdrawWithNativeToken() | ||
.accounts({ | ||
// @ts-expect-error missing type | ||
redPacket: new SolanaWeb3.PublicKey(id), | ||
signer: new SolanaWeb3.PublicKey(creator), | ||
systemProgram: web3.SystemProgram.programId, | ||
}) | ||
.rpc({ | ||
commitment: 'confirmed', | ||
}) | ||
} |
43 changes: 43 additions & 0 deletions
43
packages/plugins/RedPacket/src/SiteAdaptor/helpers/refundSplToken.ts
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,43 @@ | ||
import { ASSOCIATED_TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync } from '@solana/spl-token' | ||
import * as SolanaWeb3 from /* webpackDefer: true */ '@solana/web3.js' | ||
import { getRpProgram } from './getRpProgram.js' | ||
|
||
export async function refundSplToken({ | ||
id, | ||
tokenMint, | ||
tokenProgram, | ||
tokenAccount, | ||
creator, | ||
}: { | ||
id: string | ||
tokenMint: SolanaWeb3.PublicKey | ||
tokenProgram: SolanaWeb3.PublicKey | null | ||
tokenAccount: SolanaWeb3.PublicKey | null | ||
creator: SolanaWeb3.PublicKey | ||
}) { | ||
if (!tokenProgram || !tokenAccount) throw new Error('Token program or account not found') | ||
|
||
const program = await getRpProgram() | ||
const vault = getAssociatedTokenAddressSync( | ||
new SolanaWeb3.PublicKey(tokenMint), | ||
new SolanaWeb3.PublicKey(id), | ||
true, | ||
new SolanaWeb3.PublicKey(tokenProgram), | ||
) | ||
|
||
return program.methods | ||
.withdrawWithSplToken() | ||
.accounts({ | ||
// @ts-expect-error missing type | ||
redPacket: new SolanaWeb3.PublicKey(id), | ||
signer: creator, | ||
vault, | ||
tokenAccount, | ||
tokenMint, | ||
tokenProgram, | ||
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID, | ||
}) | ||
.rpc({ | ||
commitment: 'confirmed', | ||
}) | ||
} |
Oops, something went wrong.