Skip to content

Commit 6f2a578

Browse files
committed
fixed royalties decoding for eth addresses
1 parent 69221ff commit 6f2a578

4 files changed

Lines changed: 11 additions & 9 deletions

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,6 @@
5555
"base-x": "^4.0.0",
5656
"coin-format": "^0.0.2",
5757
"utf-helpers": "^0.0.3"
58-
}
58+
},
59+
"packageManager": "yarn@1.22.21+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72"
5960
}

src/Royalties/decoding.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {IV2Royalty, RoyaltyType, UniqueRoyaltyPart} from './types'
44
import {splitStringEvery} from './utils'
55

66
export const decodeRoyaltyPart = (encoded: string): UniqueRoyaltyPart => {
7-
if (encoded.length !== 66) {
7+
if (encoded.length !== 130) {
88
throw new Error('Invalid royalty part encoding - length is not 32 bytes ("0x" + 64 symbols)')
99
}
1010
const encodedMeta = encoded.slice(2, 66)
@@ -13,12 +13,13 @@ export const decodeRoyaltyPart = (encoded: string): UniqueRoyaltyPart => {
1313
const version = parseInt(encodedMeta.slice(0, 2), 16)
1414
const decimals = parseInt(encodedMeta.slice(46, 46 + 2), 16)
1515
const value = BigInt('0x' + encodedMeta.slice(48))
16-
const royaltyType =
17-
encodedMeta[44] === '0' ? RoyaltyType.DEFAULT : RoyaltyType.PRIMARY_ONLY
16+
const royaltyType = encodedMeta[44] === '0'
17+
? RoyaltyType.DEFAULT
18+
: RoyaltyType.PRIMARY_ONLY
1819

1920
const isEthereum = encodedMeta[45] === '0'
2021
const address = isEthereum
21-
? '0x' + encodedAddress.slice(24)
22+
? Address.normalize.ethereumAddress('0x' + encodedAddress.slice(24))
2223
: Address.substrate.encode(encodedAddress)
2324

2425
return {

src/test/royalties.samples.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ export const ETH_DEFAULT = {
2525
decimals: 6,
2626
value: 15n,
2727
royaltyType: RoyaltyType.DEFAULT,
28-
address: '0x1234a38988dd5ecc93dd9ce90a44a00e5fb91e4c',
28+
address: '0xcafe52dae8874E9E6d7511e05d213590E47e97B6',
2929
},
3030
encoded:
3131
'0x' +
3232
'010000000000000000000000000000000000000000000006000000000000000f' +
33-
'0000000000000000000000001234a38988dd5ecc93dd9ce90a44a00e5fb91e4c',
33+
'000000000000000000000000cafe52dae8874e9e6d7511e05d213590e47e97b6',
3434
} satisfies Sample
3535

3636
export const ROYALTY_ENCODED =

src/test/royalties.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ describe('Royalties TS implementation', async () => {
169169
decimals: 4,
170170
value: 9999n,
171171
royaltyType: 'PRIMARY_ONLY' as const,
172-
address: '0x1234a38988dd5ecc93dd9ce90a44a00e5fb91e4c'
172+
address: '0x1234A38988Dd5ecC93Dd9cE90a44A00e5FB91e4C'
173173
}
174174
]
175175

@@ -182,7 +182,7 @@ describe('Royalties TS implementation', async () => {
182182
percent: 1
183183
},
184184
{
185-
address: '0x1234a38988dd5ecc93dd9ce90a44a00e5fb91e4c',
185+
address: '0x1234A38988Dd5ecC93Dd9cE90a44A00e5FB91e4C',
186186
percent: 99.99,
187187
isPrimaryOnly: true
188188
}

0 commit comments

Comments
 (0)