Skip to content

Commit 517c979

Browse files
authored
Merge pull request #1 from SundaeSwap-finance/milestone-1
Milestone 1
2 parents 9ffe886 + 6bcef7d commit 517c979

File tree

16 files changed

+2345
-91
lines changed

16 files changed

+2345
-91
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ jobs:
1111
steps:
1212
- uses: actions/checkout@v3
1313

14-
- uses: aiken-lang/setup-aiken@v0.1.0
14+
- uses: aiken-lang/setup-aiken@v1.0.3
1515
with:
16-
version: v1.0.24-alpha
16+
version: v1.1.17
1717

1818
- run: aiken fmt --check
1919
- run: aiken check -D

aiken.lock

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# This file was generated by Aiken
2+
# You typically do not need to edit this file
3+
4+
[[requirements]]
5+
name = "aiken-lang/stdlib"
6+
version = "v2.2.0"
7+
source = "github"
8+
9+
[[requirements]]
10+
name = "aiken-lang/merkle-patricia-forestry"
11+
version = "2.0.1"
12+
source = "github"
13+
14+
[[requirements]]
15+
name = "aiken-lang/fuzz"
16+
version = "main"
17+
source = "github"
18+
19+
[[packages]]
20+
name = "aiken-lang/stdlib"
21+
version = "v2.2.0"
22+
requirements = []
23+
source = "github"
24+
25+
[[packages]]
26+
name = "aiken-lang/merkle-patricia-forestry"
27+
version = "2.0.1"
28+
requirements = []
29+
source = "github"
30+
31+
[[packages]]
32+
name = "aiken-lang/fuzz"
33+
version = "main"
34+
requirements = []
35+
source = "github"
36+
37+
[etags]
38+
"aiken-lang/fuzz@main" = [{ secs_since_epoch = 1756480816, nanos_since_epoch = 282727354 }, "9843473958e51725a9274b487d2d4aac0395ec1a2e30f090724fa737226bc127"]

aiken.toml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
name = "sundae/cosponsor"
22
version = "0.0.0"
3+
compiler = "v1.1.17"
4+
plutus = "v3"
35
license = "Apache-2.0"
46
description = "Aiken contracts for project 'sundae/cosponsor'"
57

@@ -10,5 +12,17 @@ platform = "github"
1012

1113
[[dependencies]]
1214
name = "aiken-lang/stdlib"
13-
version = "1.7.0"
15+
version = "v2.2.0"
1416
source = "github"
17+
18+
[[dependencies]]
19+
name = "aiken-lang/merkle-patricia-forestry"
20+
version = "2.0.1"
21+
source = "github"
22+
23+
[[dependencies]]
24+
name = "aiken-lang/fuzz"
25+
version = "main"
26+
source = "github"
27+
28+
[config]

