-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: organize stardust objects on migratable and unmigratable
- Loading branch information
Showing
5 changed files
with
144 additions
and
35 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
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,55 @@ | ||
// 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) { | ||
if (!outputObject) { | ||
unmigratable.push(outputObject); | ||
continue; | ||
} | ||
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 }; | ||
} |