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

devnet -> testnet #300

Merged
merged 3 commits into from
Dec 26, 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
8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,11 @@
"editor.formatOnPaste": true,
"editor.formatOnSaveMode": "file"
},
"cSpell.words": ["ARIO", "hashchain", "redelegate"]
"cSpell.words": [
"ARIO",
"hashchain",
"redelegate",
"redelegation",
"redelegations"
]
}
6 changes: 3 additions & 3 deletions src/gar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1777,10 +1777,10 @@ end
--- @field vaultId string | nil # The vault id to redelegate from (optional)

--- @class RedelegateStakeResult
--- @field sourceGateway table # The updated gateway object that the stake was moved from
--- @field targetGateway table # The updated gateway object that the stake was moved to
--- @field sourceAddress WalletAddress # The address of the gateway that the stake was moved from
--- @field targetAddress table # The address of the gateway that the stake was moved to
--- @field redelegationFee number # The fee charged for the redelegation
--- @field feeResetTimestamp number # The timestamp when the reldelegation fee will be reset
--- @field feeResetTimestamp number # The timestamp when the redelegation fee will be reset
--- @field redelegationsSinceFeeReset number # The number of redelegations the user has made since the last fee reset

--- Take stake from a delegate and stake it to a new delegate.
Expand Down
23 changes: 14 additions & 9 deletions src/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2281,24 +2281,29 @@ addEventingHandler(ActionMap.RedelegateStake, utils.hasMatchingTag("Action", Act
local isStakeMovingFromDelegateToOperator = delegateAddress == targetAddress
local isStakeMovingFromOperatorToDelegate = delegateAddress == sourceAddress
local isStakeMovingFromWithdrawal = vaultId ~= nil
if isStakeMovingFromWithdrawal then
LastKnownWithdrawSupply = LastKnownWithdrawSupply - quantity
end

if isStakeMovingFromDelegateToOperator then
if isStakeMovingFromWithdrawal then
LastKnownWithdrawSupply = LastKnownWithdrawSupply - stakeMoved
else
LastKnownDelegatedSupply = LastKnownDelegatedSupply - stakeMoved
if not isStakeMovingFromWithdrawal then
LastKnownDelegatedSupply = LastKnownDelegatedSupply - quantity
end
LastKnownStakedSupply = LastKnownStakedSupply + stakeMoved
elseif isStakeMovingFromOperatorToDelegate then
if isStakeMovingFromWithdrawal then
LastKnownWithdrawSupply = LastKnownWithdrawSupply + stakeMoved
else
LastKnownStakedSupply = LastKnownStakedSupply - stakeMoved
if not isStakeMovingFromWithdrawal then
LastKnownStakedSupply = LastKnownStakedSupply - quantity
end
LastKnownDelegatedSupply = LastKnownDelegatedSupply + stakeMoved
elseif isStakeMovingFromWithdrawal then
LastKnownStakedSupply = LastKnownStakedSupply + stakeMoved
-- else
-- Stake is simply moving from one delegation to another
end

LastKnownCirculatingSupply = LastKnownCirculatingSupply - redelegationResult.redelegationFee
if redelegationFee > 0 then
msg.ioEvent:addField("Redelegation-Fee", redelegationFee)
end
addSupplyData(msg.ioEvent)

Send(msg, {
Expand Down
35 changes: 20 additions & 15 deletions tests/gar.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1597,6 +1597,7 @@ describe('GatewayRegistry', async () => {
},
memory,
});
assertNoResultError(result);
return {
result,
memory: result.Memory,
Expand Down Expand Up @@ -1625,13 +1626,15 @@ describe('GatewayRegistry', async () => {
memory: joinTargetMemory,
});

const { memory: delegatedStakeMemory } = await delegateStake({
delegatorAddress,
quantity: stakeQty,
gatewayAddress: sourceAddress,
timestamp: STUB_TIMESTAMP,
memory: transferMemory,
});
const { result: delegateStakeResult, memory: delegatedStakeMemory } =
await delegateStake({
delegatorAddress,
quantity: stakeQty,
gatewayAddress: sourceAddress,
timestamp: STUB_TIMESTAMP,
memory: transferMemory,
});
assertNoResultError(delegateStakeResult);

const sourceGatewayBefore = await getGateway({
address: sourceAddress,
Expand Down Expand Up @@ -1780,14 +1783,16 @@ describe('GatewayRegistry', async () => {
);

const decreaseStakeMsgId = 'decrease-stake-message-id-'.padEnd(43, 'x');
const { memory: decreaseStakeMemory } = await decreaseDelegateStake({
memory: delegatedStakeMemory,
timestamp: STUB_TIMESTAMP + 1,
delegatorAddress,
decreaseQty: stakeQty,
gatewayAddress: sourceAddress,
messageId: decreaseStakeMsgId,
});
const { result: decreaseStakeResult, memory: decreaseStakeMemory } =
await decreaseDelegateStake({
memory: delegatedStakeMemory,
timestamp: STUB_TIMESTAMP + 1,
delegatorAddress,
decreaseQty: stakeQty,
gatewayAddress: sourceAddress,
messageId: decreaseStakeMsgId,
});
assertNoResultError(decreaseStakeResult);

const { memory: redelegateStakeMemory } = await redelegateStake({
memory: decreaseStakeMemory,
Expand Down
Loading