diff --git a/lib/claim.ts b/lib/claim.ts index e0dcb10..e26076a 100644 --- a/lib/claim.ts +++ b/lib/claim.ts @@ -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"; @@ -76,10 +76,23 @@ export async function claimExternal( factory: Contract, receiver: string, claim: Claim, - claimAccountAddress: string, giftSigner: LegacyStarknetKeyPair, account = deployer, ): Promise { + 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); diff --git a/tests-integration/factory.test.ts b/tests-integration/factory.test.ts index c838e19..7813926 100644 --- a/tests-integration/factory.test.ts +++ b/tests-integration/factory.test.ts @@ -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,