lib/calculation/conversion.ak

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
use aiken/cbor.{serialise}
2+
use aiken/collection/list
3+
use aiken/primitive/bytearray
4+
use cardano/address.{Address, Inline, Script, VerificationKey}
5+
use cardano/assets.{Lovelace, Value}
6+
use cardano/transaction.{
7+
Datum, DatumHash, InlineDatum, Input, NoDatum, Output, OutputReference,
8+
}
9+
use types/cosponsor.{CosponsoredProposalProcedure}
10+
11+
pub fn convert_inputs(inputs: List<Input>) -> ByteArray {
12+
let (length, bytes) =
13+
list.foldr(
14+
inputs,
15+
(0, ""),
16+
fn(input, acc) {
17+
let OutputReference { transaction_id: hash, output_index: index } =
18+
input.output_reference
19+
20+
(
21+
acc.1st + 1,
22+
bytearray.concat(#"82", hash)
23+
|> bytearray.concat(serialise(index))
24+
|> bytearray.concat(acc.2nd),
25+
)
26+
},
27+
)
28+
29+
if length <= 23 {
30+
bytearray.from_int_big_endian(128 + length, 1) |> bytearray.concat(bytes)
31+
} else {
32+
bytearray.concat(#"9f", bytes) |> bytearray.concat(#"ff")
33+
}
34+
}
35+
36+
pub fn convert_mint(mint: Value) -> ByteArray {
37+
mint |> serialise
38+
}
39+
40+
pub fn convert_outputs(outputs: List<Output>) -> ByteArray {
41+
let (length, bytes) =
42+
list.foldr(
43+
outputs,
44+
(0, ""),
45+
fn(output, acc) {
46+
let Output { address, value, datum, .. } = output
47+
48+
let (add_datum, datum_bytes) = convert_datum(datum)
49+
(
50+
acc.1st + 1,
51+
bytearray.from_int_big_endian(130 + add_datum, 1)
52+
|> bytearray.concat(convert_address(address))
53+
|> bytearray.concat(convert_value(value))
54+
|> bytearray.concat(datum_bytes)
55+
|> bytearray.concat(acc.2nd),
56+
)
57+
},
58+
)
59+
60+
if length <= 23 {
61+
bytearray.from_int_big_endian(128 + length, 1) |> bytearray.concat(bytes)
62+
} else {
63+
bytearray.concat(#"9f", bytes) |> bytearray.concat(#"ff")
64+
}
65+
}
66+
67+
pub fn convert_fee(fee: Lovelace) -> ByteArray {
68+
fee |> serialise
69+
}
70+
71+
pub fn convert_extra_signatories(signatures: List<ByteArray>) -> ByteArray {
72+
let (length, bytes) =
73+
list.foldr(
74+
signatures,
75+
(0, ""),
76+
fn(signature, acc) {
77+
(acc.1st + 1, bytearray.concat(serialise(signature), acc.2nd))
78+
},
79+
)
80+
if length <= 23 {
81+
bytearray.from_int_big_endian(128 + length, 1) |> bytearray.concat(bytes)
82+
} else {
83+
bytearray.concat(#"9f", bytes) |> bytearray.concat(#"ff")
84+
}
85+
}
86+
87+
fn convert_datum(datum: Datum) -> (Int, ByteArray) {
88+
when datum is {
89+
NoDatum -> (0, "")
90+
DatumHash(datum_hash) -> (1, datum_hash)
91+
InlineDatum(datum_bytes) -> (1, serialise(datum_bytes))
92+
}
93+
}
94+
95+
fn convert_value(assets: Value) -> ByteArray {
96+
let lovelace = assets.lovelace_of(assets) |> serialise
97+
let multi_asset = assets.without_lovelace(assets) |> serialise
98+
99+
if multi_asset == #"a0" {
100+
lovelace
101+
} else {
102+
#"82" |> bytearray.concat(lovelace) |> bytearray.concat(multi_asset)
103+
}
104+
}
105+
106+
fn convert_address(address: Address) -> ByteArray {
107+
//; bit 4: payment cred is keyhash/scripthash
108+
let (header_byte_pc, credential_p) =
109+
when address.payment_credential is {
110+
Script(cred) -> (16, cred)
111+
VerificationKey(cred) -> (0, cred)
112+
}
113+
let (header_byte_sc, credential_s) =
114+
when address.stake_credential is {
115+
None -> (96, "")
116+
Some(Inline(VerificationKey(cred))) -> (0, cred)
117+
Some(Inline(Script(cred))) -> (32, cred)
118+
_ -> fail @"no way"
119+
}
120+
bytearray.from_int_big_endian(header_byte_pc + header_byte_sc, 1)
121+
|> bytearray.concat(bytearray.concat(credential_p, credential_s))
122+
|> serialise
123+
}
124+
125+
pub fn convert_proposals(
126+
proposals: List<CosponsoredProposalProcedure>,
127+
) -> ByteArray {
128+
let (length, bytes) =
129+
list.foldr(
130+
proposals,
131+
(0, ""),
132+
fn(proposal, acc) {
133+
(acc.1st + 1, bytearray.concat(convert_proposal(proposal), acc.2nd))
134+
},
135+
)
136+
if length <= 23 {
137+
bytearray.from_int_big_endian(128 + length, 1) |> bytearray.concat(bytes)
138+
} else {
139+
bytearray.concat(#"9f", bytes) |> bytearray.concat(#"ff")
140+
}
141+
}
142+
143+
fn convert_proposal(proposal: CosponsoredProposalProcedure) -> ByteArray {
144+
#"84"
145+
|> bytearray.concat(serialise(proposal.procedure.deposit))
146+
|> bytearray.concat(serialise(proposal.procedure.return_address))
147+
|> bytearray.concat(serialise(proposal.procedure.governance_action))
148+
|> bytearray.concat(serialise(proposal.anchor))
149+
}

0 commit comments

Comments
 (0)