Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement starknet refund #1018

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions components/Swap/AtomicChat/Resolver.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,11 @@ export const ResolveMessages: FC = () => {
if (committment?.uncommitted || sourceLock?.unlocked) {
return <div className="flex w-full grow flex-col space-y-2" >
<Committed walletIcon={WalletIcon} />
<AssetsLockedByLP address={lp_address} destination_network={destination_network} tx_id={commitFromApi?.transactions.find(t => t.type === 'lock')?.hash} />
<RefundCompleted walletIcon={WalletIcon} source_network={source_network} tx_id={completedRefundHash} />
</div >
}
return <div className="flex w-full grow flex-col space-y-2" >
<Committed walletIcon={WalletIcon} />
<AssetsLockedByLP address={lp_address} destination_network={destination_network} tx_id={commitFromApi?.transactions.find(t => t.type === 'lock')?.hash} />
{
completedRefundHash ?
<RefundRequested walletIcon={WalletIcon} />
Expand Down
7 changes: 0 additions & 7 deletions components/Swap/AtomicChat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,6 @@ const Commitment: FC<ContainerProps> = (props) => {
)
}



const Footer: FC = () => {
return <></>
}


const Container: FC<ContainerProps> = (props) => {
const { type } = props

Expand Down
31 changes: 25 additions & 6 deletions lib/wallets/starknet/useStarknet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import toast from "react-hot-toast";
import { Call, Contract, RpcProvider, shortString } from "starknet";
import PHTLCAbi from "../../../lib/abis/atomic/STARKNET_PHTLC.json"
import ETHABbi from "../../../lib/abis/STARKNET_ETH.json"
import { CommitmentParams, CreatyePreHTLCParams, GetCommitsParams, LockParams } from "../phtlc";
import { CommitmentParams, CreatyePreHTLCParams, GetCommitsParams, LockParams, RefundParams } from "../phtlc";
import { BigNumberish, ethers } from "ethers";
import { AssetLock, Commit } from "../../../Models/PHTLC";

Expand Down Expand Up @@ -104,7 +104,8 @@ export default function useStarknet(): WalletProvider {
await connectWallet(chain)
}

const LOCK_TIME = 1000 * 60 * 60 * 3 // 3 hours
// const LOCK_TIME = 1000 * 60 * 60 * 3 // 3 hours
const LOCK_TIME = 1000 * 60 * 30 // 30 minutes
const messanger = "0x152747029e738c20a4ecde5ef869ea072642938d62f0aa7f3d0e9dfb5051cb9"

const createPreHTLC = async (params: CreatyePreHTLCParams) => {
Expand Down Expand Up @@ -146,8 +147,6 @@ export default function useStarknet(): WalletProvider {

const trx = (await wallet?.metadata?.starknetAccount?.account?.execute([increaseAllowanceCall, committmentCall]))



const commitTransactionData = await wallet.metadata.starknetAccount.provider.waitForTransaction(
trx.transaction_hash
);
Expand All @@ -166,9 +165,29 @@ export default function useStarknet(): WalletProvider {
const claim = () => {
throw new Error('Not implemented')
}
const refund = () => {
throw new Error('Not implemented')

const refund = async (params: RefundParams) => {
const { contractAddress: atomicAddress, commitId, lockId } = params

if (!wallet?.metadata?.starknetAccount?.account) {
throw new Error('Wallet not connected')
}

const atomicContract = new Contract(
PHTLCAbi,
atomicAddress,
wallet.metadata?.starknetAccount?.account,
)

const refundCall: Call = atomicContract.populate(lockId ? "unlock" : "uncommit", [lockId || commitId])
const trx = (await wallet?.metadata?.starknetAccount?.account?.execute(refundCall))

if (!trx) {
throw new Error("No result")
}
return trx.transaction_hash
}

const getCommitment = async (params: CommitmentParams): Promise<Commit> => {
const { commitId, contractAddress } = params

Expand Down
Loading