-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tooling-dashboard): organize migration stardust objects (#3826)
* feat: fetch stardust basic and nft objects * feat: organize stardust objects on migratable and unmigratable * fix: migration constants and variable nameing * fix: variable naming * fix: move constants to core * fix: evert adding routes to barrel * fix: remove undefined object check --------- Co-authored-by: Marc Espin <[email protected]>
- Loading branch information
Showing
7 changed files
with
143 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...oard/lib/constants/migration.constants.ts → ...core/src/constants/migration.constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
apps/wallet-dashboard/lib/interfaces/migration.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
type ExpirationUnlockCondition = { | ||
owner: string; | ||
return_address: string; | ||
unix_time: number; | ||
}; | ||
type StorageDepositReturnUnlockCondition = { | ||
return_address: string; | ||
return_amount: string; | ||
}; | ||
type TimelockUnlockCondition = { | ||
unix_time: number; | ||
}; | ||
|
||
export type CommonOutputObject = { | ||
id: { id: string }; | ||
balance: string; | ||
native_tokens: { | ||
type: string; | ||
fields: { id: { id: string }; size: string }; | ||
}; | ||
}; | ||
|
||
export interface CommonOutputObjectWithUc extends CommonOutputObject { | ||
expiration_uc?: { | ||
type: string; | ||
fields: ExpirationUnlockCondition; | ||
}; | ||
storage_deposit_return_uc?: { | ||
type: string; | ||
fields: StorageDepositReturnUnlockCondition; | ||
}; | ||
timelock_uc?: { | ||
type: string; | ||
fields: TimelockUnlockCondition; | ||
}; | ||
} | ||
|
||
export interface BasicOutputObject extends CommonOutputObjectWithUc { | ||
metadata?: number[]; | ||
tag?: number[]; | ||
sender?: string; | ||
} | ||
|
||
export interface NftOutputObject extends CommonOutputObjectWithUc {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { IotaObjectData } from '@iota/iota-sdk/client'; | ||
import { CommonOutputObjectWithUc } from '../interfaces/migration.interface'; | ||
|
||
export type StardustMigrationGroupedObjects = { | ||
migratable: IotaObjectData[]; | ||
unmigratable: IotaObjectData[]; | ||
}; | ||
|
||
export function groupStardustObjectsByMigrationStatus( | ||
stardustOutputObjects: IotaObjectData[], | ||
epochTimestamp: number, | ||
address: string, | ||
): StardustMigrationGroupedObjects { | ||
const migratable: IotaObjectData[] = []; | ||
const unmigratable: IotaObjectData[] = []; | ||
|
||
const epochUnix = epochTimestamp / 1000; | ||
|
||
for (const outputObject of stardustOutputObjects) { | ||
const outputObjectFields = ( | ||
outputObject.content as unknown as { | ||
fields: CommonOutputObjectWithUc; | ||
} | ||
).fields; | ||
|
||
if (outputObjectFields.expiration_uc) { | ||
const unlockableAddress = | ||
outputObjectFields.expiration_uc.fields.unix_time <= epochUnix | ||
? outputObjectFields.expiration_uc.fields.return_address | ||
: outputObjectFields.expiration_uc.fields.owner; | ||
if (unlockableAddress !== address) { | ||
unmigratable.push(outputObject); | ||
continue; | ||
} | ||
} | ||
if ( | ||
outputObjectFields.timelock_uc && | ||
outputObjectFields.timelock_uc.fields.unix_time > epochUnix | ||
) { | ||
unmigratable.push(outputObject); | ||
continue; | ||
} | ||
|
||
migratable.push(outputObject); | ||
} | ||
|
||
return { migratable, unmigratable }; | ||
} |