Skip to content

Commit

Permalink
claim external update
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonard-Pat committed Jun 6, 2024
1 parent 0eb6f40 commit 1f518b6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
17 changes: 15 additions & 2 deletions lib/claim.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Account, Contract, RPC, Uint256, ec, encode, num, shortString, uint256 } from "starknet";
import { Account, CallData, Contract, RPC, Uint256, ec, encode, hash, num, shortString, uint256 } from "starknet";
import { LegacyStarknetKeyPair, deployer, manager } from ".";
import { GIFT_AMOUNT, GIFT_MAX_FEE } from "./deposit";

Expand Down Expand Up @@ -76,10 +76,23 @@ export async function claimExternal(
factory: Contract,
receiver: string,
claim: Claim,
claimAccountAddress: string,
giftSigner: LegacyStarknetKeyPair,
account = deployer,
): Promise<string> {
const constructorArgs: AccountConstructorArguments = {
sender: deployer.address,
amount: claim.amount,
max_fee: claim.max_fee,
token: claim.token,
claim_pubkey: claim.claim_pubkey,
};
const claimAccountAddress = hash.calculateContractAddressFromHash(
0,
claim.class_hash,
CallData.compile({ constructorArgs }),
factory.address,
);

const claimExternalData = await getClaimExternalData({ receiver });
const signature = await giftSigner.signMessage(claimExternalData, claimAccountAddress);

Expand Down
8 changes: 0 additions & 8 deletions tests-integration/factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ describe("Factory", function () {
it(`Test calculate claim address`, async function () {
const { factory, claimAccountClassHash } = await setupGiftProtocol();
const { tokenContract, claimSigner } = await defaultDepositTestSetup(factory);
const a = factory.populateTransaction.get_claim_address(
claimAccountClassHash,
deployer.address,
GIFT_AMOUNT,
GIFT_MAX_FEE,
tokenContract.address,
claimSigner.publicKey,
);
const claimAddress = await factory.get_claim_address(
claimAccountClassHash,
deployer.address,
Expand Down

0 comments on commit 1f518b6

Please sign in to comment.