Skip to content
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
5 changes: 2 additions & 3 deletions modules/sdk-coin-vet/src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ export const CLAIM_BASE_REWARDS_METHOD_ID = '0x858d50e8'; // claimVetGeneratedVt
export const CLAIM_STAKING_REWARDS_METHOD_ID = '0x0962ef79'; // claimRewards(uint256)

export const STARGATE_NFT_ADDRESS = '0x1856c533ac2d94340aaa8544d35a5c1d4a21dee7';
export const STARGATE_DELEGATION_ADDRESS = '0x4cb1c9ef05b529c093371264fab2c93cc6cddb0e';
export const STARGATE_DELEGATION_ADDRESS_TESTNET = '0x7240e3bc0d26431512d5b67dbd26d199205bffe8';

export const STARGATE_NFT_ADDRESS_TESTNET = '0x887d9102f0003f1724d8fd5d4fe95a11572fcd77';

export const STARGATE_CONTRACT_ADDRESS_TESTNET = '0x1e02b2953adefec225cf0ec49805b1146a4429c1';
export const STARGATE_CONTRACT_ADDRESS = '0x03c557be98123fdb6fad325328ac6eb77de7248c';

export const VALIDATOR_REGISTRATION_STAKER_CONTRACT_ADDRESS_TESTNET = '0x00000000000000000000000000005374616B6572';
export const VALIDATOR_REGISTRATION_STAKER_CONTRACT_ADDRESS_MAINNET = '0x00000000000000000000000000005374616B6572';
Expand Down
43 changes: 2 additions & 41 deletions modules/sdk-coin-vet/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ import {
CLAIM_STAKING_REWARDS_METHOD_ID,
STARGATE_NFT_ADDRESS,
STARGATE_NFT_ADDRESS_TESTNET,
STARGATE_DELEGATION_ADDRESS,
DELEGATE_CLAUSE_METHOD_ID,
STARGATE_CONTRACT_ADDRESS_TESTNET,
STARGATE_DELEGATION_ADDRESS_TESTNET,
STARGATE_CONTRACT_ADDRESS,
VALIDATOR_REGISTRATION_STAKER_CONTRACT_ADDRESS_MAINNET,
VALIDATOR_REGISTRATION_STAKER_CONTRACT_ADDRESS_TESTNET,
ADD_VALIDATION_METHOD_ID,
Expand Down Expand Up @@ -325,24 +324,14 @@ export class Utils implements BaseUtils {
}
}

/**
* Get the network-appropriate stargate contract address
* @param {CoinConfig} coinConfig - The coin configuration object
* @returns {string} The delegation contract address for the network
*/
getDefaultDelegationAddress(coinConfig: Readonly<CoinConfig>): string {
const isTestnet = coinConfig.network.type === 'testnet';
return isTestnet ? STARGATE_CONTRACT_ADDRESS_TESTNET : STARGATE_DELEGATION_ADDRESS;
}

/**
* Get the network-appropriate staking contract address
* @param {CoinConfig} coinConfig - The coin configuration object
* @returns {string} The staking contract address for the network
*/
getDefaultStakingAddress(coinConfig: Readonly<CoinConfig>): string {
const isTestnet = coinConfig.network.type === 'testnet';
return isTestnet ? STARGATE_CONTRACT_ADDRESS_TESTNET : STARGATE_NFT_ADDRESS;
return isTestnet ? STARGATE_CONTRACT_ADDRESS_TESTNET : STARGATE_CONTRACT_ADDRESS;
}

/**
Expand All @@ -357,19 +346,6 @@ export class Utils implements BaseUtils {
: VALIDATOR_REGISTRATION_STAKER_CONTRACT_ADDRESS_MAINNET;
}

/**
* Check if an address is a valid delegation contract address for any network
* @param {string} address - The address to check
* @returns {boolean} True if the address is a delegation contract address
*/
isDelegationContractAddress(address: string): boolean {
const lowerAddress = address.toLowerCase();
return (
lowerAddress === STARGATE_DELEGATION_ADDRESS.toLowerCase() ||
lowerAddress === STARGATE_DELEGATION_ADDRESS_TESTNET.toLowerCase()
);
}

