import { SpaceportSDK } from '@spaceport/sdk'
async function manageRoyalties() {
const licenseeSDK = SpaceportSDK.createWithAccount(licenseeAccount, {
chain: 'devnet',
apiKey: process.env.SDK_API_KEY,
})
const licensorSDK = SpaceportSDK.createWithAccount(licensorAccount, {
chain: 'devnet',
apiKey: process.env.SDK_API_KEY,
})
// 1. Register royalties from CSV invoice data
const registrationResult = await licenseeSDK.royalties.register({
csvFile: csvFile, // File object containing invoice data
productIds: productIds, // Array of product IDs
})
// 2. Monitor registration job
if (registrationResult.success) {
const jobStatus = await licenseeSDK.utils.pollJobStatus(registrationResult.jobId, {
timeout: 300000, // 5 minutes
interval: 3000, // 3 seconds
})
}
// 3. Pay off-chain royalties (by licensee)
const payResult = await licenseeSDK.royalties.payOffchain({
coreProductIds: productIds.map((id) => id.toString()),
})
// 4. Accept off-chain royalties (by licensor)
const acceptanceInputs = quarterRanges.map((quarter) => ({
coreProductIds: productIds.map((id) => id.toString()),
periodStart: quarter.start,
periodEnd: quarter.end,
}))
const acceptResult = await licensorSDK.royalties.acceptOffchain(acceptanceInputs)
// 5. Deny off-chain royalties (by licensor)
const denialInputs = quarterRanges.map((quarter) => ({
coreProductIds: productIds.map((id) => id.toString()),
periodStart: quarter.start,
periodEnd: quarter.end,
}))
const denyResult = await licensorSDK.royalties.denyOffchain(denialInputs)
}