You can check the source code of Opium Protocol, which performs settlement of derivative contracts in our GitHub​