/**
* Check if an address is a valid NFT contract address for any network
* @param {string} address - The address to check
Expand Down Expand Up @@ -411,21 +387,6 @@ export class Utils implements BaseUtils {
);
}
}

/**
* Validate that a contract address matches the expected stargate contract for the network
* @param {string} address - The contract address to validate
* @param {CoinConfig} coinConfig - The coin configuration object
* @throws {Error} If the address doesn't match the expected delegation contract address
*/
validateDelegationContractAddress(address: string, coinConfig: Readonly<CoinConfig>): void {
const expectedAddress = this.getDefaultDelegationAddress(coinConfig);
if (address.toLowerCase() !== expectedAddress.toLowerCase()) {
throw new Error(
`Invalid delegation contract address. Expected ${expectedAddress} for ${coinConfig.network.type}, got ${address}`
);
}
}
}

const utils = new Utils();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,16 @@ describe('VET Claim Rewards Transaction', function () {
});

it('should throw error when staking contract address is missing', async function () {
const txBuilder = createBasicTxBuilder();
const txBuilder = factory.getClaimRewardsBuilder();
txBuilder.tokenId(tokenId);
txBuilder.sender('0x9378c12BD7502A11F770a5C1F223c959B2805dA9');
txBuilder.chainTag(0x27);
txBuilder.blockRef('0x0000000000000000');
txBuilder.expiration(64);
txBuilder.gas(100000);
txBuilder.gasPriceCoef(0);
txBuilder.nonce('12345');
// Intentionally not setting stakingContractAddress

await txBuilder.build().should.be.rejectedWith('Staking contract address is required');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,19 @@ describe('VET Delegation Transaction', function () {
});

it('should build a signed tx and validate its toJson', async function () {
const tokenIdForDelegateTxn = '15662';
const tokenIdForDelegateTxn = '15685';
const txBuilder = factory.from(testData.DELEGATION_TRANSACTION);
const tx = txBuilder.transaction as DelegateClauseTransaction;
const toJson = tx.toJson();
toJson.id.should.equal('0xc47792a421d90cb52a4aedbd9abe96f779a8ad68e508680ac3cc135428c3f4c5');
toJson.id.should.equal('0x841fd66a1d7feff7ab3d432720a659697197e6c67da1aeb9ce9d93b131e46ab7');
toJson.stakingContractAddress?.should.equal('0x1e02b2953adefec225cf0ec49805b1146a4429c1');
toJson.nonce.should.equal('887557');
toJson.gas.should.equal(287920);
toJson.nonce.should.equal('0xf341b4c6b5ff5294');
toJson.gas.should.equal(242796);
toJson.gasPriceCoef.should.equal(128);
toJson.expiration.should.equal(64);
toJson.expiration.should.equal(400);
toJson.chainTag.should.equal(39);
toJson.tokenId?.should.equal(tokenIdForDelegateTxn);
toJson.validatorAddress?.should.equal('0x00563ec3cafbbe7e60b04b3190e6eca66579706d');
toJson.validatorAddress?.should.equal('0x00000021cbe0de65ea10f7658effeea70727154a');
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,13 @@ describe('VET Staking Transaction', function () {
const txBuilder = factory.from(testData.STAKE_CLAUSE_TRANSACTION);
const tx = txBuilder.transaction as StakeClauseTransaction;
const toJson = tx.toJson();
toJson.id.should.equal('0x7148f62b42ecfdcb7ee62ac0654514e4b5f65f2fe5fdee79d4d29f56ab1722eb');
toJson.id.should.equal('0xe003dbe6db08e71b962aa97ba5cb9e69810f52db41d31111fe39654281c6227c');
toJson.stakingContractAddress?.should.equal('0x1e02b2953adefec225cf0ec49805b1146a4429c1');
toJson.amountToStake?.should.equal(amountToStake);
toJson.nonce.should.equal('996363');
toJson.gas.should.equal(406410);
toJson.nonce.should.equal('0xf536788f0c121df3');
toJson.gas.should.equal(338631);
toJson.gasPriceCoef.should.equal(128);
toJson.expiration.should.equal(64);
toJson.expiration.should.equal(400);
toJson.chainTag.should.equal(39);
toJson.levelId?.should.equal(8);
});
Expand Down