@xyo-network/xl1-protocol-sdk 1.15.10 → 1.15.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/neutral/config/Config.d.ts +9 -0
- package/dist/neutral/config/Config.d.ts.map +1 -1
- package/dist/neutral/config/Validation.d.ts +9 -0
- package/dist/neutral/config/Validation.d.ts.map +1 -1
- package/dist/neutral/index.d.ts +2 -0
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +121 -27
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/primitives/index.d.ts +3 -0
- package/dist/neutral/primitives/index.d.ts.map +1 -0
- package/dist/neutral/primitives/step/completedStepRewardAddress.d.ts +4 -0
- package/dist/neutral/primitives/step/completedStepRewardAddress.d.ts.map +1 -0
- package/dist/neutral/primitives/step/derivedReceiveAddress.d.ts +3 -0
- package/dist/neutral/primitives/step/derivedReceiveAddress.d.ts.map +1 -0
- package/dist/neutral/primitives/step/index.d.ts +5 -0
- package/dist/neutral/primitives/step/index.d.ts.map +1 -0
- package/dist/neutral/primitives/step/spec/stepTransferIndex.spec.d.ts +2 -0
- package/dist/neutral/primitives/step/spec/stepTransferIndex.spec.d.ts.map +1 -0
- package/dist/neutral/primitives/step/stepBlockRange.d.ts +3 -0
- package/dist/neutral/primitives/step/stepBlockRange.d.ts.map +1 -0
- package/dist/neutral/primitives/step/stepTransferIndex.d.ts +2 -0
- package/dist/neutral/primitives/step/stepTransferIndex.d.ts.map +1 -0
- package/dist/neutral/primitives/transaction/elevatedPayloads.d.ts +4 -0
- package/dist/neutral/primitives/transaction/elevatedPayloads.d.ts.map +1 -0
- package/dist/neutral/primitives/transaction/index.d.ts +2 -0
- package/dist/neutral/primitives/transaction/index.d.ts.map +1 -0
- package/package.json +2 -1
- package/src/config/RewardRedemptionApi.ts +3 -3
- package/src/config/Validation.ts +10 -1
- package/src/index.ts +2 -0
- package/src/primitives/index.ts +2 -0
- package/src/primitives/step/completedStepRewardAddress.ts +8 -0
- package/src/primitives/step/derivedReceiveAddress.ts +8 -0
- package/src/primitives/step/index.ts +4 -0
- package/src/primitives/step/spec/stepTransferIndex.spec.ts +23 -0
- package/src/primitives/step/stepBlockRange.ts +8 -0
- package/src/primitives/step/stepTransferIndex.ts +18 -0
- package/src/primitives/transaction/elevatedPayloads.ts +21 -0
- package/src/primitives/transaction/index.ts +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/primitives/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,wBAAwB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"completedStepRewardAddress.d.ts","sourceRoot":"","sources":["../../../../src/primitives/step/completedStepRewardAddress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAa,MAAM,aAAa,CAAA;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAG7D,wBAAgB,0BAA0B,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,YAAY,GAAG,OAAO,CAGjF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"derivedReceiveAddress.d.ts","sourceRoot":"","sources":["../../../../src/primitives/step/derivedReceiveAddress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAa,MAAM,aAAa,CAAA;AAIrD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAG/E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/primitives/step/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAA;AAC/C,cAAc,4BAA4B,CAAA;AAC1C,cAAc,qBAAqB,CAAA;AACnC,cAAc,wBAAwB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stepTransferIndex.spec.d.ts","sourceRoot":"","sources":["../../../../../src/primitives/step/spec/stepTransferIndex.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stepBlockRange.d.ts","sourceRoot":"","sources":["../../../../src/primitives/step/stepBlockRange.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAG5E,wBAAgB,cAAc,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,YAAY,GAAG,aAAa,CAI3E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stepTransferIndex.d.ts","sourceRoot":"","sources":["../../../../src/primitives/step/stepTransferIndex.ts"],"names":[],"mappings":"AAGA,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,YAc5D"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { WithStorageMeta } from '@xyo-network/payload-model';
|
|
2
|
+
import type { AllowedBlockPayload, SignedHydratedTransactionWithStorageMeta } from '@xyo-network/xl1-protocol';
|
|
3
|
+
export declare function elevatedPayloads([tx, payloads]: SignedHydratedTransactionWithStorageMeta): WithStorageMeta<AllowedBlockPayload>[];
|
|
4
|
+
//# sourceMappingURL=elevatedPayloads.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elevatedPayloads.d.ts","sourceRoot":"","sources":["../../../../src/primitives/transaction/elevatedPayloads.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AACjE,OAAO,KAAK,EAAE,mBAAmB,EAAE,wCAAwC,EAAE,MAAM,2BAA2B,CAAA;AAG9G,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,EAAE,QAAQ,CAAC,EAAE,wCAAwC,0CAgBxF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/primitives/transaction/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "http://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@xyo-network/xl1-protocol-sdk",
|
|
4
|
-
"version": "1.15.
|
|
4
|
+
"version": "1.15.11",
|
|
5
5
|
"description": "XYO Layer One SDK Protocol",
|
|
6
6
|
"homepage": "https://xylabs.com",
|
|
7
7
|
"bugs": {
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
"@xyo-network/wallet-model": "~5.1.6",
|
|
57
57
|
"@xyo-network/xl1-protocol": "~1.12.81",
|
|
58
58
|
"async-mutex": "~0.5.0",
|
|
59
|
+
"ethers": "~6.15.0",
|
|
59
60
|
"zod": "~4.1.12"
|
|
60
61
|
},
|
|
61
62
|
"devDependencies": {
|
|
@@ -7,18 +7,18 @@ export const RewardRedemptionApiConfigZod = z.object({
|
|
|
7
7
|
host: z.string().default('localhost').register(globalRegistry, {
|
|
8
8
|
default: 'localhost',
|
|
9
9
|
description: 'Host for the Redemption API',
|
|
10
|
-
title: '
|
|
10
|
+
title: 'rewardRedemptionApi.host',
|
|
11
11
|
type: 'string',
|
|
12
12
|
}),
|
|
13
13
|
mnemonic: MnemonicStringZod.optional().register(globalRegistry, {
|
|
14
14
|
description: 'Mnemonic for the Redemption API wallet',
|
|
15
|
-
title: '
|
|
15
|
+
title: 'rewardRedemptionApi.mnemonic',
|
|
16
16
|
type: 'string',
|
|
17
17
|
}),
|
|
18
18
|
port: z.coerce.number().default(8082).register(globalRegistry, {
|
|
19
19
|
default: 8082,
|
|
20
20
|
description: 'Port for the Redemption API',
|
|
21
|
-
title: '
|
|
21
|
+
title: 'rewardRedemptionApi.port',
|
|
22
22
|
type: 'number',
|
|
23
23
|
}),
|
|
24
24
|
})
|
package/src/config/Validation.ts
CHANGED
|
@@ -13,7 +13,16 @@ export const ValidationConfigZod = z.object({
|
|
|
13
13
|
title: 'allowedRewardRedeemers',
|
|
14
14
|
type: 'array',
|
|
15
15
|
})),
|
|
16
|
-
|
|
16
|
+
allowedRewardEscrowAccountSigners: z.preprocess((val) => {
|
|
17
|
+
if (typeof val === 'string') {
|
|
18
|
+
return val.split(',').map(s => asAddress(s.trim()))
|
|
19
|
+
}
|
|
20
|
+
return val
|
|
21
|
+
}, z.array(AddressZod).optional().register(globalRegistry, {
|
|
22
|
+
description: 'List of allowed reward escrow account signer addresses, if undefined anyone can participate',
|
|
23
|
+
title: 'allowedRewardEscrowAccountSigners',
|
|
24
|
+
type: 'array',
|
|
25
|
+
})),
|
|
17
26
|
})
|
|
18
27
|
|
|
19
28
|
export type ValidationConfig = z.infer<typeof ValidationConfigZod>
|
package/src/index.ts
CHANGED
|
@@ -8,6 +8,8 @@ export * from './map/index.ts'
|
|
|
8
8
|
export * from './model/index.ts'
|
|
9
9
|
export * from './multipliers.ts'
|
|
10
10
|
export * from './payload/index.ts'
|
|
11
|
+
export * from './primitives/index.ts'
|
|
12
|
+
export * from './primitives/index.ts'
|
|
11
13
|
export * from './SignedBigInt.ts'
|
|
12
14
|
export * from './time/index.ts'
|
|
13
15
|
export * from './transaction/index.ts'
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Address, toAddress } from '@xylabs/hex'
|
|
2
|
+
import type { StepIdentity } from '@xyo-network/xl1-protocol'
|
|
3
|
+
import { keccak256 } from 'ethers'
|
|
4
|
+
|
|
5
|
+
export function completedStepRewardAddress({ block, step }: StepIdentity): Address {
|
|
6
|
+
const addressKey = new TextEncoder().encode(`${block}|${step}`)
|
|
7
|
+
return toAddress(keccak256(addressKey).slice(-40), { prefix: false })
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Address, toAddress } from '@xylabs/hex'
|
|
2
|
+
import { isDefined } from '@xylabs/typeof'
|
|
3
|
+
import { keccak256 } from 'ethers'
|
|
4
|
+
|
|
5
|
+
export function derivedReceiveAddress(address: Address, scope?: string): Address {
|
|
6
|
+
const addressKey = new TextEncoder().encode(isDefined(scope) ? `${scope}|${address}` : address)
|
|
7
|
+
return toAddress(keccak256(addressKey).slice(-40), { prefix: false })
|
|
8
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { StepSizes } from '@xyo-network/xl1-protocol'
|
|
2
|
+
import {
|
|
3
|
+
describe, expect, it,
|
|
4
|
+
} from 'vitest'
|
|
5
|
+
|
|
6
|
+
import { stepTransferIndex } from '../stepTransferIndex.ts'
|
|
7
|
+
|
|
8
|
+
describe('getStepTransferIndex', () => {
|
|
9
|
+
it('should get index [single entry]', { timeout: 120_000 }, () => {
|
|
10
|
+
const index = stepTransferIndex(StepSizes[3], 3)
|
|
11
|
+
expect (index[0]).toBe(0)
|
|
12
|
+
expect (index[1]).toBe(1)
|
|
13
|
+
})
|
|
14
|
+
it('should get index [double entry]', { timeout: 120_000 }, () => {
|
|
15
|
+
const index3 = stepTransferIndex(StepSizes[3] * StepSizes[4], 3)
|
|
16
|
+
expect (index3[0]).toBe(0)
|
|
17
|
+
expect (index3[1]).toBe(2)
|
|
18
|
+
|
|
19
|
+
const index4 = stepTransferIndex(StepSizes[3] * StepSizes[4], 4)
|
|
20
|
+
expect (index4[0]).toBe(1)
|
|
21
|
+
expect (index4[1]).toBe(2)
|
|
22
|
+
})
|
|
23
|
+
})
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { StepIdentity, XL1BlockRange } from '@xyo-network/xl1-protocol'
|
|
2
|
+
import { asXL1BlockRange, StepSizes } from '@xyo-network/xl1-protocol'
|
|
3
|
+
|
|
4
|
+
export function stepBlockRange({ block, step }: StepIdentity): XL1BlockRange {
|
|
5
|
+
const stepSize = StepSizes[step]
|
|
6
|
+
const start = block - stepSize
|
|
7
|
+
return asXL1BlockRange([start, start + stepSize - 1])
|
|
8
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
import { StepSizes } from '@xyo-network/xl1-protocol'
|
|
3
|
+
|
|
4
|
+
export function stepTransferIndex(block: number, step: number) {
|
|
5
|
+
let rewardTransferCount = 0
|
|
6
|
+
let rewardTransferIndex = -1
|
|
7
|
+
for (let i = 3; i < StepSizes.length; i++) {
|
|
8
|
+
const stepSize = StepSizes[i]
|
|
9
|
+
if (block % stepSize === 0) {
|
|
10
|
+
if (stepSize === StepSizes[step]) {
|
|
11
|
+
rewardTransferIndex = rewardTransferCount
|
|
12
|
+
}
|
|
13
|
+
rewardTransferCount++
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
assertEx(rewardTransferIndex >= 0, () => `Error: Could not find step size for step ${step} at block ${block}`)
|
|
17
|
+
return [rewardTransferIndex, rewardTransferCount]
|
|
18
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { WithStorageMeta } from '@xyo-network/payload-model'
|
|
2
|
+
import type { AllowedBlockPayload, SignedHydratedTransactionWithStorageMeta } from '@xyo-network/xl1-protocol'
|
|
3
|
+
import { isAllowedBlockPayload } from '@xyo-network/xl1-protocol'
|
|
4
|
+
|
|
5
|
+
export function elevatedPayloads([tx, payloads]: SignedHydratedTransactionWithStorageMeta) {
|
|
6
|
+
const opCodes = (tx.script ?? []).filter(operation => operation.startsWith('elevate|'))
|
|
7
|
+
const elevatedPayloads: WithStorageMeta<AllowedBlockPayload>[] = []
|
|
8
|
+
for (const opCode of opCodes) {
|
|
9
|
+
const [code, hash] = opCode.split('|')
|
|
10
|
+
if (code === 'elevated') {
|
|
11
|
+
const elevatedPayload = payloads.find(payload => payload._hash === hash)
|
|
12
|
+
if (isAllowedBlockPayload(elevatedPayload)) {
|
|
13
|
+
elevatedPayloads.push(elevatedPayload)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
if (opCodes.length === elevatedPayloads.length) {
|
|
18
|
+
return elevatedPayloads
|
|
19
|
+
}
|
|
20
|
+
throw new Error('Not all elevated payloads could be found in the transaction payloads')
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './elevatedPayloads.ts'
|